Skip to content

Commit

Permalink
Deploy preview for PR 599 🛫
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoMendonc-a committed Sep 27, 2023
1 parent 7b7a10d commit c57da98
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pr-preview/pr-599/examples-engine-hello-cubos.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ <h1>
Hello CUBOS
</h1>
<p>Using <a href="classcubos_1_1engine_1_1Cubos.html" class="m-doc">cubos::<wbr />engine::<wbr />Cubos</a> to create a simple program.</p>
<p><a name="md_hello_cubos_page"></a></p><p>This example shows the basics of how <a href="classcubos_1_1engine_1_1Cubos.html" class="m-doc">cubos::<wbr />engine::<wbr />Cubos</a> is used, by making a simple &quot;Hello World&quot; program.</p><p>We&#x27;ll start by including the engine.</p><pre class="m-code"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cubos/engine/cubos.hpp&gt;</span>
<p><a name="md_hello_cubos_page"></a></p><p>This example shows the basics of how <a href="classcubos_1_1engine_1_1Cubos.html" class="m-doc">cubos::<wbr />engine::<wbr />Cubos</a> is used, by making a simple &quot;Hello World&quot; program.</p><pre class="m-code"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cubos/engine/cubos.hpp&gt;</span>

<span class="k">using</span><span class="w"> </span><span class="n">cubos</span><span class="o">::</span><span class="n">engine</span><span class="o">::</span><span class="n">Cubos</span><span class="p">;</span></pre><p>Now we&#x27;ll just need the object that represents the itself.</p><pre class="m-code"><span class="w"> </span><span class="n">Cubos</span><span class="w"> </span><span class="n">cubos</span><span class="p">{};</span></pre><p>The <a href="classcubos_1_1engine_1_1Cubos.html" class="m-doc">cubos::<wbr />engine::<wbr />Cubos</a> class represents the engine. We&#x27;ll need it to add functionality to our program.</p><p>Let&#x27;s start by defining what functionality we want to add.</p><pre class="m-code"><span class="kt">void</span><span class="w"> </span><span class="nf">sayHelloCubos</span><span class="p">()</span>
<span class="k">using</span><span class="w"> </span><span class="n">cubos</span><span class="o">::</span><span class="n">engine</span><span class="o">::</span><span class="n">Cubos</span><span class="p">;</span></pre><p>First we&#x27;ll need to get a <code>Cubos</code> object.</p><pre class="m-code"><span class="w"> </span><span class="n">Cubos</span><span class="w"> </span><span class="n">cubos</span><span class="p">{};</span></pre><p>The <a href="classcubos_1_1engine_1_1Cubos.html" class="m-doc">cubos::<wbr />engine::<wbr />Cubos</a> class represents the engine. We&#x27;ll need it to add functionality to our program.</p><p>Let&#x27;s start by defining what functionality we want to add.</p><pre class="m-code"><span class="kt">void</span><span class="w"> </span><span class="nf">sayHelloCubos</span><span class="p">()</span>
<span class="p">{</span>
<span class="w"> </span><span class="n">CUBOS_INFO</span><span class="p">(</span><span class="s">&quot;Hello CUBOS&quot;</span><span class="p">);</span>
<span class="p">}</span></pre><p>This function simply prints <code>Hello CUBOS</code> to the console. It uses one of CUBOS.&#x27;s logging macros. You can find more about them here. However, this function is not currently called, so we&#x27;ll need to tell CUBOS. that we want it to run.</p><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">startupSystem</span><span class="p">(</span><span class="n">sayHelloCubos</span><span class="p">);</span></pre><p>Startup systems run only once when the engine is loaded. Now let&#x27;s make things more interesting. Let&#x27;s print <code>Hello World</code>, but split it over two different systems.</p><pre class="m-code"><span class="kt">void</span><span class="w"> </span><span class="nf">sayHello</span><span class="p">()</span>
Expand All @@ -62,9 +62,8 @@ <h1>
<span class="kt">void</span><span class="w"> </span><span class="nf">sayWorld</span><span class="p">()</span>
<span class="p">{</span>
<span class="w"> </span><span class="n">CUBOS_INFO</span><span class="p">(</span><span class="s">&quot;World&quot;</span><span class="p">);</span>
<span class="p">}</span></pre><p>Instead of using <code>startupSystem</code>, we&#x27;ll use <a href="classcubos_1_1engine_1_1Cubos.html#ab70e5477ca4cfd504510585138cc84f0" class="m-doc">cubos::<wbr />engine::<wbr />Cubos::<wbr />system</a> . This means the systems will be called every cycle, instead of just once at startup.</p><aside class="m-note m-info"><h4>Note</h4><p>As we don&#x27;t have anything that would require multiple cycles (such as a window to draw to), the CUBOS. main cycle will run only once.</p></aside><p>However, we can&#x27;t just do as we did for <code>sayHelloCubos</code> and call it a day. We want <code>sayHello</code> to come before <code>sayWorld</code>, so we&#x27;ll have to explicitly tell that to the engine, or else we risk having them in the wrong order. To do that we use tags. Let&#x27;s create two tags, one for each system.</p><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">tag</span><span class="p">(</span><span class="s">&quot;exampleTagA&quot;</span><span class="p">).</span><span class="n">before</span><span class="p">(</span><span class="s">&quot;exampleTagB&quot;</span><span class="p">);</span>
<span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">startupTag</span><span class="p">(</span><span class="s">&quot;exampleTagB&quot;</span><span class="p">);</span></pre> <p><a href="classcubos_1_1engine_1_1Cubos.html#adefdf998ef5507ae6e74c5eb60bcf01f" class="m-doc">cubos::<wbr />engine::<wbr />Cubos::<wbr />tag</a> creates a new tag, and <a href="classcubos_1_1engine_1_1TagBuilder.html#a82faaca675e37ba793a9cbd09fcce3c8" class="m-doc">cubos::<wbr />engine::<wbr />TagBuilder::<wbr />before</a> makes any systems tagged with it come before systems tagged with the one given as parameter. There&#x27;s also a <a href="classcubos_1_1engine_1_1TagBuilder.html#abf6f6a074f98531e2d561485b627ded8" class="m-doc">cubos::<wbr />engine::<wbr />TagBuilder::<wbr />after</a> that has the inverse effect. Now all we have to do is to assign these tags to our systems.</p><aside class="m-note m-info"><h4>Note</h4><p>If we wanted to give these tags to a system running on startup, we&#x27;d have to use <a href="classcubos_1_1engine_1_1Cubos.html#a5949b9d4a18a5f52cbb3e72fb75451c2" class="m-doc">cubos::<wbr />engine::<wbr />Cubos::<wbr />startupTag</a> instead.</p></aside><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">system</span><span class="p">(</span><span class="n">sayHello</span><span class="p">).</span><span class="n">tagged</span><span class="p">(</span><span class="s">&quot;exampleTagA&quot;</span><span class="p">);</span>
<span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">system</span><span class="p">(</span><span class="n">sayWorld</span><span class="p">).</span><span class="n">tagged</span><span class="p">(</span><span class="s">&quot;exampleTagB&quot;</span><span class="p">);</span></pre><p>With everything properly set up, all that remains is to run the engine.</p><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">run</span><span class="p">();</span></pre>
<span class="p">}</span></pre><p>Instead of using <code>startupSystem</code>, we&#x27;ll use <a href="classcubos_1_1engine_1_1Cubos.html#ab70e5477ca4cfd504510585138cc84f0" class="m-doc">cubos::<wbr />engine::<wbr />Cubos::<wbr />system</a> . This means the systems will be called every cycle, instead of just once at startup.</p><aside class="m-note m-info"><h4>Note</h4><p>As we don&#x27;t have anything that would require multiple cycles (such as a window to draw to), the CUBOS. main cycle will run only once.</p></aside><p>However, we can&#x27;t just do as we did for <code>sayHelloCubos</code> and call it a day. We want <code>sayHello</code> to come before <code>sayWorld</code>, so we&#x27;ll have to explicitly tell that to the engine, or else we risk having them in the wrong order. To do that we use tags. Let&#x27;s create two tags, one for each system.</p><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">tag</span><span class="p">(</span><span class="s">&quot;helloTag&quot;</span><span class="p">).</span><span class="n">before</span><span class="p">(</span><span class="s">&quot;worldTag&quot;</span><span class="p">);</span></pre> <p><a href="classcubos_1_1engine_1_1Cubos.html#adefdf998ef5507ae6e74c5eb60bcf01f" class="m-doc">cubos::<wbr />engine::<wbr />Cubos::<wbr />tag</a> creates a new tag, and <a href="classcubos_1_1engine_1_1TagBuilder.html#a82faaca675e37ba793a9cbd09fcce3c8" class="m-doc">cubos::<wbr />engine::<wbr />TagBuilder::<wbr />before</a> makes any systems tagged with it come before systems tagged with the one given as parameter. There&#x27;s also a <a href="classcubos_1_1engine_1_1TagBuilder.html#abf6f6a074f98531e2d561485b627ded8" class="m-doc">cubos::<wbr />engine::<wbr />TagBuilder::<wbr />after</a> that has the inverse effect. Now all we have to do is to assign these tags to our systems.</p><aside class="m-note m-info"><h4>Note</h4><p>If we wanted to give these tags to a system running on startup, we&#x27;d have to use <a href="classcubos_1_1engine_1_1Cubos.html#a5949b9d4a18a5f52cbb3e72fb75451c2" class="m-doc">cubos::<wbr />engine::<wbr />Cubos::<wbr />startupTag</a> instead.</p></aside><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">system</span><span class="p">(</span><span class="n">sayHello</span><span class="p">).</span><span class="n">tagged</span><span class="p">(</span><span class="s">&quot;helloTag&quot;</span><span class="p">);</span>
<span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">system</span><span class="p">(</span><span class="n">sayWorld</span><span class="p">).</span><span class="n">tagged</span><span class="p">(</span><span class="s">&quot;worldTag&quot;</span><span class="p">);</span></pre><p>With everything properly set up, all that remains is to run the engine.</p><pre class="m-code"><span class="w"> </span><span class="n">cubos</span><span class="p">.</span><span class="n">run</span><span class="p">();</span></pre>
</div>
</div>
</div>
Expand Down

0 comments on commit c57da98

Please sign in to comment.