Skip to content

Commit

Permalink
Snippets
Browse files Browse the repository at this point in the history
Original commit: 972a6802090df56ecf79058cb923a3bfda7fc4c9
  • Loading branch information
jankrassnigg committed Jan 16, 2024
1 parent d98cab1 commit 9889200
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 45 deletions.
12 changes: 6 additions & 6 deletions index.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions pages/docs/custom-code/cpp/custom-cpp-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ <h2 id="component-class-declaration">Component Class Declaration</h2>
// ezComponent

public:
virtual void SerializeComponent(ezWorldWriter&amp; stream) const override;
virtual void DeserializeComponent(ezWorldReader&amp; stream) override;
virtual void SerializeComponent(ezWorldWriter&amp; inout_stream) const override;
virtual void DeserializeComponent(ezWorldReader&amp; inout_stream) override;

protected:
virtual void OnSimulationStarted() override;
Expand All @@ -128,7 +128,7 @@ <h2 id="component-class-declaration">Component Class Declaration</h2>
void Update();

float m_fAmplitude = 1.0f; // [ property ]
ezAngle m_Speed = ezAngle::Degree(90); // [ property ]
ezAngle m_Speed = ezAngle::MakeFromDegree(90); // [ property ]
};
</code></pre>
<!-- END-DOCS-CODE-SNIPPET -->
Expand All @@ -143,7 +143,7 @@ <h2 id="reflection-block">Reflection Block</h2>
EZ_BEGIN_PROPERTIES
{
EZ_MEMBER_PROPERTY(&quot;Amplitude&quot;, m_fAmplitude)-&gt;AddAttributes(new ezDefaultValueAttribute(1), new ezClampValueAttribute(0, 10)),
EZ_MEMBER_PROPERTY(&quot;Speed&quot;, m_Speed)-&gt;AddAttributes(new ezDefaultValueAttribute(ezAngle::Degree(90))),
EZ_MEMBER_PROPERTY(&quot;Speed&quot;, m_Speed)-&gt;AddAttributes(new ezDefaultValueAttribute(ezAngle::MakeFromDegree(90))),
}
EZ_END_PROPERTIES;

Expand Down Expand Up @@ -187,11 +187,11 @@ <h2 id="initialization-and-update">Initialization and Update</h2>
<h2 id="serialization">Serialization</h2>
<p>Finally, to make our component also work in exported scenes, we need to implement serialization:</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: component-serialize -->
<pre><code class="lang-cpp">void DemoComponent::SerializeComponent(ezWorldWriter&amp; stream) const
<pre><code class="lang-cpp">void DemoComponent::SerializeComponent(ezWorldWriter&amp; inout_stream) const
{
SUPER::SerializeComponent(stream);
SUPER::SerializeComponent(inout_stream);

auto&amp; s = stream.GetStream();
auto&amp; s = inout_stream.GetStream();

s &lt;&lt; m_fAmplitude;
s &lt;&lt; m_Speed;
Expand All @@ -201,12 +201,12 @@ <h2 id="serialization">Serialization</h2>
<p>This writes out the data in the latest format. If you change the format, you should increase the version number of your component in the reflection block at the very top.</p>
<p>Obviously, at runtime we also need to deserialize our component. This is where we implement backwards compatibility for older exported scenes:</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: component-deserialize -->
<pre><code class="lang-cpp">void DemoComponent::DeserializeComponent(ezWorldReader&amp; stream)
<pre><code class="lang-cpp">void DemoComponent::DeserializeComponent(ezWorldReader&amp; inout_stream)
{
SUPER::DeserializeComponent(stream);
const ezUInt32 uiVersion = stream.GetComponentTypeVersion(GetStaticRTTI());
SUPER::DeserializeComponent(inout_stream);
const ezUInt32 uiVersion = inout_stream.GetComponentTypeVersion(GetStaticRTTI());

auto&amp; s = stream.GetStream();
auto&amp; s = inout_stream.GetStream();

s &gt;&gt; m_fAmplitude;

Expand All @@ -216,7 +216,7 @@ <h2 id="serialization">Serialization</h2>
// convert this to ezAngle
float fDegree;
s &gt;&gt; fDegree;
m_Speed = ezAngle::Degree(fDegree);
m_Speed = ezAngle::MakeFromDegree(fDegree);
}
else
{
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pages/docs/custom-code/cpp/engine-plugins.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ <h3 id="dll-symbol-importexport">DLL Symbol Import/Export</h3>
<pre><code class="lang-cpp">// Configure the DLL Import/Export Define
#if EZ_ENABLED(EZ_COMPILE_ENGINE_AS_DLL)
# ifdef BUILDSYSTEM_BUILDING_SAMPLEGAMEPLUGIN_LIB
# define EZ_SAMPLEGAMEPLUGIN_DLL __declspec(dllexport)
# define EZ_SAMPLEGAMEPLUGIN_DLL EZ_DECL_EXPORT
# else
# define EZ_SAMPLEGAMEPLUGIN_DLL __declspec(dllimport)
# define EZ_SAMPLEGAMEPLUGIN_DLL EZ_DECL_IMPORT
# endif
#else
# define EZ_SAMPLEGAMEPLUGIN_DLL
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/custom-code/cpp/engine-plugins.html.view.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pages/docs/debugging/cvars.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h2 id="example-code">Example Code</h2>
<!-- BEGIN-DOCS-CODE-SNIPPET: cvar-2 -->
<pre><code class="lang-cpp">if (cvar_DebugDisplay)
{
ezDebugRenderer::DrawLineSphere(m_pMainWorld, ezBoundingSphere(ezVec3::ZeroVector(), 1.0f), ezColor::Orange);
ezDebugRenderer::DrawLineSphere(m_pMainWorld, ezBoundingSphere::MakeFromCenterAndRadius(ezVec3::MakeZero(), 1.0f), ezColor::Orange);
}
</code></pre>
<!-- END-DOCS-CODE-SNIPPET -->
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/debugging/cvars.html.view.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pages/docs/debugging/debug-rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ <h2 id="example">Example</h2>
<p>A full example for how to use the debug renderer is given in the <a href="../../samples/sample-game-plugin.html">Sample Game Plugin</a>. Here, the <code>DebugRenderComponent</code> shows how to utilize the debug renderer.</p>
<p>The following code snippet is sufficient to render a wireframe sphere at the location of the component:</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: debugrender-sphere -->
<pre><code class="lang-cpp">ezBoundingSphere sphere;
sphere.SetElements(ezVec3::ZeroVector(), m_fSize);
<pre><code class="lang-cpp">ezBoundingSphere sphere = ezBoundingSphere::MakeFromCenterAndRadius(ezVec3::MakeZero(), m_fSize);
ezDebugRenderer::DrawLineSphere(GetWorld(), sphere, m_Color, ownerTransform);
</code></pre>
<!-- END-DOCS-CODE-SNIPPET -->
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/debugging/debug-rendering.html.view.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pages/docs/runtime/world/components.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h2 id="component-reflection-block">Component Reflection Block</h2>
{
EZ_MEMBER_PROPERTY(&quot;Size&quot;, m_fSize)-&gt;AddAttributes(new ezDefaultValueAttribute(1), new ezClampValueAttribute(0, 10)),
EZ_MEMBER_PROPERTY(&quot;Color&quot;, m_Color)-&gt;AddAttributes(new ezDefaultValueAttribute(ezColor::White)),
EZ_ACCESSOR_PROPERTY(&quot;Texture&quot;, GetTextureFile, SetTextureFile)-&gt;AddAttributes(new ezAssetBrowserAttribute(&quot;Texture 2D&quot;)),
EZ_ACCESSOR_PROPERTY(&quot;Texture&quot;, GetTextureFile, SetTextureFile)-&gt;AddAttributes(new ezAssetBrowserAttribute(&quot;CompatibleAsset_Texture_2D&quot;)),
EZ_BITFLAGS_MEMBER_PROPERTY(&quot;Render&quot;, DebugRenderComponentMask, m_RenderTypes)-&gt;AddAttributes(new ezDefaultValueAttribute(DebugRenderComponentMask::Box)),
}
EZ_END_PROPERTIES;
Expand Down Expand Up @@ -200,11 +200,11 @@ <h2 id="serialization-and-versioning">Serialization and Versioning</h2>
<p>To implement proper serialization, you need to override <code>ezComponent::SerializeComponent()</code> and <code>ezComponent::DeserializeComponent()</code>.</p>
<p>During serialization you simply write data to a stream, as you like:</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: component-serialize -->
<pre><code class="lang-cpp">void DemoComponent::SerializeComponent(ezWorldWriter&amp; stream) const
<pre><code class="lang-cpp">void DemoComponent::SerializeComponent(ezWorldWriter&amp; inout_stream) const
{
SUPER::SerializeComponent(stream);
SUPER::SerializeComponent(inout_stream);

auto&amp; s = stream.GetStream();
auto&amp; s = inout_stream.GetStream();

s &lt;&lt; m_fAmplitude;
s &lt;&lt; m_Speed;
Expand All @@ -219,12 +219,12 @@ <h2 id="serialization-and-versioning">Serialization and Versioning</h2>
<!-- END-DOCS-CODE-SNIPPET -->
<p>The version number should be increased every time the serialization format of the component type has to change. During deserialization you can query the version number with which this component data was written. You than have to handle converting older formats as appropriate:</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: component-deserialize -->
<pre><code class="lang-cpp">void DemoComponent::DeserializeComponent(ezWorldReader&amp; stream)
<pre><code class="lang-cpp">void DemoComponent::DeserializeComponent(ezWorldReader&amp; inout_stream)
{
SUPER::DeserializeComponent(stream);
const ezUInt32 uiVersion = stream.GetComponentTypeVersion(GetStaticRTTI());
SUPER::DeserializeComponent(inout_stream);
const ezUInt32 uiVersion = inout_stream.GetComponentTypeVersion(GetStaticRTTI());

auto&amp; s = stream.GetStream();
auto&amp; s = inout_stream.GetStream();

s &gt;&gt; m_fAmplitude;

Expand All @@ -234,7 +234,7 @@ <h2 id="serialization-and-versioning">Serialization and Versioning</h2>
// convert this to ezAngle
float fDegree;
s &gt;&gt; fDegree;
m_Speed = ezAngle::Degree(fDegree);
m_Speed = ezAngle::MakeFromDegree(fDegree);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/runtime/world/components.html.view.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pages/docs/runtime/world/spatial-system.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ <h2 id="exposing-game-objects-to-the-spatial-system">Exposing Game Objects to th
<p>The world sends the <a href="world-messaging.html">message</a> <code>ezMsgUpdateLocalBounds</code> to all components when it determines that an update is necessary. This can also be triggered manually by calling <code>ezGameObject::UpdateLocalBounds()</code> when spatial data, such as which category to use, has been modified.</p>
<p>Components can handle this message and add spatial information to it. For 3D objects one would use something like the bounding sphere of a mesh, but it is also possible to use more abstract spatial data. For example the <a href="../../../samples/rts.html">RTS sample</a> has an <code>RtsSelectableComponent</code> which is attached to all units that should be selectable by the player. Although the <code>RtsSelectableComponent</code> doesn't have a visual representation, it reacts to <code>ezMsgUpdateLocalBounds</code> to add spatial data, which can then be used to efficiently look up units under the mouse cursor.</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: spatial-bounds-update -->
<pre><code class="lang-cpp">void RtsSelectableComponent::OnUpdateLocalBounds(ezMsgUpdateLocalBounds&amp; msg)
<pre><code class="lang-cpp">void RtsSelectableComponent::OnUpdateLocalBounds(ezMsgUpdateLocalBounds&amp; ref_msg)
{
ezBoundingBoxSphere bounds;
bounds.m_fSphereRadius = m_fSelectionRadius;
bounds.m_vCenter.SetZero();
bounds.m_vBoxHalfExtends.Set(m_fSelectionRadius);

msg.AddBounds(bounds, s_SelectableCategory);
ref_msg.AddBounds(bounds, s_SelectableCategory);
}
</code></pre>
<!-- END-DOCS-CODE-SNIPPET -->
Expand All @@ -140,9 +140,9 @@ <h2 id="querying-the-spatial-system">Querying the Spatial System</h2>
<p>Once you have spatial data inserted into the system, you can use it to efficiently query for objects within a volume.</p>
<p>When calling functions such as <code>ezSpatialSystem::FindObjectsInSphere()</code> you have to provide a <em>bitmask</em> of categories. That's because you can request to get objects from multiple categories at the same time. You can get this bitmask by calling <code>ezSpatialData::Category::GetBitmask()</code> on a category object.</p>
<!-- BEGIN-DOCS-CODE-SNIPPET: spatial-query -->
<pre><code class="lang-cpp">void RtsGameState::InspectObjectsInArea(const ezVec2&amp; position, float radius, ezSpatialSystem::QueryCallback callback) const
<pre><code class="lang-cpp">void RtsGameState::InspectObjectsInArea(const ezVec2&amp; vPosition, float fRadius, ezSpatialSystem::QueryCallback callback) const
{
ezBoundingSphere sphere(position.GetAsVec3(0), radius);
ezBoundingSphere sphere = ezBoundingSphere::MakeFromCenterAndRadius(vPosition.GetAsVec3(0), fRadius);
ezSpatialSystem::QueryParams queryParams;
queryParams.m_uiCategoryBitmask = RtsSelectableComponent::s_SelectableCategory.GetBitmask();
m_pMainWorld-&gt;GetSpatialSystem()-&gt;FindObjectsInSphere(sphere, queryParams, callback);
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/runtime/world/spatial-system.html.view.json

Large diffs are not rendered by default.

0 comments on commit 9889200

Please sign in to comment.