<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Macroquad</title>
    <subtitle>Macroquad is a simple and easy to use game library for Rust programming language.</subtitle>
    <link href="https://macroquad.rs/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://macroquad.rs/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2025-03-07T16:31:42+00:00</updated>
    <id>https://macroquad.rs/atom.xml</id>
    <entry xml:lang="en">
        <title>The book Game Development in Rust with Macroquad</title>
        <published>2025-03-07T16:31:42+00:00</published>
        <updated>2025-03-07T16:31:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/book/" type="text/html"/>
        <id>https://macroquad.rs/articles/book/</id>
        
        <content type="html">&lt;img src=&quot;&#x2F;images&#x2F;macroquad_cover_small.png&quot;&gt;
&lt;h2 id=&quot;learn-game-development-with-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#learn-game-development-with-macroquad&quot; aria-label=&quot;Anchor link for: learn-game-development-with-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Learn game development with Macroquad&lt;&#x2F;h2&gt;
&lt;p&gt;A complete guide on how to develop a classic 2D shoot ’em up game using the
Macroquad. It covers everything from a simple Hello World application to
adding graphics, audio, a shader, a graphical menu, and how to release the
game on multiple platforms. Each chapter introduces new Macroquad concepts,
improves on the gameplay, and ends with a challenge.&lt;&#x2F;p&gt;
&lt;p&gt;The book is written by Olle Wreede from Agical.&lt;&#x2F;p&gt;
&lt;p&gt;Buy the book &lt;a href=&quot;https:&#x2F;&#x2F;agical.se&#x2F;buymq&quot;&gt;Game Development in Rust with Macroquad&lt;&#x2F;a&gt;
on the Lulu online book store.&lt;&#x2F;p&gt;
&lt;p&gt;The complete guide is also &lt;a href=&quot;https:&#x2F;&#x2F;mq.agical.se&quot;&gt;available online&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #15</title>
        <published>2024-10-01T20:10:42+00:00</published>
        <updated>2024-10-01T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week15/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week15/</id>
        
        <content type="html">&lt;h1 id=&quot;servo-quad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#servo-quad&quot; aria-label=&quot;Anchor link for: servo-quad&quot;&gt;🔗&lt;&#x2F;a&gt;servo-quad&lt;&#x2F;h1&gt;
&lt;p&gt;Nothing to see there yet, but lately I was playing aroudn with the idea of stripping servo from heaviest dependencies and running it with miniquad.&lt;&#x2F;p&gt;
&lt;p&gt;Imagine servo, but super fast to compile, scriptable in languages other than JS and running anywhere miniquad can run!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week15&#x2F;servo.jpg&quot; alt=&quot;servo&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;this very newsletter was supposed to prevent me from spending too much on private miniquad forks, so when first results are achieved, lets get back on track with the updates&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;miniquad-window-icons-on-linux-x11&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad-window-icons-on-linux-x11&quot; aria-label=&quot;Anchor link for: miniquad-window-icons-on-linux-x11&quot;&gt;🔗&lt;&#x2F;a&gt;miniquad: window icons on Linux&#x2F;X11&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week15&#x2F;icon.jpg&quot; alt=&quot;x11_icons&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;492&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;miniquad-refactored-internal-texture-representation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad-refactored-internal-texture-representation&quot; aria-label=&quot;Anchor link for: miniquad-refactored-internal-texture-representation&quot;&gt;🔗&lt;&#x2F;a&gt;miniquad: Refactored internal texture representation&lt;&#x2F;h1&gt;
&lt;p&gt;Miniquad used to store &lt;code&gt;raw: GLuint&lt;&#x2F;code&gt; as an opengl texture, and for multi sampled texture attachment miniquad used to save a renderbuffer id inside the very same raw field. Big mistake! Lead to a lot of confusion and misinterpreting the data. Now it is properly typed:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;493&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-render-texture-ex&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-render-texture-ex&quot; aria-label=&quot;Anchor link for: macroquad-render-texture-ex&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad: render_texture_ex&lt;&#x2F;h1&gt;
&lt;p&gt;Alongside &lt;code&gt;render_texture&lt;&#x2F;code&gt; and &lt;code&gt;render_texture_msaa&lt;&#x2F;code&gt;, macroquad now have a &lt;code&gt;render_texture_ex&lt;&#x2F;code&gt; function, with former being a shortcut to former. This will allow to add more configuration in the future, but immediate benefits: now it is possible to have depth buffer for render texture and configure sample count for msaa render textures.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;835&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #14</title>
        <published>2024-09-12T20:10:42+00:00</published>
        <updated>2024-09-12T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week14/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week14/</id>
        
        <content type="html">&lt;h1 id=&quot;miniquad-msaa-render-textures-on-web&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad-msaa-render-textures-on-web&quot; aria-label=&quot;Anchor link for: miniquad-msaa-render-textures-on-web&quot;&gt;🔗&lt;&#x2F;a&gt;miniquad: MSAA render textures on web&lt;&#x2F;h1&gt;
&lt;p&gt;A second(after instancing) platform-dependent feature in miniquad: render passes resolve attachment. They are only supported on GL3+ and WebGl2, and they helps with anti-aliased render textures. While, tehcnically, they were implemented in miniquad already, now we got &lt;code&gt;features.resolve_attachments&lt;&#x2F;code&gt; and proper WebGL support.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;blob&#x2F;master&#x2F;examples&#x2F;msaa_render_texture.rs&quot;&gt;Examnple&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;487&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Thanks Sokol, where the feature was gleaned from&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-configurable-batch-size&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-configurable-batch-size&quot; aria-label=&quot;Anchor link for: macroquad-configurable-batch-size&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad: Configurable batch size&lt;&#x2F;h1&gt;
&lt;p&gt;Macroquad performs automatic and static batching for each draw_* call. For each draw call, it pre-allocate a huge cpu&#x2F;gpu buffer to add vertices to. When it exceeds the buffer, it allocates the new one, marking the new draw call.&lt;&#x2F;p&gt;
&lt;p&gt;Some examples when altering those values migh be convinient:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;for huge 3d models that do not fit into a single draw call, increasing
the buffer size might be easier than splitting the model.&lt;&#x2F;li&gt;
&lt;li&gt;when each draw_* call got its own material, buffer size might be reduced to save some memory&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;804&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-a-lot-of-tiled-related-fixes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-a-lot-of-tiled-related-fixes&quot; aria-label=&quot;Anchor link for: macroquad-a-lot-of-tiled-related-fixes&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad: A lot of Tiled related fixes&lt;&#x2F;h1&gt;
&lt;p&gt;Shout out to &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;InnocentusLime&quot;&gt;InnocentusLime&lt;&#x2F;a&gt; who fixed a ton of bugs in semi-abandoned macroquad-tiled!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;792&quot;&gt;#792&lt;&#x2F;a&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;788&quot;&gt;#788&lt;&#x2F;a&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;803&quot;&gt;#803&lt;&#x2F;a&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;808&quot;&gt;#808&lt;&#x2F;a&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;801&quot;&gt;#801&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;p&gt;To battle test soundness of the new camera API, I ported fish-fight&#x27;s follow camera. It does seem to work just fine, this might be a final interation on macroquad-0.5 2D camera API.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week14&#x2F;camera.gif&quot; alt=&quot;camera&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;follow_camera&#x2F;main.rs&quot;&gt;Example source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #13</title>
        <published>2024-08-26T20:10:42+00:00</published>
        <updated>2024-08-26T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week13/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week13/</id>
        
        <content type="html">&lt;h1 id=&quot;macroquad-utf-8-in-input-fields&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-utf-8-in-input-fields&quot; aria-label=&quot;Anchor link for: macroquad-utf-8-in-input-fields&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad: UTF-8 in input fields&lt;&#x2F;h1&gt;
&lt;p&gt;All macroquad&#x27;s UI input fields with text now fully support UTF-8.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week13&#x2F;utf.jpg&quot; alt=&quot;utf&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;786&#x2F;&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;camera2d-rework&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#camera2d-rework&quot; aria-label=&quot;Anchor link for: camera2d-rework&quot;&gt;🔗&lt;&#x2F;a&gt;Camera2D rework&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week13&#x2F;ferris.gif&quot; alt=&quot;ferris&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;How to make an aspect-ratio respecting camera&amp;quot; is, by far, a single most commonly asked question in macroquad&#x27;s discord. Everything about macroquad&#x27;s cameras was very frustrating and super non-intuitive.&lt;&#x2F;p&gt;
&lt;p&gt;This week macroquad might have got a solution: just remove the camera alltogether! Over all camera fixing proposals macroquad ever had, this &amp;quot;camera&amp;quot; using code looks by far the best. Next step - support an old, macroquad-0.4 Camera2D in a compatibility layer and make sure that the new style of handling viewports got feature-parity with the old camera.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; This will guarantee that no matter what window size,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; the top to bottom distance will be 100 in world space.
&lt;&#x2F;span&gt;&lt;span&gt;    canvas.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_viewport_bound&lt;&#x2F;span&gt;&lt;span&gt;(ViewportBound::Horizontal(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;));
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        ctx.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_screen&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;WHITE&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        crab_position &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;crab_direction&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;ctx);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; crab_position will be exactly in the middle of the window
&lt;&#x2F;span&gt;&lt;span&gt;        canvas.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_viewport_center&lt;&#x2F;span&gt;&lt;span&gt;(crab_position);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;        canvas.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw&lt;&#x2F;span&gt;&lt;span&gt;(Sprite::new(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;crab), crab_position, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;WHITE&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;camera.rs&quot;&gt;Full example source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;rounded-rectangle&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#rounded-rectangle&quot; aria-label=&quot;Anchor link for: rounded-rectangle&quot;&gt;🔗&lt;&#x2F;a&gt;Rounded rectangle&lt;&#x2F;h2&gt;
&lt;p&gt;Follow up on last weeks &amp;quot;BuilderAPI&amp;quot; thing. All the drawing functions migrated to the new API, the last ported one being a &lt;code&gt;draw_rounded_rectangle.&lt;&#x2F;code&gt;.
Now it looks like&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;canvas1.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;    Rectangle::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;rounded_corners&lt;&#x2F;span&gt;&lt;span&gt;(RoundedCorners {&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span&gt;}), 
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;RED
&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #12</title>
        <published>2024-08-19T20:10:42+00:00</published>
        <updated>2024-08-19T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week12/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week12/</id>
        
        <content type="html">&lt;h1 id=&quot;miniquad-anti-aliased-render-targets&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad-anti-aliased-render-targets&quot; aria-label=&quot;Anchor link for: miniquad-anti-aliased-render-targets&quot;&gt;🔗&lt;&#x2F;a&gt;miniquad: Anti aliased render targets&lt;&#x2F;h1&gt;
&lt;p&gt;A change heavily inspired by sokol: a way to make render pass that automatically resolves multisampled render textures.&lt;&#x2F;p&gt;
&lt;p&gt;It is a breaking change, &lt;code&gt;new_render_pass_mrt&lt;&#x2F;code&gt; got an extra argument now. However,  it should not affect most people - &lt;code&gt;new_render_pass_mrt&lt;&#x2F;code&gt; got introduced a few weeks back, and, hopefully, most people still use &lt;code&gt;new_render_pass&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;blob&#x2F;master&#x2F;examples&#x2F;msaa_render_texture.rs&quot;&gt;A new example&lt;&#x2F;a&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;478&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;for macroquad, this change allowed to implement a &lt;code&gt;render_target_msaa&lt;&#x2F;code&gt; function. It works just like a normal &lt;code&gt;render_target&lt;&#x2F;code&gt;, and &lt;code&gt;render_target.texture&lt;&#x2F;code&gt; is a normal macroquad&#x27;s texture.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span&gt;&#x2F;&#x2F; Setup &amp;#39;render_target&amp;#39;, used to hold the rendering result so we can resize it
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-let render_target = render_target(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32);
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;let render_target = render_target_msaa(VIRTUAL_WIDTH as u32, VIRTUAL_HEIGHT as u32, 4);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;p&gt;The biggest promise of macroquad-0.5 is the same drawing API for macroquad-0.4 style static batching and for standalone 3d meshes. And it is about to actually happened!&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; direct equivalent of
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; `draw_text(&amp;quot;HELLO WORLD&amp;quot;, 30, 300.0, 300.0, BLACK)`
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; from macroquad 0.4
&lt;&#x2F;span&gt;&lt;span&gt;canvas1.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw&lt;&#x2F;span&gt;&lt;span&gt;(Text::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;HELLO WORLD&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;300.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;300.0&lt;&#x2F;span&gt;&lt;span&gt;), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;BLACK&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; using exactly the same `Text` to create a 3d model
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; text &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; scene.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;model&lt;&#x2F;span&gt;&lt;span&gt;(Text::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;HELLO 3D&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span&gt;), DrawParams::default());
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week12&#x2F;text3d.gif&quot; alt=&quot;text 3d&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;gltf&#x2F;main.rs&quot;&gt;Full example source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #11</title>
        <published>2024-08-12T20:10:42+00:00</published>
        <updated>2024-08-12T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week11/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week11/</id>
        
        <content type="html">&lt;h1 id=&quot;website-rehaul&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#website-rehaul&quot; aria-label=&quot;Anchor link for: website-rehaul&quot;&gt;🔗&lt;&#x2F;a&gt;Website rehaul&lt;&#x2F;h1&gt;
&lt;p&gt;A big &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad-website&#x2F;pull&#x2F;17&quot;&gt;PR&lt;&#x2F;a&gt; landed on macroquad-website, making this very website a lot better, specifically on mobiles.&lt;&#x2F;p&gt;
&lt;p&gt;Great work, &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;brettchalupa&quot;&gt;brettchalupa&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3D macroquad&lt;&#x2F;h1&gt;
&lt;p&gt;A great &amp;quot;builder API dilemma&amp;quot; was finally solved. For those who follow macroquad-0.5 branch, it went through quite a few different takes on a builder API for passing arguments to draw_* functions. I want to believe that this week was the last iteration and this is the final version of a drawing API.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; macroquad-0.4
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_circle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;10.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;RED&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; macroquad-0.5
&lt;&#x2F;span&gt;&lt;span&gt;canvas.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw&lt;&#x2F;span&gt;&lt;span&gt;(Circle::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;10.0&lt;&#x2F;span&gt;&lt;span&gt;), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;RED&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Pros:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Simple draw calls still look compact.&lt;&#x2F;li&gt;
&lt;li&gt;Last argument is an &lt;code&gt;Into&amp;lt;DrawParams&amp;gt;&lt;&#x2F;code&gt;. No more &lt;code&gt;draw_circle_lines&lt;&#x2F;code&gt; - all the drawing styles and material is in the &lt;code&gt;DrawParams&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;It is possible to use &lt;code&gt;Circle&lt;&#x2F;code&gt; without canvas and draw it without any batching.&lt;&#x2F;li&gt;
&lt;li&gt;It is possible to use &lt;code&gt;Circle&lt;&#x2F;code&gt; to create a 3d mesh.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Cons:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It might be tempting to persist the &lt;code&gt;Circle&lt;&#x2F;code&gt; and it is not super clear that it is just a lightweight builder pattern thing.&lt;&#x2F;li&gt;
&lt;li&gt;API discoverability suffer a little.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This week macroquad-0.4 drawing functions got ported to the new API.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;texture.rs&quot;&gt;New texture example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;basic_shapes.rs&quot;&gt;New basic_shapes example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This change might not look like such a big deal, but it was the last big roadblock for publishing macroquad-0.5-alpha and it took crazy amount of iterations.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #10</title>
        <published>2024-08-04T20:10:42+00:00</published>
        <updated>2024-08-12T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week10/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week10/</id>
        
        <content type="html">&lt;h1 id=&quot;an-article-on-cross-compilation-from-linux-to-osx&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#an-article-on-cross-compilation-from-linux-to-osx&quot; aria-label=&quot;Anchor link for: an-article-on-cross-compilation-from-linux-to-osx&quot;&gt;🔗&lt;&#x2F;a&gt;An article on cross compilation from Linux to OSX&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;zigbuild-osx&#x2F;&quot;&gt;A new article on *quad cross compilation&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Thanks &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;birhburh&quot;&gt;@https:&#x2F;&#x2F;github.com&#x2F;birhburh&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-more-vertex-attributes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-more-vertex-attributes&quot; aria-label=&quot;Anchor link for: macroquad-more-vertex-attributes&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad: More vertex attributes&lt;&#x2F;h1&gt;
&lt;p&gt;Trading off a slightly little higher memory footprint to an ability to pass one more vertex attribute.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;779&quot;&gt;PR with a description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-default-texture-filter&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-default-texture-filter&quot; aria-label=&quot;Anchor link for: macroquad-default-texture-filter&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad: Default texture filter&lt;&#x2F;h1&gt;
&lt;p&gt;There are two ways to set default texture filter:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;window_conf&lt;&#x2F;span&gt;&lt;span&gt;() -&amp;gt; macroquad::conf::Conf {
&lt;&#x2F;span&gt;&lt;span&gt;    macroquad::conf::Conf {
&lt;&#x2F;span&gt;&lt;span&gt;        default_filter_mode: FilterMode::Nearest,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;::default()
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[macroquad::main(window_conf)]
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture: Texture2D &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;pixel.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_background&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;LIGHTGRAY&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_texture_ex&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;texture, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;WHITE&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;or&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_default_filter_mode&lt;&#x2F;span&gt;&lt;span&gt;(FilterMode::Linear);
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; from now on all textures and fonts will be loaded with FilterMode::Linear
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture: Texture2D &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;pixel.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;772&#x2F;&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad-embracing-the-arc&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad-embracing-the-arc&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad-embracing-the-arc&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad: embracing the Arc&lt;&#x2F;h1&gt;
&lt;p&gt;Decision that took waaay to much time to make, but when it is done it feels so good. For the context, thats the problem:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;ferris.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;texture);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build_textures_atlas&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;texture);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;dbg!(telemetry::textures_count());
&lt;&#x2F;span&gt;&lt;span&gt;profiler::ui();
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In macroquad &lt;code&gt;0.3&lt;&#x2F;code&gt; texture was a &lt;code&gt;Copy&lt;&#x2F;code&gt; handle. It would be never deleted unless explicit &lt;code&gt;delete&lt;&#x2F;code&gt; call. Macroquad had no problems of having internal texture references for building atlases, debugging drawcalls and whatnot.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;macroquad-0.4&lt;&#x2F;code&gt; tried to be smart and do a right thing - make &lt;code&gt;Texture&lt;&#x2F;code&gt; a statefull-ish object, that deletes itself following a normal rust lifetimes. It worked, on the surface the API looked reasonable, but it was super missleading: macroquad still needed internal texture references, atlases were still a thing etc. So on Drop texture was not really deleted, it was marked as &amp;quot;ready to delete&amp;quot;, like some sort of a GC.&lt;&#x2F;p&gt;
&lt;p&gt;In &lt;code&gt;macroquad-0.5&lt;&#x2F;code&gt; all this will be gone. &lt;code&gt;load_texture&lt;&#x2F;code&gt; will return an &lt;code&gt;Arc&amp;lt;Texture2d&amp;gt;&lt;&#x2F;code&gt;. draw_texture will require an &lt;code&gt;Arc&amp;lt;Texture2D&amp;gt;&lt;&#x2F;code&gt;. It is clear from the API that &lt;code&gt;draw_texture&lt;&#x2F;code&gt; might store a copy of an arc for some deferred operations. It is clear that &lt;code&gt;Texture2D&lt;&#x2F;code&gt; is, indeed, a Texture, not a handle, and that Arc is an Arc. All this sounds super obvious, but, somehow, it took 2 major versions to implement...&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;texture.rs&quot;&gt;New texture example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;basic_shapes.rs&quot;&gt;New basic_shapes example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;basic_shapes.rs&quot;&gt;For the whole picture, new basic_shapes_compat example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Cross compilation of *quads project from Linux to OSX</title>
        <published>2024-08-02T09:19:42+00:00</published>
        <updated>2024-08-02T09:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/zigbuild-osx/" type="text/html"/>
        <id>https://macroquad.rs/articles/zigbuild-osx/</id>
        
        <content type="html">&lt;p&gt;Initially I thought it would be enough to just add rust target, but it expects for linker to have support of &lt;code&gt;-framework&lt;&#x2F;code&gt; flag and needs MacOS SDK. &lt;code&gt;cargo-zigbuild&lt;&#x2F;code&gt; comes to the rescue.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;add-target&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#add-target&quot; aria-label=&quot;Anchor link for: add-target&quot;&gt;🔗&lt;&#x2F;a&gt;Add target:&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;rustup target add x86_64-apple-darwin
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;download-necessary-sdk&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#download-necessary-sdk&quot; aria-label=&quot;Anchor link for: download-necessary-sdk&quot;&gt;🔗&lt;&#x2F;a&gt;Download necessary sdk&lt;&#x2F;h2&gt;
&lt;p&gt;Luckly there is &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;roblabla&#x2F;MacOSX-SDKs&quot;&gt;this repo&lt;&#x2F;a&gt; with all macos sdks versions. Use needed version. Replace it in the lines below.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;curl -L https:&#x2F;&#x2F;github.com&#x2F;roblabla&#x2F;MacOSX-SDKs&#x2F;releases&#x2F;download&#x2F;13.1&#x2F;MacOSX13.1.sdk.tar.xz &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;| &lt;&#x2F;span&gt;&lt;span&gt;tar xJ
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;install-zig-language-compiler&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#install-zig-language-compiler&quot; aria-label=&quot;Anchor link for: install-zig-language-compiler&quot;&gt;🔗&lt;&#x2F;a&gt;Install Zig language compiler&lt;&#x2F;h2&gt;
&lt;p&gt;Using &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ziglang&#x2F;zig&#x2F;wiki&#x2F;Install-Zig-from-a-Package-Manager&quot;&gt;this guilde&lt;&#x2F;a&gt; for your distribution.
For Ubuntu 20.04 it was:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;snap install zig --classic --beta
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;install-zigbuild&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#install-zigbuild&quot; aria-label=&quot;Anchor link for: install-zigbuild&quot;&gt;🔗&lt;&#x2F;a&gt;Install zigbuild&lt;&#x2F;h2&gt;
&lt;p&gt;Zig provides C cross compiler with stdlib headers and linkers for every platform, so zigbuild empowers rust with ability to link binaries for other platforms almost without restrictions.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;cargo install --locked cargo-zigbuild
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;set-sdkroot-for-zigbuild-to-find-frameworks&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#set-sdkroot-for-zigbuild-to-find-frameworks&quot; aria-label=&quot;Anchor link for: set-sdkroot-for-zigbuild-to-find-frameworks&quot;&gt;🔗&lt;&#x2F;a&gt;Set SDKROOT for zigbuild to find frameworks&lt;&#x2F;h2&gt;
&lt;p&gt;Add this to .bashrc if needed (replace &lt;code&gt;$(pwd)&lt;&#x2F;code&gt; of course)&lt;&#x2F;p&gt;
&lt;h3 id=&quot;for-osx&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#for-osx&quot; aria-label=&quot;Anchor link for: for-osx&quot;&gt;🔗&lt;&#x2F;a&gt;For OSX:&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;export &lt;&#x2F;span&gt;&lt;span&gt;SDKROOT&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;$(&lt;&#x2F;span&gt;&lt;span&gt;pwd&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;)&#x2F;MacOSX13.1.sdk&#x2F;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;cross-compile-using-zig-as-linker&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cross-compile-using-zig-as-linker&quot; aria-label=&quot;Anchor link for: cross-compile-using-zig-as-linker&quot;&gt;🔗&lt;&#x2F;a&gt;Cross-compile using zig as linker&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;cargo zigbuild --release --target x86_64-apple-darwin
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;example&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#example&quot; aria-label=&quot;Anchor link for: example&quot;&gt;🔗&lt;&#x2F;a&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;zigbuild_osx.png&quot; alt=&quot;example app&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #9</title>
        <published>2024-07-22T20:10:42+00:00</published>
        <updated>2024-07-22T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week9/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week9/</id>
        
        <content type="html">&lt;h1 id=&quot;nanoserde&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#nanoserde&quot; aria-label=&quot;Anchor link for: nanoserde&quot;&gt;🔗&lt;&#x2F;a&gt;Nanoserde&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;0-2-0-release-call-for-testing&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#0-2-0-release-call-for-testing&quot; aria-label=&quot;Anchor link for: 0-2-0-release-call-for-testing&quot;&gt;🔗&lt;&#x2F;a&gt;0.2.0 Release - Call for Testing&lt;&#x2F;h2&gt;
&lt;p&gt;Nanoserde will be bumped to &lt;code&gt;v0.2.0&lt;&#x2F;code&gt; in the near future, with a pair of breaking change related to cargo features. Previously, there was no way to separate out the different formats (&lt;code&gt;json&lt;&#x2F;code&gt;, &lt;code&gt;binary&lt;&#x2F;code&gt;, etc.), with all of them compiled each time. After v0.2.0 is release, individual formats may be enabled&#x2F;disabled through the use of the relevant cargo feature. The &lt;code&gt;no_std&lt;&#x2F;code&gt; feature has also been removed, and has been replaced by a &lt;code&gt;std&lt;&#x2F;code&gt; feature which gates both usage on stable rust and SerDe traits on &lt;code&gt;std::collections::{HashMap, HashSet}&lt;&#x2F;code&gt;. &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;nanoserde&#x2F;blob&#x2F;142d80f11f74041fa0c69d16659887d993184d9d&#x2F;README.md?plain=1#L55&quot;&gt;See the documentation for details on both changes&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;These changes are merged in, but have not yet been released to &lt;code&gt;crates-io&lt;&#x2F;code&gt;. If you rely on &lt;code&gt;nanoserde&lt;&#x2F;code&gt;, version &lt;code&gt;0.2.0-beta.0&lt;&#x2F;code&gt; has been released to allow testing prior to the version bump. There should be no other breaking changes beyond the ones described above, but please file an issue if that is not the case. &lt;&#x2F;p&gt;
&lt;h1 id=&quot;sloop&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#sloop&quot; aria-label=&quot;Anchor link for: sloop&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;sloop&quot;&gt;Sloop&lt;&#x2F;a&gt;&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week9&#x2F;sloop.gif&quot; alt=&quot;sloop&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;sloop&quot;&gt;Sloop&lt;&#x2F;a&gt; is a (very) experimental build system. It was an experiment on how hard would it be to build a fairly complex 3d game without cargo. Somehow it worked, and results were too interesting to keep it private.&lt;&#x2F;p&gt;
&lt;p&gt;While it is not very practical(yet), &lt;code&gt;sloop&lt;&#x2F;code&gt; might be a good case study on building a fully custom build system on top of raw &lt;code&gt;rustc&lt;&#x2F;code&gt;, with no &lt;code&gt;cargo&lt;&#x2F;code&gt; involved.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;mastodon.gamedev.place&#x2F;@fedor&#x2F;112873297227332511&quot;&gt;A long mastodon thread on how it works&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;sloop-example-projects&quot;&gt;A few example projects&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(), ()&amp;gt; {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; libc &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;sloop::DependencyBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;deps&#x2F;libc&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; miniquad &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;sloop::DependencyBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;deps&#x2F;miniquad&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;with_dependency&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;libc)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;?&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    sloop::Builder::new()
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;binary&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;TriangleOnTheSloop&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;entrypoint&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;src&#x2F;triangle.rs&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;with_dependency&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;libc)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;with_dependency&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;miniquad)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; ls
&lt;&#x2F;span&gt;&lt;span&gt;build.rs  deps&#x2F;  src&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; sloop
&lt;&#x2F;span&gt;&lt;span&gt;Building libc
&lt;&#x2F;span&gt;&lt;span&gt;Building miniquad
&lt;&#x2F;span&gt;&lt;span&gt;Building TriangleOnTheSloop src&#x2F;triangle.rs
&lt;&#x2F;span&gt;&lt;span&gt;Done!
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; ls
&lt;&#x2F;span&gt;&lt;span&gt;build.rs  deps&#x2F;  src&#x2F;  TriangleOnTheSloop&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #8</title>
        <published>2024-07-15T20:10:42+00:00</published>
        <updated>2024-07-15T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week8/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week8/</id>
        
        <content type="html">&lt;h1 id=&quot;miniquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad&quot; aria-label=&quot;Anchor link for: miniquad&quot;&gt;🔗&lt;&#x2F;a&gt;Miniquad&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;macos-pr&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macos-pr&quot; aria-label=&quot;Anchor link for: macos-pr&quot;&gt;🔗&lt;&#x2F;a&gt;MacOS PR&lt;&#x2F;h2&gt;
&lt;p&gt;A big rewrite of MacOsX implementation by &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;birhburh&quot;&gt;birhburh&lt;&#x2F;a&gt; that fixed a bunch of old old-standing MacOs issues. &lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;462&quot;&gt;PR with the description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad&quot; aria-label=&quot;Anchor link for: macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Macroquad&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;breaking-change-in-load-material&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#breaking-change-in-load-material&quot; aria-label=&quot;Anchor link for: breaking-change-in-load-material&quot;&gt;🔗&lt;&#x2F;a&gt;Breaking change in &lt;code&gt;load_material&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Since &lt;code&gt;0.4.11&lt;&#x2F;code&gt;, macroquad&#x27;s materials could handle uniform arrays. The signature change in &lt;code&gt;load_material&lt;&#x2F;code&gt; was supposed to be backwards compatible, but turned out that&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;it was not quite backwards compatible&lt;&#x2F;li&gt;
&lt;li&gt;the attempt to make it backward compatible introduce a lot of internal complications&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This is the change required to the user code:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span&gt;         MaterialParams {
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-            uniforms: vec![(&amp;quot;Center&amp;quot;.to_owned(), UniformType::Float2)],
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;            uniforms: vec![UniformDesc::new(&amp;quot;Center&amp;quot;, UniformType::Float2)],
&lt;&#x2F;span&gt;&lt;span&gt;             ..Default::default()
&lt;&#x2F;span&gt;&lt;span&gt;         },
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;766&quot;&gt;PR with explanation&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;multiline-draw-text&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#multiline-draw-text&quot; aria-label=&quot;Anchor link for: multiline-draw-text&quot;&gt;🔗&lt;&#x2F;a&gt;Multiline draw_text&lt;&#x2F;h2&gt;
&lt;p&gt;PR by &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cyrgani&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;cyrgani&lt;&#x2F;a&gt;, a highly requested feature, a single function for multiline text. &lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week8&#x2F;multiline.png&quot; alt=&quot;Multiline text&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;751&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;removed-bumpalo-dependency&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#removed-bumpalo-dependency&quot; aria-label=&quot;Anchor link for: removed-bumpalo-dependency&quot;&gt;🔗&lt;&#x2F;a&gt;Removed &lt;code&gt;bumpalo&lt;&#x2F;code&gt; dependency&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;bumpalo&lt;&#x2F;code&gt; was responsible for bumping minimal supported rust version for macroquad quite a few times already. Turned out we only use two functions from &lt;code&gt;bumpalo&lt;&#x2F;code&gt;, and only in &lt;code&gt;experimental::scene&lt;&#x2F;code&gt; module, which is still there mostly for legacy reason - it should be a separate crate!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;768&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;revived-fish&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#revived-fish&quot; aria-label=&quot;Anchor link for: revived-fish&quot;&gt;🔗&lt;&#x2F;a&gt;Revived Fish&lt;&#x2F;h2&gt;
&lt;p&gt;FishGame might be the best big test case for &lt;code&gt;experimental::scene&lt;&#x2F;code&gt;. Turned out that with a few changes it still works with macroquad-0.4. Updated repo: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;FishFight-The-Prequel&quot;&gt;Fish&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week8&#x2F;fish.gif&quot; alt=&quot;fish&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Sorry, I forgot how this game works&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #7</title>
        <published>2024-07-01T20:10:42+00:00</published>
        <updated>2024-07-01T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week7/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week7/</id>
        
        <content type="html">&lt;h1 id=&quot;macroquad-s-set-uniform-arrays&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-s-set-uniform-arrays&quot; aria-label=&quot;Anchor link for: macroquad-s-set-uniform-arrays&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad&#x27;s set_uniform arrays&lt;&#x2F;h1&gt;
&lt;p&gt;Now it is possible to create materials with arrays in uniforms and to set those uniforms by normal macroquad code.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;material.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_uniform&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Color&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, color)
&lt;&#x2F;span&gt;&lt;span&gt;material.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_uniform_array&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Lights&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;light_positions[&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span&gt;]);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;master&#x2F;examples&#x2F;custom_material.rs&quot;&gt;example&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;pull&#x2F;754&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;egui-miniquad-crates-io-release&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#egui-miniquad-crates-io-release&quot; aria-label=&quot;Anchor link for: egui-miniquad-crates-io-release&quot;&gt;🔗&lt;&#x2F;a&gt;egui-miniquad crates.io release&lt;&#x2F;h1&gt;
&lt;p&gt;egui-miniquad compatible with the latest miniquad got crates.io release.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;egui-miniquad&#x2F;releases&#x2F;tag&#x2F;0.15.0&quot;&gt;Release link&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;gizmos&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#gizmos&quot; aria-label=&quot;Anchor link for: gizmos&quot;&gt;🔗&lt;&#x2F;a&gt;Gizmos&lt;&#x2F;h2&gt;
&lt;p&gt;First look onto the gizmos API - a special, no context, no parametrisation way to draw debug UI.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week7&#x2F;gizmo.gif&quot; alt=&quot;gizmos&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;week7&#x2F;gizmo2.gif&quot; alt=&quot;gizmos&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;gizmos&#x2F;main.rs&quot;&gt;A new gizmo example&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;non-exclusive-immidiate-mode&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#non-exclusive-immidiate-mode&quot; aria-label=&quot;Anchor link for: non-exclusive-immidiate-mode&quot;&gt;🔗&lt;&#x2F;a&gt;non-exclusive immidiate mode&lt;&#x2F;h2&gt;
&lt;p&gt;Non-exclusive macroquad-0.4 comaptibility mode allows using the old API alongside the new one, porting old code to new API part by part.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span&gt;async fn game(ctx: macroquad::Context) {
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-    init_compat_mode(ctx);
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;    init_compat_mode(&amp;amp;ctx);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    loop {
&lt;&#x2F;span&gt;&lt;span&gt;        clear_background(LIGHTGRAY);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
&lt;&#x2F;span&gt;&lt;span&gt;        draw_rectangle(screen_width() &#x2F; 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN);
&lt;&#x2F;span&gt;&lt;span&gt;        draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW);
&lt;&#x2F;span&gt;&lt;span&gt;        draw_text(&amp;quot;HELLO&amp;quot;, 20.0, 20.0, 30.0, DARKGRAY);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        next_frame().await
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #6</title>
        <published>2024-06-24T20:10:42+00:00</published>
        <updated>2024-06-24T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week6/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week6/</id>
        
        <content type="html">&lt;h2 id=&quot;better-miniquad-error-handling-on-linux&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#better-miniquad-error-handling-on-linux&quot; aria-label=&quot;Anchor link for: better-miniquad-error-handling-on-linux&quot;&gt;🔗&lt;&#x2F;a&gt;Better miniquad error handling on linux:&lt;&#x2F;h2&gt;
&lt;p&gt;Before:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;thread &amp;#39;main&amp;#39; panicked at &#x2F;home&#x2F;fl3&#x2F;fun&#x2F;miniquad&#x2F;src&#x2F;lib.rs:346:50:
&lt;&#x2F;span&gt;&lt;span&gt;X11 backend failed
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;thread &amp;#39;main&amp;#39; panicked at &#x2F;home&#x2F;fl3&#x2F;fun&#x2F;miniquad&#x2F;src&#x2F;lib.rs:346:50:
&lt;&#x2F;span&gt;&lt;span&gt;X11 backend failed: LibraryNotFound(DlOpenError(&amp;quot;libxkbcommon.so.0&amp;quot;))
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;465&quot;&gt;Link to PR&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;macos-exit-hotkey&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macos-exit-hotkey&quot; aria-label=&quot;Anchor link for: macos-exit-hotkey&quot;&gt;🔗&lt;&#x2F;a&gt;MacOs exit hotkey&lt;&#x2F;h2&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;markmurphydev&quot;&gt;markmurphydev&lt;&#x2F;a&gt; MacOs miniquad window now closes with Cmd-Q and have all the Mac standart application menus.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;464&quot;&gt;Link to PR&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;p&gt;A &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;materials&#x2F;main.rs&quot;&gt;new example&lt;&#x2F;a&gt; with a first take on a (very WIP) material system with customizable uniforms and shaders.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week6&#x2F;helmet.gif&quot; alt=&quot;helmet&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;community-projects&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#community-projects&quot; aria-label=&quot;Anchor link for: community-projects&quot;&gt;🔗&lt;&#x2F;a&gt;Community projects&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;em&gt;Feel free to post your own projects here by opening a PR against &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad-website&#x2F;blob&#x2F;source&#x2F;content&#x2F;twiq&#x2F;week7.md&quot;&gt;next week blogpost&lt;&#x2F;a&gt;.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;miniquad-on-kaios&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad-on-kaios&quot; aria-label=&quot;Anchor link for: miniquad-on-kaios&quot;&gt;🔗&lt;&#x2F;a&gt;miniquad on KaiOS&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week6&#x2F;kaios.jpg&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;birhburh&#x2F;miniquad_kaios_tests&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;birhburh&#x2F;miniquad_kaios_tests&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;(from &lt;a href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;WfEp6ut&quot;&gt;discord&lt;&#x2F;a&gt; #showcase)&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;game-development-in-rust-with-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#game-development-in-rust-with-macroquad&quot; aria-label=&quot;Anchor link for: game-development-in-rust-with-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Game development in Rust with Macroquad&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;A complete guide on how to develop a classic 2D shoot &#x27;em up game using the game library Macroquad and the Rust programming language. It covers everything from a simple Hello World Macroquad application to adding graphics, audio, a shader, a graphical menu, and how to release the game on multiple platforms.&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;(from &lt;a href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;WfEp6ut&quot;&gt;discord&lt;&#x2F;a&gt; #showcase)&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;mq.agical.se&#x2F;&quot;&gt;https:&#x2F;&#x2F;mq.agical.se&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week6&#x2F;mqagical.png&quot; alt=&quot;&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Docker cheatsheat</title>
        <published>2024-06-19T09:19:42+00:00</published>
        <updated>2024-06-19T10:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/docker/" type="text/html"/>
        <id>https://macroquad.rs/articles/docker/</id>
        
        <content type="html">&lt;p&gt;Android SDK is huge and have a lot of dependencies, all of them requires manual installation. Docker allows to make it once and basically clone a linux computer with &lt;a href=&quot;&#x2F;articles&#x2F;android&#x2F;#a-manual-way&quot;&gt;everything android-related&lt;&#x2F;a&gt; already pre-installed.&lt;&#x2F;p&gt;
&lt;p&gt;This article is aimed for folks who never seen docker before. It is not a comprehensive docker tutorial, just a list of things that is possible with &lt;code&gt;cargo-apk&lt;&#x2F;code&gt; image.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;adding-persistent-cache-folder&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#adding-persistent-cache-folder&quot; aria-label=&quot;Anchor link for: adding-persistent-cache-folder&quot;&gt;🔗&lt;&#x2F;a&gt;Adding persistent cache folder&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;code&gt; -v &#x2F;tmp&#x2F;registry\&amp;quot;:&#x2F;usr&#x2F;local&#x2F;cargo&#x2F;registry\&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Full command:
&lt;code&gt;docker run  --rm -v &#x2F;tmp&#x2F;registry:&#x2F;usr&#x2F;local&#x2F;cargo&#x2F;registry -v $(pwd):&#x2F;root&#x2F;src -w &#x2F;root&#x2F;src notfl3&#x2F;cargo-apk cargo quad-apk build --release&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This will tell docker to use &lt;code&gt;&#x2F;tmp&#x2F;registry&lt;&#x2F;code&gt; on the host machine for cargo&#x27;s registry, therefore docker will not download all the dependencies on each build.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;passing-environment-variables&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#passing-environment-variables&quot; aria-label=&quot;Anchor link for: passing-environment-variables&quot;&gt;🔗&lt;&#x2F;a&gt;Passing environment variables&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;code&gt;-e RUST_BACKTRACE=1&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;docker run --rm -e RUST_BACKTRACE=1 -v &#x2F;tmp&#x2F;registry:&#x2F;usr&#x2F;local&#x2F;cargo&#x2F;registry -v $(pwd):&#x2F;root&#x2F;src -w &#x2F;root&#x2F;src notfl3&#x2F;cargo-apk cargo quad-apk build --release&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Useful when &lt;code&gt;cargo-quad-apk&lt;&#x2F;code&gt; does not behave.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;interactive-mode&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#interactive-mode&quot; aria-label=&quot;Anchor link for: interactive-mode&quot;&gt;🔗&lt;&#x2F;a&gt;Interactive mode&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;code&gt;-it .. &#x2F;bin&#x2F;bash&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; docker run 
&lt;&#x2F;span&gt;&lt;span&gt;  --rm 
&lt;&#x2F;span&gt;&lt;span&gt;  -v $(pwd):&#x2F;root&#x2F;src 
&lt;&#x2F;span&gt;&lt;span&gt;  -w &#x2F;root&#x2F;src 
&lt;&#x2F;span&gt;&lt;span&gt;  -it notfl3&#x2F;cargo-apk &#x2F;bin&#x2F;bash
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;[root@5aafd507681b src]#
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will run docker in an interactive mode: it will give a shell inside the container. Running &lt;code&gt;cargo quad-apk build --release&lt;&#x2F;code&gt; from that shell is the fastest way to rebuild the .apk.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;modifying-the-container&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#modifying-the-container&quot; aria-label=&quot;Anchor link for: modifying-the-container&quot;&gt;🔗&lt;&#x2F;a&gt;Modifying the container&lt;&#x2F;h1&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; docker run
&lt;&#x2F;span&gt;&lt;span&gt;  --rm
&lt;&#x2F;span&gt;&lt;span&gt;  -v $(pwd):&#x2F;root&#x2F;src
&lt;&#x2F;span&gt;&lt;span&gt;  -w &#x2F;root&#x2F;src
&lt;&#x2F;span&gt;&lt;span&gt;  -it notfl3&#x2F;cargo-apk &#x2F;bin&#x2F;bash
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt; [&lt;&#x2F;span&gt;&lt;span&gt;root@5aafd507681b src&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;]&lt;&#x2F;span&gt;&lt;span&gt;# rustup update
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; Ctrl-D
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; docker ps -a
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;CONTAINER ID   IMAGE              COMMAND                  CREATED          STATUS    PORTS     NAMES
&lt;&#x2F;span&gt;&lt;span&gt;9470f79a3f61   notfl3&#x2F;cargo-apk   &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;cargo quad-apk buil…&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;   34 seconds ago   Created             determined_satoshi
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; docker commit 9470f79a3f61 better-cargo-apk
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; docker run -it better-cargo-apk &#x2F;bin&#x2F;bash
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Run container in interactive mode, do all the required modifications, stop the container. Than &amp;quot;commit&amp;quot; changes to the container with a new image tag. Than use the new image tag in all docker-related commands. Note: it is possible to use &lt;code&gt;docker commit 9470f79a3f61 notfl3&#x2F;cargo-apk&lt;&#x2F;code&gt;, new tag is an option to roll back into original image.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;apksigner&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#apksigner&quot; aria-label=&quot;Anchor link for: apksigner&quot;&gt;🔗&lt;&#x2F;a&gt;apksigner&lt;&#x2F;h1&gt;
&lt;p&gt;Tools from &lt;a href=&quot;&#x2F;articles&#x2F;android&#x2F;#4-signing-the-apk&quot;&gt;Signing the APK&lt;&#x2F;a&gt; section of android tutorial are all available in the &lt;code&gt;not-fl3&#x2F;cargo-apk&lt;&#x2F;code&gt; container.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;-v(&#x2F;home&#x2F;USER&#x2F;.android):&#x2F;root&#x2F;.android_secrets&lt;&#x2F;code&gt; &lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;docker run --rm -v(&#x2F;home&#x2F;USER&#x2F;.android):&#x2F;root&#x2F;.android_secrets -v (pwd):&#x2F;root&#x2F;src -w &#x2F;root&#x2F;src -it notfl3&#x2F;cargo-apk &#x2F;bin&#x2F;bash&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;will get a shell session with an access to .android and to the project root. &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;[root@960582514a32 src]# apksigner 
&lt;&#x2F;span&gt;&lt;span&gt;USAGE: apksigner &amp;lt;command&amp;gt; [options]
&lt;&#x2F;span&gt;&lt;span&gt;       apksigner --version
&lt;&#x2F;span&gt;&lt;span&gt;       apksigner --help
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;EXAMPLE:
&lt;&#x2F;span&gt;&lt;span&gt;       apksigner sign --ks release.jks app.apk
&lt;&#x2F;span&gt;&lt;span&gt;       apksigner verify --verbose app.apk
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #5</title>
        <published>2024-06-17T20:10:42+00:00</published>
        <updated>2024-06-17T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week5/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week5/</id>
        
        <content type="html">&lt;h1 id=&quot;blocking-event-loop-on-ios-opengl-metal&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#blocking-event-loop-on-ios-opengl-metal&quot; aria-label=&quot;Anchor link for: blocking-event-loop-on-ios-opengl-metal&quot;&gt;🔗&lt;&#x2F;a&gt;blocking_event_loop on ios opengl&#x2F;metal&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;452&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;452&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Shout out to &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;birhburh&quot;&gt;birhburh&lt;&#x2F;a&gt; for finishing a series of PRs porting &lt;code&gt;blocking_event_loop&lt;&#x2F;code&gt; on basically everything!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;docker-article&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#docker-article&quot; aria-label=&quot;Anchor link for: docker-article&quot;&gt;🔗&lt;&#x2F;a&gt;Docker article&lt;&#x2F;h1&gt;
&lt;p&gt;Based on discords frequently asked questions, &lt;a href=&quot;&#x2F;articles&#x2F;docker&quot;&gt;a little docker cheatsheat&lt;&#x2F;a&gt;, showcasing all the things possible with docker and cargo-apk container.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;libxkbcommon-on-nixos&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#libxkbcommon-on-nixos&quot; aria-label=&quot;Anchor link for: libxkbcommon-on-nixos&quot;&gt;🔗&lt;&#x2F;a&gt;libxkbcommon on NixOS&lt;&#x2F;h1&gt;
&lt;p&gt;Just a little note for NixOS users, quads got an extra dependency, update to nix.shell is required.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;456&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>getrandom with *quad on WASM</title>
        <published>2024-06-16T09:19:42+00:00</published>
        <updated>2024-07-16T09:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/getwasm/" type="text/html"/>
        <id>https://macroquad.rs/articles/getwasm/</id>
        
        <content type="html">&lt;p&gt;&lt;em&gt;Article originally posted on &lt;a href=&quot;https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;WfEp6ut&quot;&gt;the discord&lt;&#x2F;a&gt; by &lt;a href=&quot;https:&#x2F;&#x2F;discordapp.com&#x2F;users&#x2F;145509639562199040&quot;&gt;juh9870&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Guide For those who want to use getrandom (mainly for rand or for ahash) with Macroquad.&lt;br &#x2F;&gt;
This method utilizes crypto.getRandomValues for getting cryptographically strong random values, which are good to seed your PRNG (including quad_rand)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;step-1&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#step-1&quot; aria-label=&quot;Anchor link for: step-1&quot;&gt;🔗&lt;&#x2F;a&gt;Step 1&lt;&#x2F;h2&gt;
&lt;p&gt;Add dependencies on getrandom crate with custom feature, and on sapp-jsutil crate for JS bridging&lt;&#x2F;p&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;[target.&amp;#39;cfg(target_arch = &amp;quot;wasm32&amp;quot;)&amp;#39;.dependencies]
&lt;&#x2F;span&gt;&lt;span&gt;getrandom = { version = &amp;quot;0.2&amp;quot;, features = [&amp;quot;custom&amp;quot;] }
&lt;&#x2F;span&gt;&lt;span&gt;sapp-jsutils = { version = &amp;quot;0.1&amp;quot; }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;step-2&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#step-2&quot; aria-label=&quot;Anchor link for: step-2&quot;&gt;🔗&lt;&#x2F;a&gt;Step 2&lt;&#x2F;h2&gt;
&lt;p&gt;Create a file somewhere in your project, and make it wasm-only.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;#[cfg(target_arch &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;wasm32&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;mod &lt;&#x2F;span&gt;&lt;span&gt;getrandom_on_web;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And use the following code&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;sapp_jsutils::JsObject;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;extern &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;C&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;macroquad_js_get_random_buffer&lt;&#x2F;span&gt;&lt;span&gt;(length: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;usize&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; JsObject;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F;&#x2F; Required by `getrandom` crate.
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;getrandom&lt;&#x2F;span&gt;&lt;span&gt;(buf: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;u8&lt;&#x2F;span&gt;&lt;span&gt;]) -&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Result&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;(), getrandom::Error&amp;gt; {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; obj &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= unsafe &lt;&#x2F;span&gt;&lt;span&gt;{ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;macroquad_js_get_random_buffer&lt;&#x2F;span&gt;&lt;span&gt;(buf.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;()) };
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; bytes &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Vec&lt;&#x2F;span&gt;&lt;span&gt;::with_capacity(buf.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;());
&lt;&#x2F;span&gt;&lt;span&gt;    obj.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;to_byte_buffer&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; bytes);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;(target, data) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; buf.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;iter_mut&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;zip&lt;&#x2F;span&gt;&lt;span&gt;(bytes) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;target &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; data;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Ok&lt;&#x2F;span&gt;&lt;span&gt;(())
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;getrandom::register_custom_getrandom&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;(getrandom);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;step-3&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#step-3&quot; aria-label=&quot;Anchor link for: step-3&quot;&gt;🔗&lt;&#x2F;a&gt;Step 3&lt;&#x2F;h2&gt;
&lt;p&gt;Add the JS code to your project to define the function on JS side&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; Plugin registration, see https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;wasm&#x2F; for more info
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;getrandom_plugin &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= function &lt;&#x2F;span&gt;&lt;span&gt;(importObject) {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; make macroquad_js_get_random_buffer() function available to call from rust
&lt;&#x2F;span&gt;&lt;span&gt;    importObject.env.macroquad_js_get_random_buffer &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;macroquad_js_get_random_buffer;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;miniquad_add_plugin&lt;&#x2F;span&gt;&lt;span&gt;({getrandom_plugin});
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;function &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;macroquad_js_get_random_buffer&lt;&#x2F;span&gt;&lt;span&gt;(length) {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;myArray &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= new &lt;&#x2F;span&gt;&lt;span&gt;Uint8Array(length);
&lt;&#x2F;span&gt;&lt;span&gt;    crypto.&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;getRandomValues&lt;&#x2F;span&gt;&lt;span&gt;(myArray);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;js_object&lt;&#x2F;span&gt;&lt;span&gt;(myArray);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #4</title>
        <published>2024-06-03T20:10:42+00:00</published>
        <updated>2024-06-03T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week4/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week4/</id>
        
        <content type="html">&lt;h1 id=&quot;blocking-event-loop-on-ios-opengl-metal&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#blocking-event-loop-on-ios-opengl-metal&quot; aria-label=&quot;Anchor link for: blocking-event-loop-on-ios-opengl-metal&quot;&gt;🔗&lt;&#x2F;a&gt;blocking_event_loop on ios opengl&#x2F;metal&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;452&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;452&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Shout out to &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;birhburh&quot;&gt;birhburh&lt;&#x2F;a&gt; for finishing a series of PRs porting &lt;code&gt;blocking_event_loop&lt;&#x2F;code&gt; on basically everything!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;article-on-getrandom-for-quad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#article-on-getrandom-for-quad&quot; aria-label=&quot;Anchor link for: article-on-getrandom-for-quad&quot;&gt;🔗&lt;&#x2F;a&gt;Article on getrandom for *quad&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;getwasm&#x2F;&quot;&gt;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;getwasm&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Most rust crates just assume that everyone use a non-standart, third party binary, wasm-bindgen, to post-process .wasm files on web. &lt;code&gt;rand&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;ahash&lt;&#x2F;code&gt; a very popular crates, and one of the very few crates in the ecosystem that acknowledge that not everyone use wasm-bindgen.&lt;&#x2F;p&gt;
&lt;p&gt;Approach from the article demonstrates a completely different approach for wasm32 dependencies management: &amp;quot;getrandom&amp;quot; do not know about miniquad existence, do not depend on &amp;quot;miniquad&amp;quot; in any way, but it is still usable from a miniquad based project!&lt;&#x2F;p&gt;
&lt;h1 id=&quot;html-template&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#html-template&quot; aria-label=&quot;Anchor link for: html-template&quot;&gt;🔗&lt;&#x2F;a&gt;html template&lt;&#x2F;h1&gt;
&lt;p&gt;Android Chrome  on some phones render a page slightly zoomed by default. This results into some part of the *quad canvas being rendered behind the navigation bar. &lt;&#x2F;p&gt;
&lt;p&gt;Adding &lt;code&gt;&amp;lt;meta name=&amp;quot;viewport&amp;quot; content=&amp;quot;width=device-width, initial-scale=1&amp;quot; &#x2F;&amp;gt;&lt;&#x2F;code&gt; fixed the problem, therefore the new recommended html template is:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;html&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-html &quot;&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;html &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;lang&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;en&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;head&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;meta &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;charset&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;meta &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;viewport&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;content&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;width=device-width, initial-scale=1&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;title&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;TITLE&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;title&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;style&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;html&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;canvas &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;margin&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;px&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;padding&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;px&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;width&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;height&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;overflow&lt;&#x2F;span&gt;&lt;span&gt;: hidden;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;position&lt;&#x2F;span&gt;&lt;span&gt;: absolute;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;background&lt;&#x2F;span&gt;&lt;span&gt;: black;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;z-index&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;style&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;head&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;canvas &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;id&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;glcanvas&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;tabindex&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;#39;1&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;canvas&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&amp;lt;!-- Minified and statically hosted version of https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;master&#x2F;js&#x2F;mq_js_bundle.js --&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;src&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;https:&#x2F;&#x2F;not-fl3.github.io&#x2F;miniquad-samples&#x2F;mq_js_bundle.js&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;load(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;CRATENAME.wasm&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&amp;lt;!-- Your compiled wasm file --&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;html&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week4&#x2F;race.gif&quot; alt=&quot;race&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Old GIF for a 3d macroquad test project&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;API compatibility was a big challange for a new, 3d-capable macroquad. Now we have a working prototype of a way to build an (almost)0.4 compatible, UB&#x2F;statics free API:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;macroquad::compat::&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;game&lt;&#x2F;span&gt;&lt;span&gt;(ctx: macroquad::Context) {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;init_compat_mode&lt;&#x2F;span&gt;&lt;span&gt;(ctx);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_background&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;LIGHTGRAY&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_line&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;40.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;40.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;200.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;15.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;BLUE&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_rectangle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_width&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2.0 &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;60.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;120.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;60.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;GREEN&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_circle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_width&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_height&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;15.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;YELLOW&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_text&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;HELLO&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;20.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;20.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;DARKGRAY&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    macroquad::start(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;::default(), |ctx| &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;game&lt;&#x2F;span&gt;&lt;span&gt;(ctx));
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;basic_shapes_compat.rs&quot;&gt;basic_shapes_compat.rs&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;While it is possible to use a new, more fine-graded API:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;0.5&#x2F;examples&#x2F;basic_shapes.rs&quot;&gt;basic_shapes.rs&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #3</title>
        <published>2024-05-27T20:10:42+00:00</published>
        <updated>2024-05-27T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week3/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week3/</id>
        
        <content type="html">&lt;h1 id=&quot;blocking-event-loop-on-mac-os&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#blocking-event-loop-on-mac-os&quot; aria-label=&quot;Anchor link for: blocking-event-loop-on-mac-os&quot;&gt;🔗&lt;&#x2F;a&gt;blocking_event_loop on Mac OS&lt;&#x2F;h1&gt;
&lt;p&gt;A PR by &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;birhburh&quot;&gt;birhburh&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;443&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;443&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-configuration&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-configuration&quot; aria-label=&quot;Anchor link for: macroquad-configuration&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad configuration&lt;&#x2F;h1&gt;
&lt;p&gt;Before, in the following example, &lt;code&gt;config&lt;&#x2F;code&gt; was supposed to return miniquad&#x27;s &lt;code&gt;Conf&lt;&#x2F;code&gt; struct.
Now it can return either miniquad&#x27;s &lt;code&gt;Conf&lt;&#x2F;code&gt; directly and get macroquad&#x27;s default launch arguments, or return macroquad&#x27;s &lt;code&gt;Conf&lt;&#x2F;code&gt; and configure macroquad-specific things.&lt;&#x2F;p&gt;
&lt;p&gt;As the first macroquad-specifc argument, it is now possible to specify which event will wake macroquad up from &lt;code&gt;blocking_event_loop&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In other words, this code will print &amp;quot;tick&amp;quot; only after &amp;quot;Space&amp;quot; press.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;config&lt;&#x2F;span&gt;&lt;span&gt;() -&amp;gt; macroquad::conf::Conf {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; conf: miniquad::conf::Conf &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;::default();
&lt;&#x2F;span&gt;&lt;span&gt;    conf.platform.blocking_event_loop &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    Conf {
&lt;&#x2F;span&gt;&lt;span&gt;        miniquad_conf: conf,
&lt;&#x2F;span&gt;&lt;span&gt;        update_on: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(UpdateTrigger {
&lt;&#x2F;span&gt;&lt;span&gt;            specific_key: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(vec![KeyCode::Space])
&lt;&#x2F;span&gt;&lt;span&gt;        })
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;#[macroquad::main(config)]
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;tick&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;optional-webgl2-support-on-wasm&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#optional-webgl2-support-on-wasm&quot; aria-label=&quot;Anchor link for: optional-webgl2-support-on-wasm&quot;&gt;🔗&lt;&#x2F;a&gt;Optional WebGL2 support on wasm&lt;&#x2F;h1&gt;
&lt;p&gt;Miniquad always used webgl1 as the most commonly supported web graphics API.
Now it is possible to optionally create webgl2 context and use &lt;code&gt;version 300 es&lt;&#x2F;code&gt; shaders within a standart miniquad.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;444&quot;&gt;PR with description&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;macroquad-test-suite&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#macroquad-test-suite&quot; aria-label=&quot;Anchor link for: macroquad-test-suite&quot;&gt;🔗&lt;&#x2F;a&gt;macroquad test suite&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;code&gt;quadtest&lt;&#x2F;code&gt; is a little project that collects *quad related regressions in a single binary. This week it got a few atlas related tests.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week3&#x2F;quadtest.gif&quot; alt=&quot;quadtest&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #2</title>
        <published>2024-05-20T20:10:42+00:00</published>
        <updated>2024-05-20T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week2/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week2/</id>
        
        <content type="html">&lt;h2 id=&quot;option-to-reduce-cpu-usage-to-zero-when-waiting-for-an-incoming-event&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#option-to-reduce-cpu-usage-to-zero-when-waiting-for-an-incoming-event&quot; aria-label=&quot;Anchor link for: option-to-reduce-cpu-usage-to-zero-when-waiting-for-an-incoming-event&quot;&gt;🔗&lt;&#x2F;a&gt;Option to reduce CPU usage to zero when waiting for an incoming event&lt;&#x2F;h2&gt;
&lt;p&gt;Now its possible to halt rendering when waiting for the event.
In other words, with &lt;code&gt;blocking_event_loop: true&lt;&#x2F;code&gt; the following code will not print &lt;code&gt;Frame update&lt;&#x2F;code&gt; all the time, while the button will be responsive and the &amp;quot;animation&amp;quot; will still be smooth.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[macroquad::main(window_conf)]
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; timer_frames &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        info!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Frame updated&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_background&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;LIGHTGRAY&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;ui::root_ui().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;button&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Test&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;            info!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Button pressed&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;            timer_frames &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;50&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; timer_frames &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;!= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            timer_frames &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;-= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_rectangle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, timer_frames &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32 * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;20.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;60.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;GREEN&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;            macroquad::miniquad::window::schedule_update();
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;437&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;js-version-versioning-rework&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#js-version-versioning-rework&quot; aria-label=&quot;Anchor link for: js-version-versioning-rework&quot;&gt;🔗&lt;&#x2F;a&gt;JS version versioning rework&lt;&#x2F;h2&gt;
&lt;p&gt;Since miniquad 0.3 pretty much all *quad based app started their life with this error.
&lt;img src=&quot;&#x2F;week2&#x2F;error.png&quot; alt=&quot;error&quot; &#x2F;&gt;&lt;br &#x2F;&gt;
&lt;em&gt;Version mismatch: gl.js version...&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;There was no trivial fix due to the versioning scheme miniquad used to have: each js file was suppose to correspond to the exact crate version.
Now rust code can explicitly say which JS version it needs, which accomodates a lot better a real world scneario when rust crates updates a lot more frequently than JS.&lt;&#x2F;p&gt;
&lt;p&gt;Migration to a new scheme example:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span style=&quot;background-color:#ffecec;font-weight:bold;font-style:italic;color:#bd2c00;&quot;&gt;---&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt; a&#x2F;js&#x2F;audio.js
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;font-style:italic;color:#55a532;&quot;&gt;+++&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt; b&#x2F;js&#x2F;audio.js
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;font-style:italic;color:#969896;&quot;&gt;@@ -189,4 +189,4 @@ function register_plugin(importObject) {
&lt;&#x2F;span&gt;&lt;span&gt;     importObject.env.audio_playback_set_volume = audio_playback_set_volume;
&lt;&#x2F;span&gt;&lt;span&gt; }
&lt;&#x2F;span&gt;&lt;span&gt; 
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-miniquad_add_plugin({ register_plugin, version: &amp;quot;0.1.0&amp;quot;, name: &amp;quot;macroquad_audio&amp;quot; });
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;miniquad_add_plugin({ register_plugin, version: 1, name: &amp;quot;macroquad_audio&amp;quot; });
&lt;&#x2F;span&gt;&lt;span&gt;diff --git a&#x2F;src&#x2F;web_snd.rs b&#x2F;src&#x2F;web_snd.rs
&lt;&#x2F;span&gt;&lt;span&gt;index 357ec30..8c61541 100644
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;font-weight:bold;font-style:italic;color:#bd2c00;&quot;&gt;---&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt; a&#x2F;src&#x2F;web_snd.rs
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;font-style:italic;color:#55a532;&quot;&gt;+++&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt; b&#x2F;src&#x2F;web_snd.rs
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;font-style:italic;color:#969896;&quot;&gt;@@ -14,11 +14,7 @@ extern &amp;quot;C&amp;quot; {
&lt;&#x2F;span&gt;&lt;span&gt; #[no_mangle]
&lt;&#x2F;span&gt;&lt;span&gt; pub extern &amp;quot;C&amp;quot; fn macroquad_audio_crate_version() -&amp;gt; u32 {
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-    let major = 0;
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-    let minor = 1;
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-    let patch = 0;
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-    (major &amp;lt;&amp;lt; 24) + (minor &amp;lt;&amp;lt; 16) + patch
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;    1
&lt;&#x2F;span&gt;&lt;span&gt; }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;436&quot;&gt;PR with details&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;atlases-fix&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#atlases-fix&quot; aria-label=&quot;Anchor link for: atlases-fix&quot;&gt;🔗&lt;&#x2F;a&gt;Atlases fix&lt;&#x2F;h1&gt;
&lt;p&gt;If &lt;code&gt;build_textures_atlas&lt;&#x2F;code&gt; sometimes leaded to weird visual artifacts - it might be fixed now.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture: Texture2D &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;examples&#x2F;ferris.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;texture::build_textures_atlas();
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_background&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;LIGHTGRAY&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;texture, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;WHITE&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Before&lt;br &#x2F;&gt;
&lt;img src=&quot;&#x2F;week2&#x2F;ferris2.png&quot; alt=&quot;2&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After&lt;br &#x2F;&gt;
&lt;img src=&quot;&#x2F;week2&#x2F;ferris1.png&quot; alt=&quot;1&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h1&gt;
&lt;p&gt;Main new macroquad promise: we are not limited to static batching anymore, it should be possible to explicitly batch geometry, draw directly or use instanced rendering.&lt;&#x2F;p&gt;
&lt;p&gt;This is an attempt to reproduce &lt;a href=&quot;https:&#x2F;&#x2F;www.goodboydigital.com&#x2F;pixijs&#x2F;bunnymark&#x2F;&quot;&gt;pixijs&#x27;s bunnymark&lt;&#x2F;a&gt; with new macroquad&#x27;s instanced rendering.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;not-fl3.github.io&#x2F;miniquad-samples&#x2F;bunnies&#x2F;index.html&quot;&gt;Web build&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;quad-gl&#x2F;blob&#x2F;v0.4&#x2F;examples&#x2F;bunnymark.rs&quot;&gt;Source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;week2&#x2F;bunnies2.png&quot; alt=&quot;basic-shapes&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;On my t480 it gives ~20fps on 400k bunnies, while old, static-only macroquad was capable of 15fps at 20k bunnies.&lt;&#x2F;p&gt;
&lt;p&gt;Next goal - make it actually usable, and add instanced rendering &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;quad-gl&#x2F;blob&#x2F;v0.4&#x2F;examples&#x2F;basic_shapes.rs&quot;&gt;normal shapes example&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>This Week in Quads #1</title>
        <published>2024-05-12T20:10:42+00:00</published>
        <updated>2024-05-12T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/twiq/week1/" type="text/html"/>
        <id>https://macroquad.rs/twiq/week1/</id>
        
        <content type="html">&lt;h2 id=&quot;post-1&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#post-1&quot; aria-label=&quot;Anchor link for: post-1&quot;&gt;🔗&lt;&#x2F;a&gt;Post #1!&lt;&#x2F;h2&gt;
&lt;p&gt;Now we have an &lt;a href=&quot;http:&#x2F;&#x2F;macroquad.rs&#x2F;atom.xml&quot;&gt;RSS feed&lt;&#x2F;a&gt; with a small, low effort, weekly progress summary.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;cargo-webquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cargo-webquad&quot; aria-label=&quot;Anchor link for: cargo-webquad&quot;&gt;🔗&lt;&#x2F;a&gt;cargo webquad&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;cargo-webquad&#x2F;&quot;&gt;cargo-webquad&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;One single command to &amp;quot;run&amp;quot; quad based project on web. Handy for quick dev builds.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;&amp;gt; cargo quadweb serve --example basic_shapes --assets examples
&lt;&#x2F;span&gt;&lt;span&gt;    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
&lt;&#x2F;span&gt;&lt;span&gt;Copying examples to &amp;quot;****&#x2F;target&#x2F;web-artifacts&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;addr: http:&#x2F;&#x2F;localhost:8080
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;embracing-hashmaps&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#embracing-hashmaps&quot; aria-label=&quot;Anchor link for: embracing-hashmaps&quot;&gt;🔗&lt;&#x2F;a&gt;Embracing HashMaps&lt;&#x2F;h2&gt;
&lt;p&gt;Fairly big change from &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;eloraiby&quot;&gt;eloraiby&lt;&#x2F;a&gt;: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;pull&#x2F;428&quot;&gt;miniquad&#x2F;pull&#x2F;428&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Instead of evergrowing plain vectors, miniquad resources now lives in HashMaps. No API changes, no measurable performance regressions and no constant memory leaks.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;road-to-3d-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#road-to-3d-macroquad&quot; aria-label=&quot;Anchor link for: road-to-3d-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Road to 3d macroquad&lt;&#x2F;h2&gt;
&lt;p&gt;Sneak-peak into graphics part of future macroquad is now available as &amp;quot;v0.4&amp;quot; branch of quad-gl. Super unstable and highly experimental!&lt;&#x2F;p&gt;
&lt;p&gt;Gradual batching control with very macroquad-like API:
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;quad-gl&#x2F;blob&#x2F;v0.4&#x2F;examples&#x2F;basic_shapes.rs&quot;&gt;basic-shapes&lt;&#x2F;a&gt;
&lt;img src=&quot;&#x2F;week1&#x2F;basic_shapes.gif&quot; alt=&quot;basic-shapes&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;And some basic 3d rendering:
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;quad-gl&#x2F;blob&#x2F;v0.4&#x2F;examples&#x2F;gltf.rs&quot;&gt;gltf&lt;&#x2F;a&gt;
&lt;img src=&quot;&#x2F;week1&#x2F;h.gif&quot; alt=&quot;helmet&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Macroquad 0.4 changelog</title>
        <published>2023-07-12T09:19:42+00:00</published>
        <updated>2023-07-12T09:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/macroquad-0-4/" type="text/html"/>
        <id>https://macroquad.rs/articles/macroquad-0-4/</id>
        
        <content type="html">&lt;h1 id=&quot;miniquad-update&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#miniquad-update&quot; aria-label=&quot;Anchor link for: miniquad-update&quot;&gt;🔗&lt;&#x2F;a&gt;Miniquad update&lt;&#x2F;h1&gt;
&lt;p&gt;Miniquad update did not affected userspace macroquad at all, all the examples and demos were completely intact. Except &lt;code&gt;use macroquad::miniquad::*&lt;&#x2F;code&gt; case.&lt;&#x2F;p&gt;
&lt;p&gt;Just for the &lt;code&gt;use macroquad::miniquad::*&lt;&#x2F;code&gt; case, here is a short recap of a miniquad changelog:&lt;&#x2F;p&gt;
&lt;p&gt;No more &amp;quot;Context&amp;quot; for event handlers.
RenderingBackend is now owned by the client code, and for window manipulation miniquad now provide a static &amp;quot;window&amp;quot; module.&lt;&#x2F;p&gt;
&lt;p&gt;For events, it looks like:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span&gt;impl EventHandler for Stage {
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-    fn update(&amp;amp;mut self, _ctx: &amp;amp;mut Context) {
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;    fn update(&amp;amp;mut self) {
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For functions that used to be part of the context, it became:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;- ctx.screen_size();
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt; window::screen_size()
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And for rendering functions, now its&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; gl_context &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;GlContext::new();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;gl_context.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;begin_default_pass&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In multiple places miniquad used to receive arguments like this:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;pub fn immutable&amp;lt;T&amp;gt;(ctx: &amp;amp;mut Context, buffer_type: BufferType, data: &amp;amp;[T]) -&amp;gt; Buffer;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With rendering backend being a trait object, this is no longer possible.
Now it looks like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;new_buffer_immutable&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut &lt;&#x2F;span&gt;&lt;span&gt;self, buffer_type: BufferType, data: BufferSource) -&amp;gt; BufferId;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;On the call site, the change required is:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;- .. &amp;amp;indices);
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt; BufferSource::slice(&amp;amp;indices));
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;deprecated-ex-0-2-function-got-removed&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deprecated-ex-0-2-function-got-removed&quot; aria-label=&quot;Anchor link for: deprecated-ex-0-2-function-got-removed&quot;&gt;🔗&lt;&#x2F;a&gt;Deprecated ex-0.2 function got removed&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;code&gt;draw_texture_rec&lt;&#x2F;code&gt;&lt;br &#x2F;&gt;
&lt;code&gt;widgets::InputField&lt;&#x2F;code&gt;&lt;br &#x2F;&gt;
&lt;code&gt;ui::input_field&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;thread-safety&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#thread-safety&quot; aria-label=&quot;Anchor link for: thread-safety&quot;&gt;🔗&lt;&#x2F;a&gt;Thread safety&lt;&#x2F;h1&gt;
&lt;p&gt;Macroquad always assumed WASM as a primary target and was very thread-unsafe. Before 0.4 using macroquad from different thread was basically an UB. 0.4 is still mostly single-threaded, but, at least, wrong usage will lead into a panic, not into a UB.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;camera-consistency&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#camera-consistency&quot; aria-label=&quot;Anchor link for: camera-consistency&quot;&gt;🔗&lt;&#x2F;a&gt;Camera consistency&lt;&#x2F;h1&gt;
&lt;p&gt;Small change, but there was a lot of issues with that - now render target camera and a normal camera have the Y axis.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;default-features&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#default-features&quot; aria-label=&quot;Anchor link for: default-features&quot;&gt;🔗&lt;&#x2F;a&gt;Default features&lt;&#x2F;h1&gt;
&lt;p&gt;Cargo features are additive: let&#x27;s say there is a crate A, depending on crate B and C.&lt;&#x2F;p&gt;
&lt;p&gt;If crate B depends on &amp;quot;Dependency&amp;quot; with feature &amp;quot;Foo&amp;quot; and crate C depends on the same &amp;quot;Dependency&amp;quot; with feature &amp;quot;Bar&amp;quot;, cargo will add just one crate into a build process, &amp;quot;Dependency&amp;quot;, with both features &amp;quot;Foo&amp;quot; and &amp;quot;Bar&amp;quot; on.&lt;&#x2F;p&gt;
&lt;p&gt;In macroquad 0.3 a library using macroquad like this: &lt;code&gt;macroquad = &amp;quot;0.3&amp;quot;&lt;&#x2F;code&gt; was silently introducing &amp;quot;audio&amp;quot; feature in the dependency tree. It was very counterintuitive and required complicated workarounds.&lt;&#x2F;p&gt;
&lt;p&gt;After 0.4 macroquad introduce new, no-default, features policy. It will make life of libraries authors a lot easier: &lt;code&gt;macroquad = &amp;quot;0.4&amp;quot;&lt;&#x2F;code&gt; in a sub-dependencies Cargo.toml will never bring new, unwanted features.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;resources-management&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#resources-management&quot; aria-label=&quot;Anchor link for: resources-management&quot;&gt;🔗&lt;&#x2F;a&gt;Resources management&lt;&#x2F;h1&gt;
&lt;p&gt;in 0.3, all resources was &lt;code&gt;Copy&lt;&#x2F;code&gt;, which prevented them to have proper destructors.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;examples&#x2F;ferris.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;this snipped used to be a memory leak. While it almost never a good idea to load new resources mid-frame, it was still very un-idiomatic.
0.4 fixes this. All resources are just &lt;code&gt;Clone&lt;&#x2F;code&gt;, not &lt;code&gt;Copy&lt;&#x2F;code&gt; and they all acts like smart-pointers: &lt;code&gt;texture.clone()&lt;&#x2F;code&gt; is really really cheap, its okay to do a &lt;code&gt;.clone()&lt;&#x2F;code&gt; of any resource multiple times a frame: its just a pointer clone, not actual texture clone.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture: Texture2D &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;examples&#x2F;ferris.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; will print 1 cause there is only 1 texture loaded
&lt;&#x2F;span&gt;&lt;span&gt;    println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, telemetry::textures_count());
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture1: Texture2D &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;examples&#x2F;ferris.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; will naturally print 2 cause there is only 1 texture loaded
&lt;&#x2F;span&gt;&lt;span&gt;        println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, telemetry::textures_count());
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; texture2 &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; texture.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clone&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; will still print 2, texture.clone() is a cheap texture handle clone, not
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; a real &amp;quot;deep&amp;quot; clone, it does not create a new texture
&lt;&#x2F;span&gt;&lt;span&gt;        println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, telemetry::textures_count());
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; will print 1 again, texture1 and 2 got deleted automatically
&lt;&#x2F;span&gt;&lt;span&gt;    println!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, telemetry::textures_count());
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As an example of a cheap &lt;code&gt;.clone&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;    loop {
&lt;&#x2F;span&gt;&lt;span&gt;        &#x2F;&#x2F; drawing to the texture
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &#x2F;&#x2F; 0..100, 0..100 camera
&lt;&#x2F;span&gt;&lt;span&gt;        set_camera(&amp;amp;Camera2D {
&lt;&#x2F;span&gt;&lt;span&gt;            zoom: vec2(0.01, 0.01),
&lt;&#x2F;span&gt;&lt;span&gt;            target: vec2(0.0, 0.0),
&lt;&#x2F;span&gt;&lt;span&gt;            render_target: Some(render_target.clone()), &#x2F;&#x2F; this .clone is fine, it will only clone a reference
&lt;&#x2F;span&gt;&lt;span&gt;            ..Default::default()
&lt;&#x2F;span&gt;&lt;span&gt;        });
&lt;&#x2F;span&gt;&lt;span&gt;        ...
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;error-handling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#error-handling&quot; aria-label=&quot;Anchor link for: error-handling&quot;&gt;🔗&lt;&#x2F;a&gt;Error handling&lt;&#x2F;h1&gt;
&lt;p&gt;The last panicking functions were eliminated. Now everything returns &lt;code&gt;Result&amp;lt;_, macroquad::Error&amp;gt;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;metal-shaders&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#metal-shaders&quot; aria-label=&quot;Anchor link for: metal-shaders&quot;&gt;🔗&lt;&#x2F;a&gt;Metal shaders&lt;&#x2F;h1&gt;
&lt;p&gt;macroquad do not (yet) have any shader&#x27;s cross compilers, so now all custom shaders requires &lt;code&gt;ShaderSource&lt;&#x2F;code&gt; struct with glsl and metal shader sources instead of just glsl.
With metal being opt-in feature this should be fine, at least until macroquad will get a shader cross-compiler.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;diff&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-diff &quot;&gt;&lt;code class=&quot;language-diff&quot; data-lang=&quot;diff&quot;&gt;&lt;span&gt;             load_material(
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-                DEFAULT_VERTEX_SHADER,
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#ffecec;color:#323232;&quot;&gt;-                DEFAULT_FRAGMENT_SHADER,
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;                ShaderSource {
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;                    glsl_vertex: Some(DEFAULT_VERTEX_SHADER),
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;                    glsl_fragment: Some(DEFAULT_FRAGMENT_SHADER),
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;                    metal_shader: None,
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;font-weight:bold;color:#55a532;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#eaffea;color:#323232;&quot;&gt;                },
&lt;&#x2F;span&gt;&lt;span&gt;                 mq::material::MaterialParams::default(),
&lt;&#x2F;span&gt;&lt;span&gt;             )
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Macroquad on iOS</title>
        <published>2022-10-31T09:19:42+00:00</published>
        <updated>2022-10-31T10:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/ios/" type="text/html"/>
        <id>https://macroquad.rs/articles/ios/</id>
        
        <content type="html">&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;ios&#x2F;ios_zemeroth.png&quot; alt=&quot;zemeroth&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;setting-up-a-macroquad-project&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-up-a-macroquad-project&quot; aria-label=&quot;Anchor link for: setting-up-a-macroquad-project&quot;&gt;🔗&lt;&#x2F;a&gt;Setting up a macroquad project&lt;&#x2F;h1&gt;
&lt;p&gt;This article assume that all the commands are invoked in the root folder of any mini&#x2F;macroquad based project. For simplicity, lets assumet that this project was created like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cargo init mygame
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cd mygame
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cargo add macroquad
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cat &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; src&#x2F;main.rs &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;lt;&amp;lt; EOF
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;use macroquad::prelude::*;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;#[macroquad::main(&amp;quot;MyGame&amp;quot;)]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;async fn main() {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;    loop {
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;        clear_background(RED);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;        draw_circle(200.0, 200.0, 60.0, YELLOW);
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;        next_frame().await
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;    }
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;}
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;EOF
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;building-for-the-simulator&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#building-for-the-simulator&quot; aria-label=&quot;Anchor link for: building-for-the-simulator&quot;&gt;🔗&lt;&#x2F;a&gt;Building for the simulator&lt;&#x2F;h1&gt;
&lt;p&gt;iOS application is just a normal folder, named like &amp;quot;MyGame.app&amp;quot;. This folder contains the binary, a file with a metadata and all the resources.&lt;br &#x2F;&gt;
The binary is a normal, cargo-produced, binary and resources are normal files, just like on any other platform. There is no third-party post-processors, resource compilators or anything like this.&lt;br &#x2F;&gt;
Create a folder, copy your binary and resources and it is a valid iOS application!&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;mkdir MyGame.app
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;cargo build --target x86_64-apple-ios --release
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;cp target&#x2F;x86_64-apple-ios&#x2F;release&#x2F;mygame MyGame.app
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;cat &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; MyGame.app&#x2F;Info.plist &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;lt;&amp;lt; EOF
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;!DOCTYPE plist PUBLIC &amp;quot;-&#x2F;&#x2F;Apple&#x2F;&#x2F;DTD PLIST 1.0&#x2F;&#x2F;EN&amp;quot; &amp;quot;http:&#x2F;&#x2F;www.apple.com&#x2F;DTDs&#x2F;PropertyList-1.0.dtd&amp;quot;&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;plist version=&amp;quot;1.0&amp;quot;&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;dict&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;key&amp;gt;CFBundleExecutable&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;string&amp;gt;mygame&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;key&amp;gt;CFBundleIdentifier&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;string&amp;gt;com.mygame&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;key&amp;gt;CFBundleName&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;string&amp;gt;mygame&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;key&amp;gt;CFBundleVersion&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;string&amp;gt;1&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;key&amp;gt;CFBundleShortVersionString&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;string&amp;gt;1.0&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;&#x2F;dict&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;&#x2F;plist&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;EOF
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# only once, to get the emulator running
&lt;&#x2F;span&gt;&lt;span&gt;xcrun simctl list
&lt;&#x2F;span&gt;&lt;span&gt;xcrun simctl boot LONG_HEX_ID_OF_REQUIRED_IPHONE_FROM_SIMCTL_LIST
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# also just once, to show the simulator UI
&lt;&#x2F;span&gt;&lt;span&gt;open &#x2F;Applications&#x2F;Xcode.app&#x2F;Contents&#x2F;Developer&#x2F;Applications&#x2F;Simulator.app&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# on each build, to run the game
&lt;&#x2F;span&gt;&lt;span&gt;xcrun simctl install booted MyGame.app&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;xcrun simctl launch booted com.mygame
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;note&lt;&#x2F;strong&gt; on resources. All the files inside &amp;quot;MyGame.app&#x2F;assets&amp;quot; are accesible to &lt;code&gt;miniquad::fs&lt;&#x2F;code&gt; just like on any other platform.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;├── MyGame.app
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── mygame
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── Info.plist
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── assets
&lt;&#x2F;span&gt;&lt;span&gt;│   │   ├── texture.png
&lt;&#x2F;span&gt;&lt;span&gt;│   │   ├── someronfile.ron
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;load_texture(&amp;quot;texture.png&amp;quot;)&lt;&#x2F;code&gt; or &lt;code&gt;load_file(&amp;quot;someronfile.ron&amp;quot;)&lt;&#x2F;code&gt; will work just fine.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;simulator-logs&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#simulator-logs&quot; aria-label=&quot;Anchor link for: simulator-logs&quot;&gt;🔗&lt;&#x2F;a&gt;Simulator logs&lt;&#x2F;h1&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;xcrun simctl spawn booted log stream --predicate &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;#39;processImagePath endswith &amp;quot;mygame&amp;quot;&amp;#39;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;deploying-on-the-real-device-with&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deploying-on-the-real-device-with&quot; aria-label=&quot;Anchor link for: deploying-on-the-real-device-with&quot;&gt;🔗&lt;&#x2F;a&gt;Deploying on the real device with&lt;&#x2F;h1&gt;
&lt;p&gt;The real device use exactly the same &amp;quot;application bundle&amp;quot; format - its a &amp;quot;Name.app&amp;quot; folder with a binary, Info.plist and resources.&lt;&#x2F;p&gt;
&lt;p&gt;But real device use aarch64-apple-ios instead of x86_64-apple-ios and it requires the bundle to be signed.&lt;&#x2F;p&gt;
&lt;p&gt;Which means - to install and run the app, following conditions should be met:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;the bundle(Name.app folder) should contain a &amp;quot;embedded.mobileprovision&amp;quot; file&lt;&#x2F;li&gt;
&lt;li&gt;in iphone&#x27;s settings, in General -&amp;gt; &amp;quot;VPN &amp;amp; Device Management&amp;quot; should be a record with your team name&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;getting-provisioning-profile-files&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#getting-provisioning-profile-files&quot; aria-label=&quot;Anchor link for: getting-provisioning-profile-files&quot;&gt;🔗&lt;&#x2F;a&gt;Getting provisioning profile files&lt;&#x2F;h2&gt;
&lt;p&gt;This is ridicoulosly painful proces. Brace yourself!
Good news - its only a one time thing. With all the certificates being available installing the app to an iphone works just as smooth as to the simulator!&lt;&#x2F;p&gt;
&lt;p&gt;A lot of credits goes to this article: This article helped A TON: https:&#x2F;&#x2F;medium.com&#x2F;@vojtastavik&#x2F;building-an-ios-app-without-xcodes-build-system-d3e5ca86d30d
It is a bit outdated, some CLI arguments are a bit different now, but, in general, it was incredibly instrumental to get all this done!&lt;&#x2F;p&gt;
&lt;h3 id=&quot;prerequisites&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#prerequisites&quot; aria-label=&quot;Anchor link for: prerequisites&quot;&gt;🔗&lt;&#x2F;a&gt;Prerequisites&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;free appstore account&lt;&#x2F;li&gt;
&lt;li&gt;macos 10.15+ (probably 10.14 works as well)&lt;&#x2F;li&gt;
&lt;li&gt;xcode 11+&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ios-control&#x2F;ios-deploy&quot;&gt;ios-deploy&lt;&#x2F;a&gt; tool. (&lt;code&gt;brew install ios-deploy&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;any ios device&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;connecting-phone-with-xcode&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#connecting-phone-with-xcode&quot; aria-label=&quot;Anchor link for: connecting-phone-with-xcode&quot;&gt;🔗&lt;&#x2F;a&gt;Connecting phone with xcode&lt;&#x2F;h3&gt;
&lt;p&gt;On the first connection, both xcode and macos might complain about versions incompatibility.
MacOs complains may be just ignored, but to make XCode recognise the device:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;double check that there is a folder with Iphone&#x27;s ios version here: &lt;code&gt;&#x2F;Applications&#x2F;Xcode.app&#x2F;Contents&#x2F;Developer&#x2F;Platforms&#x2F;iPhoneOS.platform&#x2F;DeviceSupport&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;if no - download the required file somewhere from the internet(there are a lot of repos on github with such a data).&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The goal of this step - to see a new device available in &lt;code&gt;Xcode -&amp;gt; Window -&amp;gt; Devices and Simulators&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;on-devicesupport-files&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#on-devicesupport-files&quot; aria-label=&quot;Anchor link for: on-devicesupport-files&quot;&gt;🔗&lt;&#x2F;a&gt;On DeviceSupport files&lt;&#x2F;h3&gt;
&lt;p&gt;Any(11+ at least) xcode could install provision files on any IOS device!&lt;&#x2F;p&gt;
&lt;p&gt;On pre 16 iOS, the only requirement is a little file in &amp;quot;&#x2F;Applications&#x2F;Xcode.app&#x2F;Contents&#x2F;Developer&#x2F;Platforms&#x2F;iPhoneOS.platform&#x2F;DeviceSupport&amp;quot;&lt;&#x2F;p&gt;
&lt;p&gt;Post iOS 16, iPhone should be in a &amp;quot;Developer mode&amp;quot; to be able to receive the provisions. However, the &amp;quot;Developer mode&amp;quot; toggle is hidden in the settings until device seen a mac with xcode 14 installed at least once. Yes, you need to physically connect your iPhone to any Mac with XCode 14 to get a toggle in the menu!&lt;&#x2F;p&gt;
&lt;p&gt;There are, however, scatchy third-party tools(&amp;quot;iCareFone 2&amp;quot; did it for me) to get this very toggle. With this toggle on, XCode11 with &amp;quot;16.2&amp;quot; in &amp;quot;DeviceSupport&amp;quot; folder can successefully install the provisions on the iphone.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;mobileprovision-file&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#mobileprovision-file&quot; aria-label=&quot;Anchor link for: mobileprovision-file&quot;&gt;🔗&lt;&#x2F;a&gt;.mobileprovision file&lt;&#x2F;h3&gt;
&lt;p&gt;Purpose of this step - create an empty xcode project runnable on the iphone. This project will be never used for building anything, just to make xcode to download provision files from apple developer portal.&lt;&#x2F;p&gt;
&lt;p&gt;First, login to the app store account. (it might be a free account, no need for the developer one). &lt;code&gt;xcode-&amp;gt;preferences-&amp;gt;account login create team&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Than create a new dummy project with the desired bundle indentifier (&lt;code&gt;com.mygame&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;Run it on the device.&lt;&#x2F;p&gt;
&lt;p&gt;If xcode complains with &amp;quot;-402620375&amp;quot; (and no other explanations) - add &lt;code&gt;--generate-entitlement-der&lt;&#x2F;code&gt; to &lt;code&gt;Project -&amp;gt; Build Settings -&amp;gt; Other Code Signing Flags&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This will create a runnable app on the phone and make two provision files in &lt;code&gt;~&#x2F;Library&#x2F;MobileDevice&#x2F;Provisioning\ Profiles&#x2F;&lt;&#x2F;code&gt;.
One for &amp;quot;com.mygame&amp;quot; and one for &amp;quot;com.mygameUITests&amp;quot;. To find which one is which &lt;code&gt;cat ~&#x2F;Library&#x2F;MobileDevice&#x2F;Provisioning\ Profiles&#x2F;lotsofhex.mobileprovision | grep -a UITests&lt;&#x2F;code&gt;. The one that doesnt have UITests in it is the one!&lt;&#x2F;p&gt;
&lt;p&gt;Copy it to MyApp.app&#x2F;embedded.mobileprovision&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt; it seems XCode (at least version 15.1) is a bit arbitrary about which &lt;code&gt;.mobileprovisions&lt;&#x2F;code&gt; file it places in the &lt;strong&gt;Provisioning Profiles&lt;&#x2F;strong&gt; folder. If your developer account has several profiles, you may have to clean the folder, forcing XCode to redownload the provisioning file, until you get one that matches your bundle identifier. &lt;strong&gt;Also note&lt;&#x2F;strong&gt; at least with XCode 15.1 the wildcard provisioning profile has proven to work well. (The wildcard file does not mention your bundle identifier at all, and just uses &lt;code&gt;&amp;quot;*&amp;quot;&lt;&#x2F;code&gt; for that entry).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt; for the paid apple developer account - with the developer account this step may be skipped alltogether, provision profiles could be downloaded from the iOS developer portal.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;scent-file-maybe&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#scent-file-maybe&quot; aria-label=&quot;Anchor link for: scent-file-maybe&quot;&gt;🔗&lt;&#x2F;a&gt;.scent file (maybe)&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt; on MacOS 14 (Sonoma), &lt;code&gt;codesign&lt;&#x2F;code&gt; does not support &lt;code&gt;.scent&lt;&#x2F;code&gt; files and you should provide the &lt;code&gt;application-identifier&lt;&#x2F;code&gt; some other way. You can check if this option is available by running &lt;code&gt;codesign --sent&lt;&#x2F;code&gt;. If the error says &amp;quot;unrecognized option `--sent&#x27;&amp;quot; then see below for how to provide an &lt;strong&gt;Entitlements&lt;&#x2F;strong&gt; file instead.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;.scent&lt;&#x2F;code&gt; file contains all the metadata for signing the bundle.&lt;&#x2F;p&gt;
&lt;p&gt;First, get a team id (the team is a thing created in xcode in the previous step).&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cat mygame_provisionsfetch.xcodeproj&#x2F;project.pbxproj &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;| &lt;&#x2F;span&gt;&lt;span&gt;grep DEVELOPMENT_TEAM
&lt;&#x2F;span&gt;&lt;span&gt;DEVELOPMENT_TEAM = YOURID&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;em&gt;mygame_provisionsfetch.xcodeproj&lt;&#x2F;em&gt; is our dummy provisions-fetching project.&lt;&#x2F;p&gt;
&lt;p&gt;Than create a &lt;code&gt;.scent&lt;&#x2F;code&gt; file next to the &lt;code&gt;MyGame.app&lt;&#x2F;code&gt; folder:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;cat &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; MyGame.scent &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;lt;&amp;lt; EOF
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;!DOCTYPE plist PUBLIC &amp;quot;-&#x2F;&#x2F;Apple&#x2F;&#x2F;DTD PLIST 1.0&#x2F;&#x2F;EN&amp;quot; &amp;quot;http:&#x2F;&#x2F;www.apple.com&#x2F;DTDs&#x2F;PropertyList-1.0.dtd&amp;quot;&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;plist version=&amp;quot;1.0&amp;quot;&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;dict&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;key&amp;gt;application-identifier&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;string&amp;gt;MYTEAMID.com.mygame&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;key&amp;gt;com.apple.developer.team-identifier&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;string&amp;gt;MYTEAMID&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;key&amp;gt;get-task-allow&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;true&#x2F;&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;key&amp;gt;keychain-access-groups&amp;lt;&#x2F;key&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;array&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;		&amp;lt;string&amp;gt;MYTEAMID.com.mygame&amp;lt;&#x2F;string&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;	&amp;lt;&#x2F;array&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;&#x2F;dict&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;lt;&#x2F;plist&amp;gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;EOF
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;├── MyGame.app
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── embedded.mobileprovision
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── mygame
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── Info.plist
&lt;&#x2F;span&gt;&lt;span&gt;│   ├── assets
&lt;&#x2F;span&gt;&lt;span&gt;│   │   ├── texture.png
&lt;&#x2F;span&gt;&lt;span&gt;│   │   ├── someronfile.ron
&lt;&#x2F;span&gt;&lt;span&gt;├── MyGame.scent
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;One way to find what to use for &lt;code&gt;MYTEAMID&lt;&#x2F;code&gt; is in the provisioning profile file. Look for &lt;code&gt;TeamIdentifier&lt;&#x2F;code&gt; in the output of this command:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;security cms -D -i MyGame.app&#x2F;embedded.mobileprovision
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;(For cleaner output than a plain &lt;code&gt;cat&lt;&#x2F;code&gt; will give you.)&lt;&#x2F;p&gt;
&lt;h3 id=&quot;entitlements-file-unless-scent-file-worked&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#entitlements-file-unless-scent-file-worked&quot; aria-label=&quot;Anchor link for: entitlements-file-unless-scent-file-worked&quot;&gt;🔗&lt;&#x2F;a&gt;Entitlements file (unless &lt;code&gt;.scent&lt;&#x2F;code&gt; file worked)&lt;&#x2F;h3&gt;
&lt;p&gt;For &lt;code&gt;codesign&lt;&#x2F;code&gt; to be successful, it needs to know about the &lt;code&gt;application-identifier&lt;&#x2F;code&gt;. If you are using macOS 14+ (Sonoma) you probably should use an Entitlements file instead of a &lt;code&gt;.scent&lt;&#x2F;code&gt; one.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;application-identifier&lt;&#x2F;code&gt; is a concatenation of your team identifier (&lt;code&gt;MYTEAMID&lt;&#x2F;code&gt; above) and your bundle identifier. Create an XML file somewhere (e.g. in the crate root named &lt;code&gt;MyGame.entitlements.xml&lt;&#x2F;code&gt;) with this content:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;xml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-xml &quot;&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;xml &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;version&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;1.0&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;encoding&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;UTF-8&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;?&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;!&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;DOCTYPE &lt;&#x2F;span&gt;&lt;span&gt;plist &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;PUBLIC &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;-&#x2F;&#x2F;Apple&#x2F;&#x2F;DTD PLIST 1.0&#x2F;&#x2F;EN&amp;quot; &amp;quot;http:&#x2F;&#x2F;www.apple.com&#x2F;DTDs&#x2F;PropertyList-1.0.dtd&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;plist &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;version&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;dict&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;key&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;application-identifier&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;key&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;string&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;MYTEAMID.com.mygame&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;string&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;dict&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;plist&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;sign-it&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#sign-it&quot; aria-label=&quot;Anchor link for: sign-it&quot;&gt;🔗&lt;&#x2F;a&gt;sign it&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;strong&gt;Before&lt;&#x2F;strong&gt; macOS 14 (Sonoma):&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# this should show the certificate previously created in xcode
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# copy the very long hex id from the certificate
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; security find-identity -v -p codesigning
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# and use it here to sign the binary
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; codesign --force --timestamp&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;none --sign LONGHEXID mygame
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# and sign the bundle itself
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; codesign --force --timestamp&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;none --sign LONGHEXID --scent MyGame.scent --generate-entitlement-der MyGame.app
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For Sonoma finding the identity (&lt;code&gt;LONGHEXID&lt;&#x2F;code&gt;) is the same as above. But you only need to sign the bundle, and you should use the entitlements file instead of the scent one:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;codesign --force --timestamp&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;none --sign LONGHEXID --entitlements MyGame.entitlements.xml MyGame.app
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;deploy-it&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#deploy-it&quot; aria-label=&quot;Anchor link for: deploy-it&quot;&gt;🔗&lt;&#x2F;a&gt;deploy it&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; ios-deploy -c
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; ios-deploy -i HEXDEVICEID -b MyGame.app
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;build-scripts&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#build-scripts&quot; aria-label=&quot;Anchor link for: build-scripts&quot;&gt;🔗&lt;&#x2F;a&gt;Build scripts&lt;&#x2F;h1&gt;
&lt;p&gt;When all the groundwork is done those scripts will deploy run the game on the simulator&#x2F;real device.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;emulator&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#emulator&quot; aria-label=&quot;Anchor link for: emulator&quot;&gt;🔗&lt;&#x2F;a&gt;Emulator&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;cargo build --target x86_64-apple-ios
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# if assets are updated all the time - copy them on each build
&lt;&#x2F;span&gt;&lt;span&gt;cp -r assets MyGame.app&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# note debug&#x2F;release
&lt;&#x2F;span&gt;&lt;span&gt;cp target&#x2F;x86_64-apple-ios&#x2F;debug&#x2F;mygame MyGame.app&#x2F;mygame
&lt;&#x2F;span&gt;&lt;span&gt;xcrun simctl install booted MyGame.app&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;xcrun simctl launch booted com.mygame
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;real-device&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#real-device&quot; aria-label=&quot;Anchor link for: real-device&quot;&gt;🔗&lt;&#x2F;a&gt;Real device&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;cargo build --target aarch64-apple-ios --release
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# if assets are updated all the time - copy them on each build
&lt;&#x2F;span&gt;&lt;span&gt;cp -r assets MyGame.app&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# note debug&#x2F;release
&lt;&#x2F;span&gt;&lt;span&gt;cp target&#x2F;aarch64-apple-ios&#x2F;release&#x2F;mygame MyGame.app&#x2F;mygame
&lt;&#x2F;span&gt;&lt;span&gt;codesign --force --timestamp&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;none --sign VERYLONGHEXID MyGame.app&#x2F;mygame
&lt;&#x2F;span&gt;&lt;span&gt;codesign --force --timestamp&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;none --sign VERYLONGHEXID --scent MyGame.scent --generate-entitlement-der MyGame.app
&lt;&#x2F;span&gt;&lt;span&gt;ios-deploy -i HEXDEVICEID -b MyGame.app
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt; on macOS 14 (Sonoma), replace both &lt;code&gt;codesign&lt;&#x2F;code&gt; invokations with:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;codesign --force --timestamp&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;none --sign VERYLONGHEXID --entitlements MyGame.entitlements.xml MyGame.app
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Java interop with Miniquad on Android</title>
        <published>2022-07-04T20:10:42+00:00</published>
        <updated>2022-07-04T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/java/" type="text/html"/>
        <id>https://macroquad.rs/articles/java/</id>
        
        <content type="html">&lt;p&gt;Miniquad allows seamless integration of Java code, integrating Java compilation into a rust build pipeline. This allows *quad project to get access to any Android APIs and an option to integrate any third-party Java libraries.&lt;&#x2F;p&gt;
&lt;p&gt;The article use a native file dialog as an example.&lt;&#x2F;p&gt;
&lt;p&gt;Code is available here: &lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-fileopen&#x2F;&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-fileopen&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;More comprehensive example: &lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-bluetooth&#x2F;&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-bluetooth&#x2F;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;figure class=&quot;inline-image&quot;&gt;
	&lt;video controls autoplay playsinline muted loop&gt;
		&lt;source src=&quot;https:&amp;#x2F;&amp;#x2F;user-images.githubusercontent.com&amp;#x2F;910977&amp;#x2F;177233789-fefbf9c9-6c55-4151-804a-22b85dfa82de.mp4&quot; type=&quot;video&#x2F;mp4&quot;&gt;
		Your browser does not support the video tag.
	&lt;&#x2F;video&gt;
	
&lt;&#x2F;figure&gt;

&lt;em&gt;Bluetooth example asking for permissions. Surprisingly, its A LOT of java!&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-android-runs-things&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-android-runs-things&quot; aria-label=&quot;Anchor link for: how-android-runs-things&quot;&gt;🔗&lt;&#x2F;a&gt;How android runs things&lt;&#x2F;h2&gt;
&lt;p&gt;First a brief introduction on how applications works on android. A bird&#x27;s eye view on how apps works on android, to find out where it is possible to insert some calls to get the final dialog (or any native api, actually) to appear. &lt;&#x2F;p&gt;
&lt;p&gt;Each android package, .apk, is basically a zip archive with:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;classes.dex file - all the compiled java files&lt;&#x2F;li&gt;
&lt;li&gt;.so files - all the compiled binary code&lt;&#x2F;li&gt;
&lt;li&gt;some .xml&#x27;s with metadata, resources and assets&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Android will initialize java virtual machine and run the app inside this virtual machine. All the interactions with the OS goes through the virtual machine. &lt;&#x2F;p&gt;
&lt;p&gt;There are two ways to start android application, described in one of the .xml&#x27;s of the apk:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;skip classes.dex completely and tell android to load .so and call a few symbols to let the app initialize.&lt;&#x2F;li&gt;
&lt;li&gt;find a java class in classes.dex file and let it run.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Miniquad is using the second option - it have MainActivity.java that is responsible for initializing the app and receiving input events. And inside this MainActivity.java .so with user code is being loaded and some native functions from that .so are being called.&lt;&#x2F;p&gt;
&lt;p&gt;Why miniquad is not built around NativeActivity, the first option? Well, it used to be built around NativeActivity until 0.3, actually.
The problem here - some of the android API&#x27;s are really, really hard to use through java native interface. So it really helps when there is an option to make a wrapper for something in Java and provide an easy to use function for a native code.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;A little remark on apks&lt;&#x2F;em&gt; Now instead of raw .apk developers will be forced to use .aab - a new format for applications on android. Each .aab is a bunch of signed .apk&#x27;s, so the idea is still the same.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;writing-some-java&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#writing-some-java&quot; aria-label=&quot;Anchor link for: writing-some-java&quot;&gt;🔗&lt;&#x2F;a&gt;Writing some java&lt;&#x2F;h3&gt;
&lt;p&gt;A short recap from previous section:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;miniquad has MainActivity.java&lt;&#x2F;li&gt;
&lt;li&gt;it creates an OS window and load .so with user code&lt;&#x2F;li&gt;
&lt;li&gt;it pass all the events to this .so through calling native functions from .so&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The way miniquad&#x27;s native plugins are built are very similar to UE4 android plugin&#x27;s idea(just in case the reader is familiar with UE4&#x2F;Android interop).&lt;&#x2F;p&gt;
&lt;p&gt;We can ask the build system to insert some code right to the MainActivity.java. And we can as the build system to add compile some .java files to get the classes into classes.dex.&lt;&#x2F;p&gt;
&lt;p&gt;Adding code inside MainActivity works in a quite literal way - there is a MainActivity.java template: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;blob&#x2F;master&#x2F;java&#x2F;MainActivity.java&quot;&gt;MainActivity.java&lt;&#x2F;a&gt;. Each crate based on miniquad can ask the build system to add some lines into &lt;code&gt;&#x2F;&#x2F;% MAIN_ACTIVITY_ON_RESUME&lt;&#x2F;code&gt; or &lt;code&gt;&#x2F;&#x2F;% whatever&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Fortunately Java is not against recurring lines in imports declaration,&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;java&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-java &quot;&gt;&lt;code class=&quot;language-java&quot; data-lang=&quot;java&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;android&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;app&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Activity&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;android&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;app&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Activity&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;android&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;app&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Activity&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;is totally legit for Java. So each plugin can be independent on each other and add its logic right into the MainActivity, with its own imports and its own initialisation code in Activity OnCreate and so on.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;The plan of building a file dialog crate&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Make a few .java files with classes helpful for dealing with files&lt;&#x2F;li&gt;
&lt;li&gt;Ask to insert code into MainActivity.java to make some initialization on java side&lt;&#x2F;li&gt;
&lt;li&gt;Call some functions through JNI from our plugin rust code to get the data back&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;how-to-open-a-file-dialog&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-to-open-a-file-dialog&quot; aria-label=&quot;Anchor link for: how-to-open-a-file-dialog&quot;&gt;🔗&lt;&#x2F;a&gt;How to open a file dialog&lt;&#x2F;h2&gt;
&lt;p&gt;This part might be generalized into &amp;quot;How to use Intents on Android&amp;quot;. &lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;developer.android.com&#x2F;reference&#x2F;android&#x2F;content&#x2F;Intent&quot;&gt;An intent is an abstract description of an operation to be performed. ... An Intent provides a facility for performing late runtime binding between the code in different applications.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;MainActivity has a method, &lt;code&gt;startActivityForResult&lt;&#x2F;code&gt;. This will replace the application&#x27;s activity with a new activity for the intent and later will send the result back into MainActivity.&lt;&#x2F;p&gt;
&lt;p&gt;To simplify getting data from a callback (hmm), the docs &lt;a href=&quot;https:&#x2F;&#x2F;developer.android.com&#x2F;training&#x2F;basics&#x2F;intents&#x2F;result&quot;&gt;suggests&lt;&#x2F;a&gt; to include 88Mb library with 499 Java files. While this is totally possible (check the bluetooth example, it goes this way), let&#x27;s try to avoid this for a little dialog.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;startActivityForResult&lt;&#x2F;code&gt; will send the result into a MainActivity&#x27;s as a MainActivity&#x27;s virtual function. Here ability to patch MainActivity comes in handy: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-fileopen&#x2F;blob&#x2F;main&#x2F;java&#x2F;MainActivity.java&quot;&gt;add code into MainActivity&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;wrapping-this-into-a-crate&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrapping-this-into-a-crate&quot; aria-label=&quot;Anchor link for: wrapping-this-into-a-crate&quot;&gt;🔗&lt;&#x2F;a&gt;Wrapping this into a crate&lt;&#x2F;h2&gt;
&lt;p&gt;The goal here - make a crate that provides a &lt;code&gt;find_file&lt;&#x2F;code&gt; function. This function opens a dialog and returns a bytes of a file content.&lt;&#x2F;p&gt;
&lt;p&gt;To tell cargo where are the java files: 
&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-fileopen&#x2F;blob&#x2F;main&#x2F;quad.toml&quot;&gt;quad.toml&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;main_activity_inject &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;java&#x2F;MainActivity.java&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;java_files &lt;&#x2F;span&gt;&lt;span&gt;= [
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;java&#x2F;fileopen&#x2F;FileOpen.java&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Java class responsible for the dialog: &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;example-android-fileopen&#x2F;blob&#x2F;main&#x2F;java&#x2F;fileopen&#x2F;FileOpen.java#L16&quot;&gt;FileOpen.java&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Most java calls look like &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;let env = android::attach_jni_env();
&lt;&#x2F;span&gt;&lt;span&gt;ndk_utils::call_void_method!(env, &amp;quot;OpenFileDialog&amp;quot;, &amp;quot;()V&amp;quot;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Useful links on Rust&amp;lt;-&amp;gt;Java interop:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad&#x2F;blob&#x2F;master&#x2F;src&#x2F;native&#x2F;android&#x2F;ndk_utils.rs&quot;&gt;miniquad&#x27;s ndk_utils&lt;&#x2F;a&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;docs.oracle.com&#x2F;javase&#x2F;7&#x2F;docs&#x2F;technotes&#x2F;guides&#x2F;jni&#x2F;spec&#x2F;functions.html&quot;&gt;JNI functions(available in the &amp;quot;env&amp;quot;)&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;using-the-crate&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#using-the-crate&quot; aria-label=&quot;Anchor link for: using-the-crate&quot;&gt;🔗&lt;&#x2F;a&gt;Using the crate&lt;&#x2F;h2&gt;
&lt;p&gt;This part is simple. 
Just include the crate in Cargo.toml: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span&gt;[dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;fileopen &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;..&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and use it from any miniquad&#x2F;macroquad project:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;if root_ui().button(None, &amp;quot;Open file&amp;quot;){
&lt;&#x2F;span&gt;&lt;span&gt;    fileopen::find_file(file_data.clone());
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;post-scriptum&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#post-scriptum&quot; aria-label=&quot;Anchor link for: post-scriptum&quot;&gt;🔗&lt;&#x2F;a&gt;Post-scriptum&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;em&gt;Wait is a second, patching java code, calling javac, isn&#x27;t it all horrible hacks?&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Yes it is indeed. Would be so happy to throw it all away! But so far its the easiest way to deal with java I ever seen (from a library user perspective, writing java is horrible). No need to download gigabytes of android studio, no build pipeline complications.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Publish game on Android with Macroquad</title>
        <published>2021-06-15T09:19:42+00:00</published>
        <updated>2021-06-15T10:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/android/" type="text/html"/>
        <id>https://macroquad.rs/articles/android/</id>
        
        <content type="html">&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;play.google.com&#x2F;store&#x2F;apps&#x2F;details?id=rust.zemeroth&quot;&gt;&lt;img src=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;android&#x2F;zemeroth.png&quot; alt=&quot;zemeroth&quot; &#x2F;&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;1-introduction&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#1-introduction&quot; aria-label=&quot;Anchor link for: 1-introduction&quot;&gt;🔗&lt;&#x2F;a&gt;1. Introduction&lt;&#x2F;h1&gt;
&lt;p&gt;This tutorial is based on the experience of publishing &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ozkriff&#x2F;zemeroth&quot;&gt;Zemeroth&lt;&#x2F;a&gt; game on the Google Play Store. The game is now available as open test, &lt;a href=&quot;https:&#x2F;&#x2F;play.google.com&#x2F;store&#x2F;apps&#x2F;details?id=rust.zemeroth&quot;&gt;check it out!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Topics covered:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Building a macroquad game for android &lt;&#x2F;li&gt;
&lt;li&gt;Common pitfalls and debugging tips&lt;&#x2F;li&gt;
&lt;li&gt;Setting up and uploading an APK to a Google Play&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;2-setting-up-your-environment&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#2-setting-up-your-environment&quot; aria-label=&quot;Anchor link for: 2-setting-up-your-environment&quot;&gt;🔗&lt;&#x2F;a&gt;2. Setting up your Environment&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;a-docker-way&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-docker-way&quot; aria-label=&quot;Anchor link for: a-docker-way&quot;&gt;🔗&lt;&#x2F;a&gt;A docker way&lt;&#x2F;h2&gt;
&lt;p&gt;On the machine with docker pulling all the NDK dependencies is as simple as&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;docker pull notfl3&#x2F;cargo-apk
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Docker is a recommended way to build macroquad&#x27;s game for Android. &lt;&#x2F;p&gt;
&lt;h3 id=&quot;building-an-apk-a-docker-way&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#building-an-apk-a-docker-way&quot; aria-label=&quot;Anchor link for: building-an-apk-a-docker-way&quot;&gt;🔗&lt;&#x2F;a&gt;Building an APK, a docker way&lt;&#x2F;h3&gt;
&lt;p&gt;APK may be made with just one command:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;docker run 
&lt;&#x2F;span&gt;&lt;span&gt;  --rm 
&lt;&#x2F;span&gt;&lt;span&gt;  -v $(pwd):&#x2F;root&#x2F;src 
&lt;&#x2F;span&gt;&lt;span&gt;  -w &#x2F;root&#x2F;src 
&lt;&#x2F;span&gt;&lt;span&gt;  notfl3&#x2F;cargo-apk cargo quad-apk build --release
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Will produce an apk in &lt;code&gt;target&#x2F;android-artifacts&#x2F;release&#x2F;apk&lt;&#x2F;code&gt;. &lt;&#x2F;p&gt;
&lt;p&gt;This command takes a while - each docker invocation do a clean build for all 3 android targets. There are different strategies to make docker cache build temp files between builds, described in &lt;a href=&quot;&#x2F;articles&#x2F;docker&quot;&gt;a little docker cheatsheat&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-manual-way&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-manual-way&quot; aria-label=&quot;Anchor link for: a-manual-way&quot;&gt;🔗&lt;&#x2F;a&gt;A manual way&lt;&#x2F;h2&gt;
&lt;p&gt;Docker simplify the process of installing android-sdk and android-ndk. But, sometimes, it may be more convinient to use all native build pipeline. 
While this is not really recommended, this path is included to a tutorial for better illustrating what exactly is going on in the container.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;installing-pre-requisites&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#installing-pre-requisites&quot; aria-label=&quot;Anchor link for: installing-pre-requisites&quot;&gt;🔗&lt;&#x2F;a&gt;Installing pre-requisites:&lt;&#x2F;h3&gt;
&lt;p&gt;Exact commands and pathes may depend on the host OS. Here linux commands are used, but on all the other OSes the idea should be very similar.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;JRE or JDK&lt;&#x2F;p&gt;
&lt;p&gt;This step highly depends on the OS, for ubuntu: &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;sudo apt-get install openjdk-8-jdk
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Rust android&lt;&#x2F;p&gt;
&lt;p&gt;Assuming rustup&#x27;s rust installation:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;rustup target add armv7-linux-androideabi
&lt;&#x2F;span&gt;&lt;span&gt;rustup target add aarch64-linux-android
&lt;&#x2F;span&gt;&lt;span&gt;rustup target add i686-linux-android
&lt;&#x2F;span&gt;&lt;span&gt;rustup target add x86_64-linux-android
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Android SDK&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;# create a folder for all the android pre-requisites stuff
&lt;&#x2F;span&gt;&lt;span&gt;mkdir &#x2F;this&#x2F;may&#x2F;be&#x2F;any&#x2F;path&#x2F;android
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;cd android
&lt;&#x2F;span&gt;&lt;span&gt;wget -q https:&#x2F;&#x2F;dl.google.com&#x2F;android&#x2F;repository&#x2F;sdk-tools-linux-4333796.zip
&lt;&#x2F;span&gt;&lt;span&gt;unzip -q sdk-tools-linux-4333796.zip
&lt;&#x2F;span&gt;&lt;span&gt;rm sdk-tools-linux-4333796.zip
&lt;&#x2F;span&gt;&lt;span&gt;tools&#x2F;bind&#x2F;sdkmanager &amp;quot;platform-tools&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;tools&#x2F;bin&#x2F;sdkmanager &amp;quot;platforms;android-29&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;tools&#x2F;bin&#x2F;sdkmanager &amp;quot;build-tools;29.0.0&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;tools&#x2F;bin&#x2F;sdkmanager --update
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Android NDK&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;# go to the same dir created for android-sdk
&lt;&#x2F;span&gt;&lt;span&gt;cd &#x2F;path&#x2F;from&#x2F;previous&#x2F;step&#x2F;android
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;wget -q https:&#x2F;&#x2F;dl.google.com&#x2F;android&#x2F;repository&#x2F;android-ndk-r25b-linux.zip
&lt;&#x2F;span&gt;&lt;span&gt;unzip -q android-ndk-r25b-linux.zip
&lt;&#x2F;span&gt;&lt;span&gt;rm android-ndk-r25-linux-x86_64.zip
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Cargo APK&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;cargo-quad-apk&lt;&#x2F;code&gt; is a cargo extension, allowing&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;cargo install cargo-quad-apk
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;building-an-apk-a-manual-way&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#building-an-apk-a-manual-way&quot; aria-label=&quot;Anchor link for: building-an-apk-a-manual-way&quot;&gt;🔗&lt;&#x2F;a&gt;Building an APK, a manual way&lt;&#x2F;h3&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;export ANDROID_HOME=&#x2F;path&#x2F;from&#x2F;previous&#x2F;step&#x2F;android
&lt;&#x2F;span&gt;&lt;span&gt;export NDK_HOME=&#x2F;path&#x2F;from&#x2F;previous&#x2F;step&#x2F;android&#x2F;android-ndk-r25
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;# for a debug build
&lt;&#x2F;span&gt;&lt;span&gt;cargo quad-apk build
&lt;&#x2F;span&gt;&lt;span&gt;# for a release build
&lt;&#x2F;span&gt;&lt;span&gt;cargo quad-apk build --release
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;An apk will be in &lt;code&gt;target&#x2F;android-artifacts&#x2F;debug&#x2F;apk&lt;&#x2F;code&gt; or &lt;code&gt;target&#x2F;android-artifacts&#x2F;release&#x2F;apk&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;3-fine-tuning-the-game-for-android&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#3-fine-tuning-the-game-for-android&quot; aria-label=&quot;Anchor link for: 3-fine-tuning-the-game-for-android&quot;&gt;🔗&lt;&#x2F;a&gt;3. Fine tuning the game for android&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;targeting-api-level-31&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#targeting-api-level-31&quot; aria-label=&quot;Anchor link for: targeting-api-level-31&quot;&gt;🔗&lt;&#x2F;a&gt;Targeting API Level &amp;gt;= 31&lt;&#x2F;h2&gt;
&lt;p&gt;You have to add this to your Cargo.toml&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;[package.metadata.android.activity_attributes]
&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;android:exported&amp;quot; =  &amp;quot;true&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;assets-folder&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#assets-folder&quot; aria-label=&quot;Anchor link for: assets-folder&quot;&gt;🔗&lt;&#x2F;a&gt;Assets folder&lt;&#x2F;h2&gt;
&lt;p&gt;Assuming following project structure: &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;.
&lt;&#x2F;span&gt;&lt;span&gt;├── assets
&lt;&#x2F;span&gt;&lt;span&gt;├── └── nice_texture.png
&lt;&#x2F;span&gt;&lt;span&gt;├── src
&lt;&#x2F;span&gt;&lt;span&gt;├── └── main.rs
&lt;&#x2F;span&gt;&lt;span&gt;└── Cargo.toml
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To include assets folder to an APK, add this to your Cargo.toml:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ini&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-ini &quot;&gt;&lt;code class=&quot;language-ini&quot; data-lang=&quot;ini&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;[package.metadata.android]
&lt;&#x2F;span&gt;&lt;span&gt;assets &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;assets&#x2F;&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Later on texture may be loaded with &lt;code&gt;load_texture(&amp;quot;nice_texture.png&amp;quot;)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;However, on PC, usually, the load_texture call will look like &lt;code&gt;load_texture(&amp;quot;assets&#x2F;nice_texture.png&amp;quot;)&lt;&#x2F;code&gt; - the assets folder itself is a part of the path.&lt;&#x2F;p&gt;
&lt;p&gt;To fix it and use uniforms path between android and PC &lt;a href=&quot;https:&#x2F;&#x2F;docs.rs&#x2F;macroquad&#x2F;0.3.6&#x2F;macroquad&#x2F;file&#x2F;fn.set_pc_assets_folder.html&quot;&gt;set_pc_assets_folder&lt;&#x2F;a&gt; may help.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;macroquad::file::set_pc_assets_folder(&amp;quot;assets&amp;quot;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now its &lt;code&gt;load_texture(&amp;quot;nice_texture.png&amp;quot;)&lt;&#x2F;code&gt; on both platforms.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;high-dpi&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#high-dpi&quot; aria-label=&quot;Anchor link for: high-dpi&quot;&gt;🔗&lt;&#x2F;a&gt;High-dpi&lt;&#x2F;h2&gt;
&lt;img src=&quot;densities-phone_2x.png&quot;  width=&quot;300px&quot;&#x2F;&gt;
&lt;p&gt;&lt;em&gt;&lt;a href=&quot;https:&#x2F;&#x2F;developer.android.com&#x2F;training&#x2F;multiscreen&#x2F;screendensities&quot;&gt;Image source&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Android devices have significant pixel dencity difference. 
By default, android tries to emulate a low-density display on a high-density pixel display.&lt;&#x2F;p&gt;
&lt;p&gt;This means that &lt;code&gt;screen_width()&#x2F;screen_height()&lt;&#x2F;code&gt; may give a value way lower than the actual screen pixel resolution, but later on android will automatically upscale the viewport.&lt;&#x2F;p&gt;
&lt;p&gt;This may be OK - smaller viewport means better FPS, but if android&#x27;s upscale is not required - the game should tell android to support &amp;quot;high-dpi&amp;quot; screens.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;window_conf&lt;&#x2F;span&gt;&lt;span&gt;() -&amp;gt; window::Conf {
&lt;&#x2F;span&gt;&lt;span&gt;    window::Conf {
&lt;&#x2F;span&gt;&lt;span&gt;        window_title: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Zemeroth&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;to_owned&lt;&#x2F;span&gt;&lt;span&gt;(),
&lt;&#x2F;span&gt;&lt;span&gt;        high_dpi: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;::default()
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[macroquad::main(window_conf)]
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;screen-orientation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#screen-orientation&quot; aria-label=&quot;Anchor link for: screen-orientation&quot;&gt;🔗&lt;&#x2F;a&gt;Screen orientation&lt;&#x2F;h2&gt;
&lt;p&gt;By default Macroquad games are fullscreen and allows any screen locations.
To limit possible screen orientations add this to your Cargo.toml: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ini&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-ini &quot;&gt;&lt;code class=&quot;language-ini&quot; data-lang=&quot;ini&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;[package.metadata.android.activity_attributes]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;android:screenOrientation&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;userLandscape&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;icon&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#icon&quot; aria-label=&quot;Anchor link for: icon&quot;&gt;🔗&lt;&#x2F;a&gt;Icon&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;android&#x2F;icon.jpg&quot; alt=&quot;icon&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Application icon lives in an &amp;quot;resources&amp;quot; - special section in APK.
To include &amp;quot;res&amp;quot; folder to an APK:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ini&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-ini &quot;&gt;&lt;code class=&quot;language-ini&quot; data-lang=&quot;ini&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;[package.metadata.android]
&lt;&#x2F;span&gt;&lt;span&gt;res &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;android_res&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;icon &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;@mipmap&#x2F;ic_launcher&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And the icon itself for different DPI may look something like this:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;android_res&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;├── mipmap-hdpi
&lt;&#x2F;span&gt;&lt;span&gt;│   └── ic_launcher.png
&lt;&#x2F;span&gt;&lt;span&gt;├── mipmap-mdpi
&lt;&#x2F;span&gt;&lt;span&gt;│   └── ic_launcher.png
&lt;&#x2F;span&gt;&lt;span&gt;├── mipmap-xhdpi
&lt;&#x2F;span&gt;&lt;span&gt;│   └── ic_launcher.png
&lt;&#x2F;span&gt;&lt;span&gt;├── mipmap-xxhdpi
&lt;&#x2F;span&gt;&lt;span&gt;│   └── ic_launcher.png
&lt;&#x2F;span&gt;&lt;span&gt;└── mipmap-xxxhdpi
&lt;&#x2F;span&gt;&lt;span&gt;    └── ic_launcher.png
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Icons for each size certainly may be generated manually. For this tutorial 
&lt;a href=&quot;http:&#x2F;&#x2F;romannurik.github.io&#x2F;AndroidAssetStudio&#x2F;icons-launcher.html&quot;&gt;http:&#x2F;&#x2F;romannurik.github.io&#x2F;AndroidAssetStudio&#x2F;icons-launcher.html&lt;&#x2F;a&gt; was used, worked pretty good.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;debug-logs&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#debug-logs&quot; aria-label=&quot;Anchor link for: debug-logs&quot;&gt;🔗&lt;&#x2F;a&gt;Debug logs&lt;&#x2F;h2&gt;
&lt;p&gt;All the &lt;code&gt;warn!&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;info!&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;debug!&lt;&#x2F;code&gt; macroquad&#x27;s messages goes into android system messages. To access android&#x27;s system messages there is &lt;code&gt;adb logcat&lt;&#x2F;code&gt; command. There are various way to filter &lt;code&gt;adb logcat&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;filter-adb-logcat-by-tag&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#filter-adb-logcat-by-tag&quot; aria-label=&quot;Anchor link for: filter-adb-logcat-by-tag&quot;&gt;🔗&lt;&#x2F;a&gt;Filter &lt;code&gt;adb logcat&lt;&#x2F;code&gt; by tag&lt;&#x2F;h3&gt;
&lt;p&gt;Filter by tag will show only messages posted by macroquad&#x27;s &lt;code&gt;warn!&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;info!&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;debug!&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;adb logcat -v brief SAPP:V &amp;quot;*:S&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;-v brief&lt;&#x2F;code&gt; will save a little bit of screen space, hiding some log metadata.&lt;&#x2F;p&gt;
&lt;p&gt;Arguments after &lt;code&gt;adb logcat&lt;&#x2F;code&gt; are filter specification.&lt;&#x2F;p&gt;
&lt;p&gt;SAPP:V - For messages with tag SAPP V(verbose) filter will be applied. All the SAPP messages will be in the output.
*:S - For all the other tags S(silent) filter will be applied. All the other messages will be filtered out.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;filter-by-pid&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#filter-by-pid&quot; aria-label=&quot;Anchor link for: filter-by-pid&quot;&gt;🔗&lt;&#x2F;a&gt;Filter by PID&lt;&#x2F;h3&gt;
&lt;p&gt;Sometimes application produced some extra system messages. It may be some system warnings or some unhandled native libraries problems. But those messages may be filtered out when &lt;code&gt;adb logcat&lt;&#x2F;code&gt; is filtered by tag.&lt;&#x2F;p&gt;
&lt;p&gt;PID is a process id, and filtering by PID will give all the application output, with any tag.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;# Find out PID
&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt; adb shell pidof -s rust.CRATENAME
&lt;&#x2F;span&gt;&lt;span&gt;30243
&lt;&#x2F;span&gt;&lt;span&gt;# Get all the messages from a given PID
&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;adb shell pidof -s 30243
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Depending on the command processor those to commands may be usually reduced to something like&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;adb logcat --pid=$(adb shell pidof -s rust.CRATENAME)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;4-signing-the-apk&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#4-signing-the-apk&quot; aria-label=&quot;Anchor link for: 4-signing-the-apk&quot;&gt;🔗&lt;&#x2F;a&gt;4. Signing the APK&lt;&#x2F;h1&gt;
&lt;p&gt;By default, &lt;code&gt;cargo quad-apk&lt;&#x2F;code&gt; generates debug kestore file and is signing up an APK with a debug key. This allows the APK to be installed locally, but is not enough for the Google Play.&lt;&#x2F;p&gt;
&lt;p&gt;For the Play Store non-debug keystore file is required, and this file should be uploaded to the Play Console to verify developer identity. &lt;&#x2F;p&gt;
&lt;p&gt;To generate the key &lt;code&gt;keytool&lt;&#x2F;code&gt; is required. &lt;code&gt;keytool&lt;&#x2F;code&gt; is a part of a &lt;code&gt;java&lt;&#x2F;code&gt; ditribution and is being shipped with &lt;code&gt;openjdk&lt;&#x2F;code&gt;.
To sign the the APK &lt;code&gt;apksigner&lt;&#x2F;code&gt; is requires. &lt;code&gt;apksigner&lt;&#x2F;code&gt; is a part of Android SDK. &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;keytool -v -genkey -keystore mygame.keystore -alias mygame -keyalg RSA -validity 10000
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now all the pre-requisites are fullfilled and the key is ready to be used for a release build.&lt;&#x2F;p&gt;
&lt;p&gt;First, tell &lt;code&gt;cargo-apk&lt;&#x2F;code&gt; to stop signing the build with debug keystore:
&lt;code&gt;cargo quad-apk build --release --nosign&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Than sign the APK with a non-debug keystore file:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;apksigner sign --ks mygame.keystore my-app.apk --ks-key-alias alias_name
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It may be verified with&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;apksigner verify my-app.apk
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;developer.android.com&#x2F;studio&#x2F;publish&#x2F;app-signing.html&quot;&gt;The official documentation on signing can be found here.&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;note-how-to-get-keytool-apksigner-with-docker&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#note-how-to-get-keytool-apksigner-with-docker&quot; aria-label=&quot;Anchor link for: note-how-to-get-keytool-apksigner-with-docker&quot;&gt;🔗&lt;&#x2F;a&gt;NOTE: how to get &lt;code&gt;keytool&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;apksigner&lt;&#x2F;code&gt; with docker&lt;&#x2F;h2&gt;
&lt;p&gt;Assuming android keystore lives in ~&#x2F;.android and .apk to sign lives in current working directory: &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;docker run --rm 
&lt;&#x2F;span&gt;&lt;span&gt;    -v (pwd):&#x2F;root&#x2F;src  
&lt;&#x2F;span&gt;&lt;span&gt;    -v(&#x2F;home&#x2F;USER&#x2F;.android):&#x2F;root&#x2F;.android_secrets 
&lt;&#x2F;span&gt;&lt;span&gt;    -w &#x2F;root&#x2F;src -it notfl3&#x2F;cargo-apk &#x2F;bin&#x2F;bash
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This command will gives a bash session with current directory mounted to &lt;code&gt;&#x2F;root&#x2F;src&lt;&#x2F;code&gt; and .android mounted to &lt;code&gt;&#x2F;root&#x2F;.android_secrets&lt;&#x2F;code&gt;
And inside the container APK may be signed with&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;apksigner sign --ks my.keystore my-app.apk --ks-key-alias alias_name
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;android-targets&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#android-targets&quot; aria-label=&quot;Anchor link for: android-targets&quot;&gt;🔗&lt;&#x2F;a&gt;Android targets&lt;&#x2F;h2&gt;
&lt;p&gt;By default &lt;code&gt;cargo quad-apk&lt;&#x2F;code&gt; is building an APK for 3 different platforms. 
To comply Google Play requirements and get all the platforms:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ini&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-ini &quot;&gt;&lt;code class=&quot;language-ini&quot; data-lang=&quot;ini&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;[package.metadata.android]
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;build_targets &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; [ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;armv7-linux-androideabi&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;aarch64-linux-android&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;i686-linux-android&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;x86_64-linux-android&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; ]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To reduce build time while debugging - pick one for a testing device in use:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ini&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-ini &quot;&gt;&lt;code class=&quot;language-ini&quot; data-lang=&quot;ini&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;[package.metadata.android]
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;build_targets &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; [ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;armv7-linux-androideabi&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; ]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;google-play-versioning&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#google-play-versioning&quot; aria-label=&quot;Anchor link for: google-play-versioning&quot;&gt;🔗&lt;&#x2F;a&gt;Google Play versioning&lt;&#x2F;h2&gt;
&lt;p&gt;Google play have its own versioning mechanism for uploaded APKs.
Each APK for google play should have unique &lt;code&gt;version_code&lt;&#x2F;code&gt;.
Otherwise google developer console will end up with &lt;code&gt;Version code 1 has already been used. Try another version code.&amp;quot;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To set &lt;code&gt;version_code&lt;&#x2F;code&gt; from an app Cargo.toml:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;ini&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-ini &quot;&gt;&lt;code class=&quot;language-ini&quot; data-lang=&quot;ini&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;[package.metadata.android]
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;version_code &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2
&lt;&#x2F;span&gt;&lt;span&gt;version_name &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Version Name&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;developer.android.com&#x2F;studio&#x2F;publish&#x2F;versioning&quot;&gt;The official documentation on versioning can be found here.&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;preview-assets-for-a-store-page&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#preview-assets-for-a-store-page&quot; aria-label=&quot;Anchor link for: preview-assets-for-a-store-page&quot;&gt;🔗&lt;&#x2F;a&gt;Preview assets for a store page&lt;&#x2F;h2&gt;
&lt;p&gt;To submit your game for a google review and do an open test&#x2F;release - the Play Store page should be filled setted up - screenshots&#x2F;descriptions should be uploaded. Lots of data will be marked as (*)required, however, the real minimal subset of game graphics to upload is:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;512x512 icon&lt;&#x2F;li&gt;
&lt;li&gt;1024x500 banner&lt;&#x2F;li&gt;
&lt;li&gt;two 16:9 screenshots&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;developer.android.com&#x2F;studio&#x2F;publish&#x2F;versioning&quot;&gt;Useful article on preview assets.&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;internal-test-open-test-and-release&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#internal-test-open-test-and-release&quot; aria-label=&quot;Anchor link for: internal-test-open-test-and-release&quot;&gt;🔗&lt;&#x2F;a&gt;Internal test, open test and release&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;em&gt;Difference between an internal, closed, and open test?&lt;&#x2F;em&gt;
&lt;em&gt;You can create releases on three testing tracks before you release your app to production.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Internal testing: Create an internal testing release to quickly distribute your app to up to 100 testers for initial quality assurance checks.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Do not require setted up store page and do not require a review. Helps with ensuring that signing process actually worked, build is really uploaded. Also allows to add testers by email.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Closed testing: Create a closed testing release to test pre-release versions of your app with a wider set of testers to gather more targeted feedback.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Almost an open test, but requires adding tester&#x27;s email.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Open testing: Create an open testing release to run a test with a large group and surface your app&#x27;s test version on Google Play. If you run an open test, anyone can join your testing program and submit private feedback to you.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Almost a release, page is publicly available, no additional actions from testers required to install the game.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;support.google.com&#x2F;googleplay&#x2F;android-developer&#x2F;answer&#x2F;9845334?hl=en&quot;&gt;More info on testing tracks can be found here.&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h1 id=&quot;apk-to-aab&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#apk-to-aab&quot; aria-label=&quot;Anchor link for: apk-to-aab&quot;&gt;🔗&lt;&#x2F;a&gt;APK to AAB&lt;&#x2F;h1&gt;
&lt;p&gt;Those days GooglePlay do not accept the goold old .apk. Now we are forced to upload .aab and all the official docs refer gradle&#x2F;android studio to build an .aab.&lt;&#x2F;p&gt;
&lt;p&gt;Turned out that .aab is exactly the same archive as the apk, but .xml&#x27;s are converted to protobufs and a few files got renamed! I guess it is possible to make a little rust app converting the xml&#x27;s, but right now I am using the aapt2&#x2F;bundle-tool from google.&lt;&#x2F;p&gt;
&lt;p&gt;This little script do the job: https:&#x2F;&#x2F;gist.github.com&#x2F;not-fl3&#x2F;ffff62804ca2c8acc6d8ef74aa610eb6
(yes it is just &amp;quot;aapt2 convert &amp;amp;&amp;amp; bundletool build-bundle&amp;quot;, why it is never mentioned in the official android docs?)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Making an online multiplayer game in Rust with Nakama</title>
        <published>2021-05-01T09:19:42+00:00</published>
        <updated>2021-05-01T09:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/fish-tutorial/" type="text/html"/>
        <id>https://macroquad.rs/articles/fish-tutorial/</id>
        
        <content type="html">&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;title.gif&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;Fish Game is a 2-4 player online game built in the &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;&quot;&gt;Macroquad&lt;&#x2F;a&gt; game engine and the &lt;a href=&quot;https:&#x2F;&#x2F;www.rust-lang.org&#x2F;&quot;&gt;Rust&lt;&#x2F;a&gt; programming language. The game was created as a demonstration of &lt;a href=&quot;https:&#x2F;&#x2F;heroiclabs.com&#x2F;&quot;&gt;Nakama&lt;&#x2F;a&gt;, an open-source scalable game server.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, Fish Game is a frenetic platformer arena starring murderous fish - the last fish standing wins! The game design is heavily inspired by the excellent &lt;a href=&quot;https:&#x2F;&#x2F;store.steampowered.com&#x2F;app&#x2F;312530&#x2F;Duck_Game&#x2F;&quot;&gt;Duck Game&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The game is playable &lt;a href=&quot;https:&#x2F;&#x2F;fedorgames.itch.io&#x2F;fish-game?secret=UAVcggHn332a&quot;&gt;online on itch.io&lt;&#x2F;a&gt; and the Windows&#x2F;Linux&#x2F;Mac native version may be built from &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&quot;&gt;the source&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In this tutorial, we’re going to walk through each part of the code that interacts with Nakama to cover all the principles and APIs that you need to know to create your own online multiplayer game with Macroquad and Nakama.&lt;&#x2F;p&gt;
&lt;p&gt;We’ll touch on the following Nakama features:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;User authentication&lt;&#x2F;li&gt;
&lt;li&gt;Matchmaking&lt;&#x2F;li&gt;
&lt;li&gt;Realtime Multiplayer&lt;&#x2F;li&gt;
&lt;li&gt;Leaderboards&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This tutorial will briefly cover how to create a game with Macroquad. Afterward, it will focus on Nakama integration.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;making-a-platformer-game&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#making-a-platformer-game&quot; aria-label=&quot;Anchor link for: making-a-platformer-game&quot;&gt;🔗&lt;&#x2F;a&gt;Making a platformer game&lt;&#x2F;h1&gt;
&lt;p&gt;This part of the tutorial will explain how to create a single-player platformer game in Rust, starting with setting up macroquad. By the end of this section, we will have created a simple but fully functional platformer.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;setting-up-macroquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-up-macroquad&quot; aria-label=&quot;Anchor link for: setting-up-macroquad&quot;&gt;🔗&lt;&#x2F;a&gt;Setting up macroquad&lt;&#x2F;h2&gt;
&lt;p&gt;Start an empty Rust project:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cargo init --bin fishgame
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Run it: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cd fishgame
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; cargo run 
&lt;&#x2F;span&gt;&lt;span&gt;     Running `target&#x2F;debug&#x2F;fishgame`
&lt;&#x2F;span&gt;&lt;span&gt;Hello, world!
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Open &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; and add macroquad as a dependency:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span&gt;[package]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;name &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;fishgame&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;background-color:#f5f5f5;font-weight:bold;color:#b52a1d;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;[dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;macroquad &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.3&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Open &lt;code&gt;src&#x2F;main.rs&lt;&#x2F;code&gt; and add some macroquad drawing code to check that everything works (took this from &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;tree&#x2F;master&#x2F;examples&quot;&gt;macroquad examples&lt;&#x2F;a&gt;):&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;src&#x2F;main.rs&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;macroquad::prelude::&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[macroquad::main(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;BasicShapes&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_background&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;RED&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_line&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;40.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;40.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;200.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;15.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;BLUE&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_rectangle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_width&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2.0 &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;60.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;120.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;60.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;GREEN&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_circle&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_width&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_height&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;15.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;YELLOW&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_text&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;IT WORKS!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;20.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;20.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;30.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;DARKGRAY&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;&amp;gt; cargo run
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;itworks.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;If we got a window with some shapes: All good, the project is set up correctly. Now it&#x27;s time to draw more shapes to make it look like a game.&lt;&#x2F;p&gt;
&lt;p&gt;If instead of a window, we have some errors: Maybe some native dependency is missing. Most likely, it is one of these: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span&gt;apt install libx11-dev libxi-dev libgl1-mesa-dev
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For more details, check the &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;?tab=readme-ov-file#build-instructions&quot;&gt;build instructions&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;making-game-levels&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#making-game-levels&quot; aria-label=&quot;Anchor link for: making-game-levels&quot;&gt;🔗&lt;&#x2F;a&gt;Making game levels&lt;&#x2F;h2&gt;
&lt;p&gt;The easiest way to do some 2D-level design with macroquad is with the free tiles editor &lt;a href=&quot;https:&#x2F;&#x2F;www.mapeditor.org&quot;&gt;Tiled&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;tiled.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;&lt;em&gt;Tiled with &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;blob&#x2F;master&#x2F;assets&#x2F;map.json&quot;&gt;Fish Game&#x27;s level&lt;&#x2F;a&gt;&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We have a &lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;macroquad-tiled&quot;&gt;crate&lt;&#x2F;a&gt; for reading tiled data in macroquad. 
&lt;code&gt;our Cargo.toml&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span style=&quot;background-color:#f5f5f5;font-weight:bold;color:#b52a1d;&quot;&gt;...&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;[dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;macroquad &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.3&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# the new dependency, macroquad-tiled crate:
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;macroquad-tiled &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.1&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then load the Tiled map to macroquad and draw a level:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;src&#x2F;main.rs&lt;&#x2F;code&gt;, all assets are in &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;tree&#x2F;master&#x2F;assets&quot;&gt;the Fish Game repo&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;macroquad::prelude::&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;use&lt;&#x2F;span&gt;&lt;span&gt; macroquad_tiled &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as&lt;&#x2F;span&gt;&lt;span&gt; tiled;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[macroquad::main(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Fishgame&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; tileset &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;assets&#x2F;tileset.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; decorations &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;assets&#x2F;decorations1.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; tiled_map_json &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_string&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;assets&#x2F;map.json&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; tiled_map &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;tiled::load_map(
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;tiled_map_json,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;tileset.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, tileset), (&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;decorations1.png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, decorations)],
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;[],
&lt;&#x2F;span&gt;&lt;span&gt;    )
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clear_background&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;BLACK&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;        tiled_map.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_tiles&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; The name of the layer in assets&#x2F;map.json
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;main layer&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;            Rect::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_width&lt;&#x2F;span&gt;&lt;span&gt;(), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;screen_height&lt;&#x2F;span&gt;&lt;span&gt;()),
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        );
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;background.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;Now we have a level background. For a more polished game, it would be reasonable to invest some time into a more complicated camera, window handling, etc.
All of those are implemented in the final Fish Game but will be skipped in the tutorial to get started with Nakama faster.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;character-physics&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#character-physics&quot; aria-label=&quot;Anchor link for: character-physics&quot;&gt;🔗&lt;&#x2F;a&gt;Character physics&lt;&#x2F;h2&gt;
&lt;p&gt;Add a character into the level from the previous chapter:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; whale &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;load_texture&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;assets&#x2F;Whale&#x2F;Whale(76x66)(Orange).png&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;).await;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; for simplicity lets give our world fixed size
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; width &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;700.&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; height &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;500.&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    tiled_map.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_tiles&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; The name of the layer in assets&#x2F;map.json
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;main layer&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        Rect::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, width, height),
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    );
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_texture_ex&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;        whale,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;WHITE&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        DrawTextureParams {
&lt;&#x2F;span&gt;&lt;span&gt;            source: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(Rect::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;76.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;66.&lt;&#x2F;span&gt;&lt;span&gt;)),
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;::default()
&lt;&#x2F;span&gt;&lt;span&gt;        },
&lt;&#x2F;span&gt;&lt;span&gt;    );
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;character.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;Now we have a character and a level. The next step is to allow the user to move the character.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; fish_pos &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;200.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_key_down&lt;&#x2F;span&gt;&lt;span&gt;(KeyCode::Right) {
&lt;&#x2F;span&gt;&lt;span&gt;        fish_pos.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_key_down&lt;&#x2F;span&gt;&lt;span&gt;(KeyCode::Left) {
&lt;&#x2F;span&gt;&lt;span&gt;        fish_pos.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;-= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; fish_bottom_point &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(fish_pos.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;76. &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2.&lt;&#x2F;span&gt;&lt;span&gt;, fish_pos.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;66.&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; fish_tile &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;        fish_bottom_point.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; width &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; tiled_map.raw_tiled_map.width &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        fish_bottom_point.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; height &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; tiled_map.raw_tiled_map.height &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    );
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; tiled_map
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_tile&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;main layer&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, fish_tile.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as u32&lt;&#x2F;span&gt;&lt;span&gt;, fish_tile.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as u32&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_none&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    {
&lt;&#x2F;span&gt;&lt;span&gt;        fish_pos.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;character_moving.gif&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;There are lots hard-coded corner cases to take into account, but putting all of this together gives us a complete platformer character mechanic.&lt;&#x2F;p&gt;
&lt;p&gt;There is a crate with platformer physics implementation based on the brilliant &lt;a href=&quot;https:&#x2F;&#x2F;maddythorson.medium.com&#x2F;celeste-and-towerfall-physics-d24bd2ae0fc5&quot;&gt;article on Celeste and Towerfall physics&lt;&#x2F;a&gt;: &lt;a href=&quot;https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;macroquad-platformer&quot;&gt;macroquad-platformer&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span&gt;[dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;macroquad &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.3&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;macroquad-tiled &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.1&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;macroquad-platformer &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.1&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With the new crate involved, the code will look like the &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;macroquad&#x2F;blob&#x2F;master&#x2F;examples&#x2F;platformer.rs&quot;&gt;platformer example&lt;&#x2F;a&gt;. &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; world &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;World::new();
&lt;&#x2F;span&gt;&lt;span&gt;world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;add_static_tiled_layer&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;    static_colliders,
&lt;&#x2F;span&gt;&lt;span&gt;    tiled_map.raw_tiled_map.tilewidth &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    tiled_map.raw_tiled_map.tileheight &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    tiled_map.raw_tiled_map.width &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as _&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; player &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;add_actor&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;200.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;36&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;66&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; now instead of moving player directly
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; we do it through a crate
&lt;&#x2F;span&gt;&lt;span&gt;    world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;move_h&lt;&#x2F;span&gt;&lt;span&gt;(player, speed.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_frame_time&lt;&#x2F;span&gt;&lt;span&gt;());
&lt;&#x2F;span&gt;&lt;span&gt;    world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;move_v&lt;&#x2F;span&gt;&lt;span&gt;(player, speed.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_frame_time&lt;&#x2F;span&gt;&lt;span&gt;());
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; and to draw the player we ask the crate for the player&amp;#39;s current position:
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; pos &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;actor_pos&lt;&#x2F;span&gt;&lt;span&gt;(player.collider);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;not-fl3&#x2F;a51dbff5f09c04d5a371e55db4c48e13&quot;&gt;Full source code&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now the fish can jump!&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;fish_jump.gif&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;h2 id=&quot;nodes&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#nodes&quot; aria-label=&quot;Anchor link for: nodes&quot;&gt;🔗&lt;&#x2F;a&gt;Nodes&lt;&#x2F;h2&gt;
&lt;p&gt;Now we have enough of a game to start adding Nakama networking. Just one final piece missing.&lt;&#x2F;p&gt;
&lt;p&gt;So far, the game code looks like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; load some resources
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; and initialize more variables
&lt;&#x2F;span&gt;&lt;span&gt;   &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;       &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; check input and change some variables
&lt;&#x2F;span&gt;&lt;span&gt;       &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; make a few draw calls based on the variables content
&lt;&#x2F;span&gt;&lt;span&gt;       
&lt;&#x2F;span&gt;&lt;span&gt;       &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; and repeat this forever
&lt;&#x2F;span&gt;&lt;span&gt;       &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await;
&lt;&#x2F;span&gt;&lt;span&gt;   }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This may be good enough for a quick prototype. But for the whole Fish Game, we are going to have quite a few things in those variables:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;other players&lt;&#x2F;li&gt;
&lt;li&gt;weapons&lt;&#x2F;li&gt;
&lt;li&gt;bullets&lt;&#x2F;li&gt;
&lt;li&gt;level decorations&lt;&#x2F;li&gt;
&lt;li&gt;some UI&lt;&#x2F;li&gt;
&lt;li&gt;some visual effects&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Macroquad does not force any specific way to store data or game objects. Macroquad does have some embedded ways for organizing scenes and is friendly for any third-party ECS-like crates.&lt;&#x2F;p&gt;
&lt;p&gt;For Fish Game, we are going to use macroquad&#x27;s scenes. &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;struct &lt;&#x2F;span&gt;&lt;span&gt;Player {
&lt;&#x2F;span&gt;&lt;span&gt;    collider: Actor,
&lt;&#x2F;span&gt;&lt;span&gt;    speed: Vec2,
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;Player {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;JUMP_SPEED&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;f32 = -&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;700.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;GRAVITY&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;f32 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2000.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;MOVE_SPEED&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;f32 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;300.0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;() -&amp;gt; Player {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; resources &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;storage::get_mut::&amp;lt;Resources&amp;gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        Player {
&lt;&#x2F;span&gt;&lt;span&gt;            collider: resources.physics.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;add_actor&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;200.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100.0&lt;&#x2F;span&gt;&lt;span&gt;), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;36&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;66&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;            speed: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;Node &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;Player {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;draw&lt;&#x2F;span&gt;&lt;span&gt;(node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; resources &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;storage::get_mut::&amp;lt;Resources&amp;gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; pos &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; resources.physics.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;actor_pos&lt;&#x2F;span&gt;&lt;span&gt;(node.collider);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;draw_texture_ex&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;            resources.whale,
&lt;&#x2F;span&gt;&lt;span&gt;            pos.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;- &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;20.&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;            pos.y,
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;WHITE&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;            DrawTextureParams {
&lt;&#x2F;span&gt;&lt;span&gt;                source: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(Rect::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.0&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;76.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;66.&lt;&#x2F;span&gt;&lt;span&gt;)),
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Default&lt;&#x2F;span&gt;&lt;span&gt;::default()
&lt;&#x2F;span&gt;&lt;span&gt;            },
&lt;&#x2F;span&gt;&lt;span&gt;        );
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;mut &lt;&#x2F;span&gt;&lt;span&gt;node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; world &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &amp;amp;mut &lt;&#x2F;span&gt;&lt;span&gt;storage::get_mut::&amp;lt;Resources&amp;gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;().physics;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; pos &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;actor_pos&lt;&#x2F;span&gt;&lt;span&gt;(node.collider);
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; on_ground &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;collide_check&lt;&#x2F;span&gt;&lt;span&gt;(node.collider, pos &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;vec2&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1.&lt;&#x2F;span&gt;&lt;span&gt;));
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; on_ground &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;== &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;false &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            node.speed.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;+= Self&lt;&#x2F;span&gt;&lt;span&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;GRAVITY &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_frame_time&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_key_down&lt;&#x2F;span&gt;&lt;span&gt;(KeyCode::Right) {
&lt;&#x2F;span&gt;&lt;span&gt;            node.speed.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= Self&lt;&#x2F;span&gt;&lt;span&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;MOVE_SPEED&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        } &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;else if &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_key_down&lt;&#x2F;span&gt;&lt;span&gt;(KeyCode::Left) {
&lt;&#x2F;span&gt;&lt;span&gt;            node.speed.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= -Self&lt;&#x2F;span&gt;&lt;span&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;MOVE_SPEED&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        } &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;else &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            node.speed.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0.&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_key_pressed&lt;&#x2F;span&gt;&lt;span&gt;(KeyCode::Space) {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; on_ground {
&lt;&#x2F;span&gt;&lt;span&gt;                node.speed.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= Self&lt;&#x2F;span&gt;&lt;span&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;JUMP_SPEED&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            }
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;move_h&lt;&#x2F;span&gt;&lt;span&gt;(node.collider, node.speed.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_frame_time&lt;&#x2F;span&gt;&lt;span&gt;());
&lt;&#x2F;span&gt;&lt;span&gt;        world.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;move_v&lt;&#x2F;span&gt;&lt;span&gt;(node.collider, node.speed.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_frame_time&lt;&#x2F;span&gt;&lt;span&gt;());
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; this is it, now it will get its draw&#x2F;update calls 
&lt;&#x2F;span&gt;&lt;span&gt;    scene::add_node(Player::new());
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;not-fl3&#x2F;a98d9f9e37a01be8bc2f0d246164b8bb&quot;&gt;Full source code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;It may not look like a big improvement over the previous approach, but scenes allow building complicated node relationships and applying iteration strategies over scene nodes. We are going to use it a lot more in the upcoming sections.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;networking-with-nakama&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#networking-with-nakama&quot; aria-label=&quot;Anchor link for: networking-with-nakama&quot;&gt;🔗&lt;&#x2F;a&gt;Networking with Nakama&lt;&#x2F;h1&gt;
&lt;p&gt;The &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;nakama-rs&#x2F;&quot;&gt;&amp;quot;nakama-rs&amp;quot;&lt;&#x2F;a&gt; crate is a pure Rust implementation of the Nakama protocol.&lt;&#x2F;p&gt;
&lt;p&gt;It allows working with Nakama in three different styles. &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;nakama-rs can produce raw data with either HTTP or WebSocket requests, but leaves the networking implementation for the user.&lt;&#x2F;li&gt;
&lt;li&gt;nakama-rs can make Rest&#x2F;WebSocket calls with that raw data, but with a very low-level interface over requests.&lt;&#x2F;li&gt;
&lt;li&gt;Very high-level stateful client, which hides implementation details completely.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;For Fish Game, we are going to use that high-level client.  That client works as a giant state machine - the user makes non-blocking calls, and the client may change some internal state based on those calls.
Than in the main loop game pull changes from the ApiClient and may react accordingly.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;connecting-to-nakama&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#connecting-to-nakama&quot; aria-label=&quot;Anchor link for: connecting-to-nakama&quot;&gt;🔗&lt;&#x2F;a&gt;Connecting to Nakama&lt;&#x2F;h2&gt;
&lt;p&gt;nakama-rs&#x27; ApiClient will be used as a singleton. Once a global object is created, it is persisted throughout the game lifetime and is globally accessible.&lt;&#x2F;p&gt;
&lt;p&gt;In macroquad, we can use the node system for this. It will still be a singleton, but the access and relationship graph with our new Nakama node will be easily traceable and visible.&lt;&#x2F;p&gt;
&lt;p&gt;So we will create a scene node with ApiClient and  pass a reference to this node to all nodes communicating with Nakama.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub struct &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;api_client: ApiClient,
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span&gt;(key: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;str&lt;&#x2F;span&gt;&lt;span&gt;, server: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;str&lt;&#x2F;span&gt;&lt;span&gt;, port: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;u32&lt;&#x2F;span&gt;&lt;span&gt;, protocol: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;str&lt;&#x2F;span&gt;&lt;span&gt;) -&amp;gt; Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;        Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;            api_client: ApiClient::new(key, server, port, protocol),
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;scene::Node &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;ready&lt;&#x2F;span&gt;&lt;span&gt;(node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; Once created, nakama node should never be deleted.
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; The persist() call will make nakama node a singleton,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; alive during all scene reloads.
&lt;&#x2F;span&gt;&lt;span&gt;        node.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;persist&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; api_client should be &amp;quot;ticked&amp;quot; once per frame
&lt;&#x2F;span&gt;&lt;span&gt;        self.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;tick&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;async &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; now the first node in the scene will be a nakama node
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; nakama &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;scene::add_node(nodes::Nakama::new(
&lt;&#x2F;span&gt;&lt;span&gt;        credentials::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;NAKAMA_KEY&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        credentials::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;NAKAMA_SERVER&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        credentials::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;NAKAMA_PORT&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        credentials::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;NAKAMA_PROTOCOL&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    ));
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span&gt;} 
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;authentication-and-registration&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#authentication-and-registration&quot; aria-label=&quot;Anchor link for: authentication-and-registration&quot;&gt;🔗&lt;&#x2F;a&gt;Authentication and registration&lt;&#x2F;h2&gt;
&lt;p&gt;Macroquad uses the immediate mode gui concept for UI. Here we will skip GUI style setup (it may be found &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;blob&#x2F;25a9872b540035f2998f8624eba5423066d4715d&#x2F;src&#x2F;gui.rs#L34-L43&quot;&gt;here&lt;&#x2F;a&gt;), and we will proceed to the UI logic instead.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;login.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;Most UI windows interacting with Nakama are built in the same way:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;get Nakama node&lt;&#x2F;li&gt;
&lt;li&gt;check if some operation is in progress, and if it is - show loading UI&lt;&#x2F;li&gt;
&lt;li&gt;check if there is some error to show&lt;&#x2F;li&gt;
&lt;li&gt;check if Nakama finished the required operation and can proceed to the next window&lt;&#x2F;li&gt;
&lt;li&gt;draw all input elements and on some button press - make a Nakama request&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; email &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;::new();
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; password &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;::new();
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; nakama &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;scene::get_node(nakama).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;            
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;in_progress&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;in_progress_gui&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if let &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(error) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;error&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;as_deref&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;        ui.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;label&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, error);
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;authenticated&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; done with authentication, proceeding to matchmaking
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;Scene::MatchmakingLobby;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    widgets::InputText::new(hash!())
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;label&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Email&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;ui&lt;&#x2F;span&gt;&lt;span&gt;(ui, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; email);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    widgets::InputText::new(hash!())
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;password&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;label&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Password&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;ui&lt;&#x2F;span&gt;&lt;span&gt;(ui, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; password);
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ui.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;button&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Login&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;authenticate&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;email, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;password);
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;next_frame&lt;&#x2F;span&gt;&lt;span&gt;().await;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;real-time-multiplayer&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#real-time-multiplayer&quot; aria-label=&quot;Anchor link for: real-time-multiplayer&quot;&gt;🔗&lt;&#x2F;a&gt;Real-time multiplayer&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;em&gt;The real-time multiplayer engine makes it easy for users to set up and join matches where they can rapidly exchange data with opponents.
Any user can participate in matches with other users. Users can create, join, and leave matches with messages sent from clients. A match exists on the server until its last participant has left.
Any data sent through a match is immediately routed to all other participants. The matches are kept in memory and can be persisted as needed.&lt;&#x2F;em&gt;
&lt;a href=&quot;https:&#x2F;&#x2F;heroiclabs.com&#x2F;docs&#x2F;gameplay-multiplayer-realtime&#x2F;&quot;&gt;source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Match window code is very similar to the authentication window, as well as all other windows in Fish Game:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;loop &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; check if nakama is in progress 
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; check if nakama has errors
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; check if nakama finished and we can return
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; draw some input widgets and maybe make nakama request
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now let&#x27;s focus on how Nakama&#x27;s real-time matches work.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;matchmaker.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;To create a match:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;nakama.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;socket_create_match&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will start a process that on success will give some id in &lt;code&gt;nakama.match_id()&lt;&#x2F;code&gt;. &lt;&#x2F;p&gt;
&lt;p&gt;This ID may be shared to friends to join this exact match later: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;nakama.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;socket_join_match_by_id&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;match_id);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We have two problems here: &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Match discoverability.
Sharing a match id with a friend works for private games, but we need a better solution for public games.
This will be addressed in the &lt;a href=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;fish-tutorial&#x2F;#Matchmaker&quot;&gt;Matchmaker&lt;&#x2F;a&gt; section.&lt;&#x2F;li&gt;
&lt;li&gt;Nakama considers a match started right after the &lt;code&gt;create_match&lt;&#x2F;code&gt; call, and anyone can join at any moment. While the rules of Fish Game won&#x27;t let players join in the middle, and the game starts only when all of the players have pressed the “ready” button.
This will be addressed in the &lt;a href=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;fish-tutorial&#x2F;#Ready-window&quot;&gt;Ready window&lt;&#x2F;a&gt; section.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;matchmaker&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#matchmaker&quot; aria-label=&quot;Anchor link for: matchmaker&quot;&gt;🔗&lt;&#x2F;a&gt;Matchmaker&lt;&#x2F;h2&gt;
&lt;p&gt;You can use the Matchmaker to find other players. It is possible to match them using properties and a query that specifies the values the other players&#x27; properties should hold. In &lt;code&gt;nakama-rs&lt;&#x2F;code&gt; the Matchmaker is a &lt;code&gt;struct&lt;&#x2F;code&gt; and can be created using &lt;code&gt;Matchmaker::new()&lt;&#x2F;code&gt;. There are two types of properties, string properties and numeric properties that can be added with &lt;code&gt;matchmaker.add_string_property(&amp;quot;name&amp;quot;, &amp;quot;value&amp;quot;)&lt;&#x2F;code&gt; and &lt;code&gt;matchmaker.add_numeric_property(&amp;quot;rank&amp;quot;, 1000.0)&lt;&#x2F;code&gt; respectively. Names of properties should be unique across both types.&lt;&#x2F;p&gt;
&lt;p&gt;The query is a space-separated string using the &lt;a href=&quot;http:&#x2F;&#x2F;blevesearch.com&#x2F;docs&#x2F;Query-String-Query&#x2F;&quot;&gt;Bleve Query-String-Query Syntax&lt;&#x2F;a&gt;. It is possible to add queries manually using &lt;code&gt;matchmaker.add_query_item(&amp;quot;properties.region:Europe&amp;quot;)&lt;&#x2F;code&gt; but &lt;code&gt;nakama-rs&lt;&#x2F;code&gt; provides a helper to construct the query string using the builder pattern. For now, terms, numeric ranges, required, optional and exclusion are supported.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; By default query items are optional. The Matchmaker will prefer
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; players holding the value, but will also match players without it.
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; Prefer players from Europe.
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; query_item &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;QueryItemBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;region&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;term&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Europe&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; Only match with players from Europe    
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; query_item &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;QueryItemBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;region&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;term&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Europe&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;required&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;();   
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; Only match with players not from Europe
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; query_item &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;QueryItemBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;region&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;term&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Europe&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;excluded&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; query_item &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;QueryItemBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;rank&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;lt&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; or .gt(10), .leq(10) and .geq(10)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In addition, it is possible to specify the minimum and the maximum number of players using &lt;code&gt;matchmaker.min(2)&lt;&#x2F;code&gt; and &lt;code&gt;matchmaker.max(100)&lt;&#x2F;code&gt;. The default values are 2 and 100, respectively.&lt;&#x2F;p&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;matchmaker2.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;Fish Game only specifies one property called &lt;code&gt;&amp;quot;engine&amp;quot;&lt;&#x2F;code&gt; with the value &lt;code&gt;macroquad_engine&lt;&#x2F;code&gt;. The query only specifies that we also match players holding the same value for that property, allowing us to avoid matchmaking players running a different game on the same Nakama server.&lt;&#x2F;p&gt;
&lt;p&gt;The full matchmaker setup can be seen below:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;widgets::InputText::new(hash!())
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;ratio&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1. &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;4.&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;filter_numbers&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;label&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Minimum players&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;ui&lt;&#x2F;span&gt;&lt;span&gt;(ui, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; minimum_players);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;widgets::InputText::new(hash!())
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;ratio&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1. &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&#x2F; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;4.&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;filter_numbers&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;label&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Maximum players&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;ui&lt;&#x2F;span&gt;&lt;span&gt;(ui, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; maximum_players);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ui.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;button&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Start matchmaking&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; matchmaker &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;Matchmaker::new();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    matchmaker
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;min&lt;&#x2F;span&gt;&lt;span&gt;(minimum_players.parse::&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;u32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;max&lt;&#x2F;span&gt;&lt;span&gt;(maximum_players.parse::&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;u32&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;add_string_property&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;engine&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;macroquad_matchmaking&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;add_query_item&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;QueryItemBuilder::new(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;engine&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;required&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;term&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;macroquad_matchmaking&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;                .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;build&lt;&#x2F;span&gt;&lt;span&gt;(),
&lt;&#x2F;span&gt;&lt;span&gt;        );
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;socket_add_matchmaker&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;matchmaker);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    next_scene &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(Scene::WaitingForMatchmaking { private: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;false &lt;&#x2F;span&gt;&lt;span&gt;});
&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can add the Matchmaker by calling &lt;code&gt;nakama.socket_add_matchmaker(&amp;amp;matchmaker)&lt;&#x2F;code&gt;, adding the user to the server&#x27;s matchmaking pool. The user will stay in the pool until matched as long as they are online or until you remove them manually. It is possible to add multiple matchmakers with different queries simultaneously to look for different types of matches.&lt;&#x2F;p&gt;
&lt;p&gt;When the server matches the user, the ApiClient will handle the event and set &lt;code&gt;nakama.matchmaker_token&lt;&#x2F;code&gt; to &lt;code&gt;Some(token)&lt;&#x2F;code&gt;. The token is a short-lived entry ticket that you can use to join a match with the other matched players by calling &lt;code&gt;nakama.socket_join_match_by_token(token)&lt;&#x2F;code&gt;. The server creates the match as soon as the first player tries to join it and sends an event once the player joined successfully. In the client, &lt;code&gt;nakama.match_id()&lt;&#x2F;code&gt; will then contain a value. It is now possible to send match data between players.&lt;&#x2F;p&gt;
&lt;p&gt;For additional details, check out the &lt;a href=&quot;https:&#x2F;&#x2F;heroiclabs.com&#x2F;docs&#x2F;gameplay-matchmaker&quot;&gt;Matchmaker documentation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;exchanging-messages&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#exchanging-messages&quot; aria-label=&quot;Anchor link for: exchanging-messages&quot;&gt;🔗&lt;&#x2F;a&gt;Exchanging messages&lt;&#x2F;h2&gt;
&lt;p&gt;nakama-rs&#x27;&lt;code&gt;ApiClient&lt;&#x2F;code&gt; provides two API calls to communicate between each other: &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fn socket_send&amp;lt;T: SerBin&amp;gt;(&amp;amp;self, opcode: u32, data: T)&lt;&#x2F;code&gt;
&lt;code&gt;socket_send&lt;&#x2F;code&gt; will binary serialize given message and broadcast it to each player in the room. Opcode here acts as a tag or discriminant in rust &lt;a href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;ch06-01-defining-an-enum.html&quot;&gt;enum&lt;&#x2F;a&gt; - a small descriptor specifiyng what kind of data is being sent.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;fn try_recv(&amp;amp;self) -&amp;gt; Option&amp;lt;Event&amp;gt;&lt;&#x2F;code&gt;
&lt;code&gt;try_recv&lt;&#x2F;code&gt; will give an Event if someone sent a message or joined&#x2F;left match since last &lt;code&gt;try_recv&lt;&#x2F;code&gt; call.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;A convenient Rust representation of an &lt;code&gt;opcode&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;data&lt;&#x2F;code&gt; pair may look like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;mod &lt;&#x2F;span&gt;&lt;span&gt;message {
&lt;&#x2F;span&gt;&lt;span&gt;    #[derive(Debug, Clone, SerBin, DeBin, PartialEq)]
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub struct &lt;&#x2F;span&gt;&lt;span&gt;State {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;pos: (&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;u16&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;u16&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;facing: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;bool&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;State {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;OPCODE&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;i32 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    #[derive(Debug, Clone, SerBin, DeBin, PartialEq)]
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub struct &lt;&#x2F;span&gt;&lt;span&gt;Damage {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;target: String,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;direction: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;bool&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;Damage {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;OPCODE&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;i32 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then, in order to send some message:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;send&lt;&#x2F;span&gt;&lt;span&gt;(Damage::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;OPCODE&lt;&#x2F;span&gt;&lt;span&gt;, Damage {
&lt;&#x2F;span&gt;&lt;span&gt;    target: target.network_id,
&lt;&#x2F;span&gt;&lt;span&gt;    direction: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;false
&lt;&#x2F;span&gt;&lt;span&gt;});
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To recieve such a message on other client: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;while let &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(event) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; nakama.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;try_recv&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Event may be either a message from other client or a system even like joined&#x2F;leaved player. This will be explained in details in &lt;a href=&quot;https:&#x2F;&#x2F;macroquad.rs&#x2F;articles&#x2F;fish-tutorial&#x2F;#Player-state-synchronization&quot;&gt;Player state syncronization&lt;&#x2F;a&gt; section.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;player-state-synchronization&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#player-state-synchronization&quot; aria-label=&quot;Anchor link for: player-state-synchronization&quot;&gt;🔗&lt;&#x2F;a&gt;Player state synchronization&lt;&#x2F;h2&gt;
&lt;p&gt;Fish Game uses a relayed network synchronization model. Each player simulates its physics and sends its state to other players.&lt;&#x2F;p&gt;
&lt;p&gt;One of the players is called &amp;quot;host&amp;quot; and is responsible for global events and conflict resolution.&lt;&#x2F;p&gt;
&lt;p&gt;Nakama node from previous chapters:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;scene::Node &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        node.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;tick&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now it will also take responsibility for state synchronization. &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;scene::Node &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; send our own player state to all the other players
&lt;&#x2F;span&gt;&lt;span&gt;        {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; player &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;scene::find_node_by_type::&amp;lt;Player&amp;gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; state &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;message::State {
&lt;&#x2F;span&gt;&lt;span&gt;                pos: (player.pos.x &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as u16&lt;&#x2F;span&gt;&lt;span&gt;, player.pos.y &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as u16&lt;&#x2F;span&gt;&lt;span&gt;), 
&lt;&#x2F;span&gt;&lt;span&gt;                facing: player.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;facing&lt;&#x2F;span&gt;&lt;span&gt;(),
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;            };
&lt;&#x2F;span&gt;&lt;span&gt;            node.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;socket_send&lt;&#x2F;span&gt;&lt;span&gt;(message::State::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;OPCODE&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;message::State(state.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;));
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        node.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;tick&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In the final game code, the &lt;code&gt;State&lt;&#x2F;code&gt; structure is slightly more &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;blob&#x2F;master&#x2F;src&#x2F;nodes&#x2F;nakama&#x2F;nakama_realtime_game.rs#L67&quot;&gt;optimized&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Also, in the real game, network fps are different from the rendering fps - with networking lag sending state 60 times per second is too much, and ~15-20 should be enough. Fish Game works on 15.
But the idea is the same - The &lt;code&gt;Nakama&lt;&#x2F;code&gt; node packs all the important parts of the player state and sends it over the network to all the other players in the room. &lt;&#x2F;p&gt;
&lt;p&gt;Next step - receive other players&#x27; data and draw other players.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;struct &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; now Nakama node is keeping track on all remote players in the scene
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; key here is session_id from nakama presence - the always unique player identifier
&lt;&#x2F;span&gt;&lt;span&gt;    remote_players: HashMap&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;, Handle&amp;lt;RemotePlayer&amp;gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;scene::Node &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; send our own player state to all the other players
&lt;&#x2F;span&gt;&lt;span&gt;        {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; receive other players updates
&lt;&#x2F;span&gt;&lt;span&gt;        {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;while let &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(event) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; nakama.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;try_recv&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; proceed event and modify the scene somehow
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;..
&lt;&#x2F;span&gt;&lt;span&gt;            }
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        node.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;tick&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That is the bare-bones implementation - for each frame, we receive all the Nakama events and apply changes to the scene. 
We need to have a list of &lt;code&gt;remote_players&lt;&#x2F;code&gt; to track the scene nodes of remote players and add&#x2F;remove players on game joins or leaves. And we need to apply the received messages to those remote players.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; event {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; add or remove RemotePlayer node
&lt;&#x2F;span&gt;&lt;span&gt;    Event::::Presence { joins, leaves } &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; joined &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; joins {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; joined_id &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; join.session_id;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; username &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; join.username;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; remote_player &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;RemotePlayer::new(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;username, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;joined);
&lt;&#x2F;span&gt;&lt;span&gt;             self.remote_players.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;                joined.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;clone&lt;&#x2F;span&gt;&lt;span&gt;(),
&lt;&#x2F;span&gt;&lt;span&gt;                scene::add_node(remote_player),
&lt;&#x2F;span&gt;&lt;span&gt;            );
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; leaver &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; leaves {
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; other &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;self.remote_players.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;remove&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;leaver).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; leaver &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;scene::get_node::&amp;lt;RemotePlayer&amp;gt;(leaver).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;            other.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;delete&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will keep the list of active remote players accurate, and for each, we will have a RemotePlayer node.&lt;&#x2F;p&gt;
&lt;p&gt;The RemotePlayer node may be very similar to the Player node but with very different logic.&lt;&#x2F;p&gt;
&lt;p&gt;Then continue the event handling &lt;code&gt;match&lt;&#x2F;code&gt; to deal with a data message:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; received opcode&#x2F;data pair
&lt;&#x2F;span&gt;&lt;span&gt;Event::MatchData {
&lt;&#x2F;span&gt;&lt;span&gt;    user_id,
&lt;&#x2F;span&gt;&lt;span&gt;    opcode,
&lt;&#x2F;span&gt;&lt;span&gt;    data,
&lt;&#x2F;span&gt;&lt;span&gt;} &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if let &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(remote_player) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;self.remote_players.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;user_id) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let mut&lt;&#x2F;span&gt;&lt;span&gt; remote_player &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;scene::get_node(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;remote_player).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;match&lt;&#x2F;span&gt;&lt;span&gt; opcode &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as i32 &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            message::State::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;OPCODE &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; deserialize message according to opcode
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let &lt;&#x2F;span&gt;&lt;span&gt;message::State(data) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;DeBin::deserialize_bin(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;data).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;                &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; and apply message data to the remote player node
&lt;&#x2F;span&gt;&lt;span&gt;                remote_player.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_pos&lt;&#x2F;span&gt;&lt;span&gt;(data.pos.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0 &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32&lt;&#x2F;span&gt;&lt;span&gt;, data.pos.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as f32&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;                remote_player.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;set_facing&lt;&#x2F;span&gt;&lt;span&gt;(data.facing);
&lt;&#x2F;span&gt;&lt;span&gt;            }
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;} 
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;blob&#x2F;master&#x2F;src&#x2F;nodes&#x2F;nakama&#x2F;nakama_realtime_game.rs&quot;&gt;&lt;em&gt;src&#x2F;nodes&#x2F;nakama&#x2F;nakama_realtime_game.rs&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;a-note-about-network-performance&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-note-about-network-performance&quot; aria-label=&quot;Anchor link for: a-note-about-network-performance&quot;&gt;🔗&lt;&#x2F;a&gt;A note about network performance&lt;&#x2F;h2&gt;
&lt;p&gt;While Fish Game has good enough network performance to be fully functional, it is kept intentionally simplistic for demonstration purposes.&lt;&#x2F;p&gt;
&lt;p&gt;Nakama’s real-time Multiplayer API sends data over WebSockets, which means TCP. TCP is reliable (you know if the message you sent arrived or not), but it’s slower. For an in-depth explanation about the trade-offs between TCP and UDP, see &lt;a href=&quot;https:&#x2F;&#x2F;heroiclabs.com&#x2F;docs&#x2F;expert-tcp-udp&#x2F;&quot;&gt;Choosing TCP or UDP: a guide for game developers&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Fast-paced games commonly use UDP to send synchronization information: it’s unreliable (your message can get lost) but faster. Using unreliable UDP would allow for some network optimizations that we can’t do here. For example, with some kinds of game states, only the most recent message is valid (all older messages are immediately invalid once a newer one arrives), so we could use the faster UDP packets.
It’s OK if some get lost, we&#x27;d just take the newest one that arrives.&lt;&#x2F;p&gt;
&lt;p&gt;This game is fast-paced enough that it ideally should be using “input prediction and rollback” rather than “input prediction and correction”. When using rollback, rather than applying the corrections you received to the current state of the game, you roll back the local game state to the time when the remote state was generated, apply it, and then roll the game state forward to the current time. This can help eliminate lag and avoid situations where one player sees themselves hitting another player, but it doesn’t  register as a hit. However, rollback is a lot more complicated to implement than correction. Fish Game has enough in common with arcade-style Fighting Games that the most optimal networking technique for it might be the &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pond3r&#x2F;ggpo&quot;&gt;GGPO&lt;&#x2F;a&gt; technique.&lt;&#x2F;p&gt;
&lt;p&gt;This would merit further investigation if this was a commercial game.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;global-events-and-conflicts-resolution&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#global-events-and-conflicts-resolution&quot; aria-label=&quot;Anchor link for: global-events-and-conflicts-resolution&quot;&gt;🔗&lt;&#x2F;a&gt;Global events and conflicts resolution&lt;&#x2F;h2&gt;
&lt;p&gt;In Fish Game, we have some global events. Good example: Spawn process of pickable weapon.&lt;&#x2F;p&gt;
&lt;p&gt;There are two ways to simulate such a process:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Make it deterministic and simulate it on each client.&lt;&#x2F;li&gt;
&lt;li&gt;Call one of the clients “host”. Simulate such an event only on that client and this client will tell everyone else which weapon spawned where.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;With the deterministic approach, we are going to have a problem with conflicts - if two players correctly simulated that they picked the weapon at the very same time, who is right? &lt;&#x2F;p&gt;
&lt;p&gt;With the &amp;quot;host&amp;quot; approach it is way easier - the host may be responsible for such decisions.&lt;&#x2F;p&gt;
&lt;p&gt;While all the players have unique IDs and everyone knows each other&#x27;s ID, we can just sort the list of &lt;code&gt;remote_players&lt;&#x2F;code&gt; IDs and whoever&#x27;s first is the host. &lt;&#x2F;p&gt;
&lt;p&gt;Now we can create a special node, &lt;code&gt;GlobalEvents&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub struct &lt;&#x2F;span&gt;&lt;span&gt;GlobalEvents {
&lt;&#x2F;span&gt;&lt;span&gt;    nakama: NodeHandle&amp;lt;Nakama&amp;gt;,
&lt;&#x2F;span&gt;&lt;span&gt;    last_spawn_time: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;f32&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;scene::Node &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;GlobalEvents {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;mut &lt;&#x2F;span&gt;&lt;span&gt;node: RefMut&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;Self&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; nakama &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;scene::get_node(node.nakama).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;        
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; nakama.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;is_host&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;== &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;false &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;get_time&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt; node.last_spawn_time &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;gt;= Self&lt;&#x2F;span&gt;&lt;span&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;SPAWN_INTERVAL &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;as _
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; node.spawned_items.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;() &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;lt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;3 &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; new_item_pos &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= ..&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; new_item_type &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= ..&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            
&lt;&#x2F;span&gt;&lt;span&gt;            nakama.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;spawn_item&lt;&#x2F;span&gt;&lt;span&gt;(new_item_pos, new_item_type);    
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;        
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;blob&#x2F;master&#x2F;src&#x2F;nodes&#x2F;global_events.rs&quot;&gt;&lt;em&gt;src&#x2F;nodes&#x2F;global_events.rs&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;ready-window&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#ready-window&quot; aria-label=&quot;Anchor link for: ready-window&quot;&gt;🔗&lt;&#x2F;a&gt;Ready window&lt;&#x2F;h2&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;ready.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;One of our unsolved problems: in Fish Game the game starts only when all the players joined the match, can see each other and has opted in as ready. &lt;&#x2F;p&gt;
&lt;p&gt;After this point, it is impossible to join a match and only one last standing fish will win.&lt;&#x2F;p&gt;
&lt;p&gt;All this logic may be implemented on top of Nakama&#x27;s messages.&lt;&#x2F;p&gt;
&lt;p&gt;We can add a flag to our Nakama node:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;struct &lt;&#x2F;span&gt;&lt;span&gt;Nakama {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;api_client: ApiClient,
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub &lt;&#x2F;span&gt;&lt;span&gt;game_started: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;bool 
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And introduce a special message:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;mod &lt;&#x2F;span&gt;&lt;span&gt;messages {
&lt;&#x2F;span&gt;&lt;span&gt;    #[derive(Debug, Clone, SerBin, DeBin, PartialEq)]
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub struct &lt;&#x2F;span&gt;&lt;span&gt;Ready;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;Ready {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;pub const &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;OPCODE&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;i32 = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;6&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now it is the game&#x27;s responsibility to figure when to start a match. In Fish Game rules are quite simple - before everyone pushed &amp;quot;Ready&amp;quot; and the host confirmed by pushing &amp;quot;Start game&amp;quot; - no loot is spawning and noone is allowed to move. Implementation is in &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;heroiclabs&#x2F;fishgame-macroquad&#x2F;blob&#x2F;master&#x2F;src&#x2F;nodes&#x2F;nakama&#x2F;nakama_realtime_game.rs&quot;&gt;nakama node&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;But this logic may be totally different depending on game design, and the goal of this little chapter - demonstrate where nakama&#x27;s area of responsibility in the matchmaker&#x2F;match logic ends and game should roll its own logic. &lt;&#x2F;p&gt;
&lt;h2 id=&quot;leaderboards&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#leaderboards&quot; aria-label=&quot;Anchor link for: leaderboards&quot;&gt;🔗&lt;&#x2F;a&gt;Leaderboards&lt;&#x2F;h2&gt;
&lt;p&gt;There’s one last Nakama feature we’re going to look at before ending this tutorial: Leaderboards.&lt;&#x2F;p&gt;
&lt;p&gt;Leaderboards need to be created on the server before your game can write data to them. This is done in Fish Game by adding a small server-side Lua module in &lt;code&gt;nakama&#x2F;data&#x2F;modules&#x2F;fish_game.lua&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;lua&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-lua &quot;&gt;&lt;code class=&quot;language-lua&quot; data-lang=&quot;lua&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;local &lt;&#x2F;span&gt;&lt;span&gt;nk &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;require&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;nakama&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;nk.run_once(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;function&lt;&#x2F;span&gt;&lt;span&gt;(context)
&lt;&#x2F;span&gt;&lt;span&gt;  nk.leaderboard_create(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;fish_game_wins&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;desc&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;incr&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;end&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This runs on the Nakama server at startup and creates a leaderboard called “fishgamewins”, which we’re going to use to track the total number of wins that each player has gotten.&lt;&#x2F;p&gt;
&lt;p&gt;It’s a non-authoritative leaderboard (the &lt;code&gt;false&lt;&#x2F;code&gt; in the 2nd argument), which means that the game clients can modify the leaderboard themselves, rather than requiring server-side logic to do it. It’s sorted in descending order (the &amp;quot;desc&amp;quot; in the 3rd argument) and is updated by incrementing the score (the &amp;quot;incr&amp;quot; in the 4th argument).&lt;&#x2F;p&gt;
&lt;p&gt;Note: Nakama modules can be written in Lua, Go or (in Nakama 3) JavaScript.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;posting-results-to-the-leaderboard&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#posting-results-to-the-leaderboard&quot; aria-label=&quot;Anchor link for: posting-results-to-the-leaderboard&quot;&gt;🔗&lt;&#x2F;a&gt;Posting results to the leaderboard&lt;&#x2F;h2&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;back_to_lobby.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;When only one fish is alive and the game has ended, the winner may update the leaderboard record.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;write_leaderboard_record&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;fish_game_wins&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We may want to wait for the result status to display some error and retry if we got a network error.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;accessing-the-leaderboard&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#accessing-the-leaderboard&quot; aria-label=&quot;Anchor link for: accessing-the-leaderboard&quot;&gt;🔗&lt;&#x2F;a&gt;Accessing the leaderboard&lt;&#x2F;h2&gt;
&lt;img src=&quot;&#x2F;fishgame_tutorial&#x2F;leaderboard.png&quot;  width=&quot;100%&quot;&#x2F;&gt;
&lt;p&gt;The leaderboard window is not much different from the authentication&#x2F;matchmaking window.&lt;&#x2F;p&gt;
&lt;p&gt;First, make the Nakama request: &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span&gt;nakama.api_client.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;list_leaderboard_records&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;fish_game_wins&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And then on success we will have something in &lt;code&gt;api_client.leaderboard_records&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;if let &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Some&lt;&#x2F;span&gt;&lt;span&gt;(leaderboard) &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; nakama
&lt;&#x2F;span&gt;&lt;span&gt;    .api_client
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;leaderboard_records&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;fish_game_wins&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; record &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;in &amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;leaderboard.records {
&lt;&#x2F;span&gt;&lt;span&gt;        ui.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;label&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt;format!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, record.username, record.score));
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript interop with miniquad</title>
        <published>2021-04-01T20:10:42+00:00</published>
        <updated>2021-04-01T20:10:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/wasm/" type="text/html"/>
        <id>https://macroquad.rs/articles/wasm/</id>
        
        <content type="html">&lt;h1 id=&quot;intro&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#intro&quot; aria-label=&quot;Anchor link for: intro&quot;&gt;🔗&lt;&#x2F;a&gt;Intro&lt;&#x2F;h1&gt;
&lt;p&gt;A short intro into the current state of wasm:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;cargo build --target wasm32-unknown-unknown&lt;&#x2F;code&gt; will produce &lt;code&gt;.wasm&lt;&#x2F;code&gt; file. &lt;&#x2F;p&gt;
&lt;p&gt;One .wasm file is one &amp;quot;module&amp;quot;. The module is very similar to &lt;code&gt;.o&lt;&#x2F;code&gt; or &lt;code&gt;.dll&lt;&#x2F;code&gt; files on native platforms - its a dynamically loadable library with some functions.&lt;&#x2F;p&gt;
&lt;p&gt;What actually is inside wasm file: &lt;a href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;WebAssembly&#x2F;Understanding_the_text_format&quot;&gt;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;WebAssembly&#x2F;Understanding_the_text_format&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Each wasm module has two lists: import functions and export functions.&lt;br &#x2F;&gt;
Export functions: functions exported from wasm that can be called later from JS.&lt;br &#x2F;&gt;
Import functions: JS functions that can be called from any WASM function.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;wasm&amp;quot; can&#x27;t be included in the web page with &lt;code&gt;&amp;lt;script&amp;gt;&lt;&#x2F;code&gt; tag. Instead, &amp;quot;wasm&amp;quot; is loaded with a special JS code. &lt;&#x2F;p&gt;
&lt;p&gt;That loader code is doing this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;load wasm binary data - download the file from the internet and get bytes&lt;&#x2F;li&gt;
&lt;li&gt;fill import functions table. all the JS functions that wasm use should be in that table&lt;&#x2F;li&gt;
&lt;li&gt;call browser api to instantiate wasm with the given import table&lt;&#x2F;li&gt;
&lt;li&gt;get references into now loaded wasm&#x27;s functions and wasm&#x27;s memory. Now JS can call our wasm! &lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In miniquad&#x27;s case that JS loader code will also call &amp;quot;main&amp;quot; function from wasm export and will forward JS events as WASM functions calls.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;basic-usage&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#basic-usage&quot; aria-label=&quot;Anchor link for: basic-usage&quot;&gt;🔗&lt;&#x2F;a&gt;Basic usage&lt;&#x2F;h1&gt;
&lt;p&gt;To get wasm module with all necessary export functions: add &amp;quot;miniquad&amp;quot; as a dependency in Cargo.toml.
Then, to load this wasm module, use miniquad&#x27;s JS wasm loader. Right now its named as &amp;quot;gl.js&amp;quot; for historical reasons:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;&amp;lt;script src=&amp;quot;https:&#x2F;&#x2F;not-fl3.github.io&#x2F;miniquad-samples&#x2F;gl.js&amp;quot;&amp;gt;&amp;lt;&#x2F;script&amp;gt; &amp;lt;!-- gl.js from miniquad repo (native&#x2F;sapp-wasm&#x2F;js&#x2F;gl.js) --&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;script&amp;gt;load(&amp;quot;quad.wasm&amp;quot;);&amp;lt;&#x2F;script&amp;gt; &amp;lt;!-- Your compiled wasm file --&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;advances-linking&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#advances-linking&quot; aria-label=&quot;Anchor link for: advances-linking&quot;&gt;🔗&lt;&#x2F;a&gt;Advances linking&lt;&#x2F;h1&gt;
&lt;p&gt;Sometimes miniquad&#x27;s API is not enough and custom javascript is needed.&lt;&#x2F;p&gt;
&lt;p&gt;miniquad&#x27;s gl.js will provide two global variables: &amp;quot;wasm_exports&amp;quot; and &amp;quot;wasm_memory&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;All rust&#x27;s &amp;quot;#[no_mangle] pub extern &amp;quot;C&amp;quot; fn function_name() {}&amp;quot; functions will be available to call from &amp;quot;wasm_exports&amp;quot;.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;wasm_exports.my_rust_function(1, 2, 3); &#x2F;&#x2F; make a wasm call from JS
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To call js from rust, however, some initialization work need to be done. All JS functions available to wasm should be explicitly listed before wasm loading. Before &amp;quot;load&amp;quot; call in our case. 
The set of JS functions available to call from rust is called Plugin in miniquad&#x27;s terminology.&lt;&#x2F;p&gt;
&lt;p&gt;Each plugin has two functions:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;register&lt;&#x2F;em&gt;. Will be called before wasm initialization. Can add additional function to wasm&#x27;s import table: to make plugins JS code available for wasm.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;em&gt;set_wasm_refs&lt;&#x2F;em&gt;. Will be called after successful wasm initialization and to allow plugin store wasm&#x27;s export table and wasm&#x27;s memory - to call any rust function available later in JS.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;To add plugin call &amp;quot;miniquad_add_plugin&amp;quot; from plugin&#x27;s JS file. &amp;quot;gl.js&amp;quot; should be already imported with &lt;code&gt;&amp;lt;script&amp;gt;&lt;&#x2F;code&gt; in the current web page. &lt;&#x2F;p&gt;
&lt;p&gt;Minimal example: &lt;&#x2F;p&gt;
&lt;p&gt;main.rs:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;extern &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;C&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;hi_from_js&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;#[no_mangle]
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;extern &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;C&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;hi_from_rust&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; we can call JS from rust!
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;hi_from_js&lt;&#x2F;span&gt;&lt;span&gt;(); 
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;struct &lt;&#x2F;span&gt;&lt;span&gt;Stage;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;impl &lt;&#x2F;span&gt;&lt;span&gt;EventHandler &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;Stage {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;update&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut &lt;&#x2F;span&gt;&lt;span&gt;self, _ctx: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; Context) {}
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;draw&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut &lt;&#x2F;span&gt;&lt;span&gt;self, _ctx: &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;&amp;amp;mut&lt;&#x2F;span&gt;&lt;span&gt; Context) {}
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    miniquad::start(conf::Conf::default(), |&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;mut &lt;&#x2F;span&gt;&lt;span&gt;ctx| {      
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;Box&lt;&#x2F;span&gt;&lt;span&gt;::new(Stage))
&lt;&#x2F;span&gt;&lt;span&gt;    });
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;plugin.js&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;register_plugin &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= function &lt;&#x2F;span&gt;&lt;span&gt;(importObject) {
&lt;&#x2F;span&gt;&lt;span&gt;    importObject.env.&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;hi_from_wasm &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= function &lt;&#x2F;span&gt;&lt;span&gt;(js_object) {
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;console&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;log&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;hi&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    }
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;document.&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;onclick &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= function &lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; and rust from JS!
&lt;&#x2F;span&gt;&lt;span&gt;    wasm_exports.&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;hi_from_rust&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;};
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; miniquad_add_plugin receive an object with two fields: register_plugin and on_init. Both are functions, both are optional.
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;miniquad_add_plugin&lt;&#x2F;span&gt;&lt;span&gt;({register_plugin});
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;index.html&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;html&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-html &quot;&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;head&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;meta &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;charset&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;title&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;TITLE&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;title&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;style&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;html&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;canvas &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;margin&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;px&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;padding&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;px&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;width&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;height&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;100&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;overflow&lt;&#x2F;span&gt;&lt;span&gt;: hidden;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;position&lt;&#x2F;span&gt;&lt;span&gt;: absolute;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;background&lt;&#x2F;span&gt;&lt;span&gt;: black;
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;z-index&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#0086b3;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;        }
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;style&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;head&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;canvas &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;id&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;glcanvas&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;tabindex&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;#39;1&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;canvas&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;src&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;https:&#x2F;&#x2F;not-fl3.github.io&#x2F;miniquad-samples&#x2F;gl.js&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script &lt;&#x2F;span&gt;&lt;span style=&quot;color:#795da3;&quot;&gt;src&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;plugin.js&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;load(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;sapp-jsutils.wasm&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;html&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The very good thing about WASM - that everything is super transparent and straightforward. console.log(wasm_exports) will give a very clear picture of whats going on, what functions are available. And so on - each object is debug friendly.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;type-system-helpers&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#type-system-helpers&quot; aria-label=&quot;Anchor link for: type-system-helpers&quot;&gt;🔗&lt;&#x2F;a&gt;Type system helpers&lt;&#x2F;h1&gt;
&lt;p&gt;Now we know how to call JS from rust and Rust from JS. 
The problem - functions are very limited in available types. Only f32&#x2F;f64, i8&#x2F;u8, i32&#x2F;u32 (and not i64&#x2F;u64) and pointers are available.
Surprisingly, usually it is enough - for games there are not many FFI functions and rolling your own buffer converter from wasm memory to JS memory is good enough.
But there is &lt;code&gt;sapp-jsutils&lt;&#x2F;code&gt; plugin available that can help with working with strings or even arbitrary JS objects. &lt;&#x2F;p&gt;
&lt;p&gt;With &lt;code&gt;sapp-utils&lt;&#x2F;code&gt; rust code may look like this: &lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#ffffff;color:#323232;&quot;&gt;&lt;code&gt;&lt;span&gt;#[no_mangle]
&lt;&#x2F;span&gt;&lt;span&gt;pub extern &amp;quot;C&amp;quot; fn hi_rust(js_object: JsObject) {
&lt;&#x2F;span&gt;&lt;span&gt;    let mut message = String::new();
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    js_object.to_string(&amp;amp;mut message);
&lt;&#x2F;span&gt;&lt;span&gt;    miniquad::debug!(&amp;quot;{}&amp;quot;, message);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For more info check &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;not-fl3&#x2F;miniquad-js-interop-demo.git&quot;&gt;demo project&lt;&#x2F;a&gt;. This example showcase usage of strings, arrays and structs bi-directional usage - complex types are used in both argument and return positions for both JS and Rust calls.&lt;&#x2F;p&gt;
&lt;p&gt;Note that &lt;code&gt;sapp-utils&lt;&#x2F;code&gt; are completely optional and just one of the options to help with JS-Rust interops. I believe there are way better and efficient ways to do this, depending on the task and requirements. I hope case-specific crates like &lt;code&gt;sapp-utils&lt;&#x2F;code&gt; will appear to make JS interop easier!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Cross-platform logs</title>
        <published>2020-04-01T09:19:42+00:00</published>
        <updated>2020-04-01T09:19:42+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://macroquad.rs/articles/logs/" type="text/html"/>
        <id>https://macroquad.rs/articles/logs/</id>
        
        <content type="html">&lt;h1 id=&quot;cross-platform-logs-with-miniquad&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#cross-platform-logs-with-miniquad&quot; aria-label=&quot;Anchor link for: cross-platform-logs-with-miniquad&quot;&gt;🔗&lt;&#x2F;a&gt;Cross-platform logs with miniquad&lt;&#x2F;h1&gt;
&lt;p&gt;Miniquad is cross-platform layer between rust code and target platforms rendering API. Console API necessary for logs are some kind of output API and its on miniquads responsibility to abstract it away. On the other hand, using log-rs with different frontends are the most common way to do logging in rust ecosystem.&lt;&#x2F;p&gt;
&lt;p&gt;So there are two different ways to send log messages into console with miniquad:&lt;&#x2F;p&gt;
&lt;h2 id=&quot;with-log-rs&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#with-log-rs&quot; aria-label=&quot;Anchor link for: with-log-rs&quot;&gt;🔗&lt;&#x2F;a&gt;With log-rs&lt;&#x2F;h2&gt;
&lt;p&gt;Use debug!, warn!, trace!, info! macros from log-rs just like with any other library. The only issue - special logging frontend for wasm will be needed. Fortunately, there is one: sapp-console-log.&lt;&#x2F;p&gt;
&lt;p&gt;dependencies to Cargo.toml:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span&gt;[dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;log &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.4&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;[target.wasm32-unknown-unknown.dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;sapp-console-log &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.1&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;[target.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;#39;cfg(not(target_arch = &amp;quot;wasm32&amp;quot;)&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;.dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;env_logger &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.7&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;# any other log-rs frontend will work fine as well
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;initialization in main.rs:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    #[cfg(target_arch &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;wasm32&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)]
&lt;&#x2F;span&gt;&lt;span&gt;    sapp_console_log::init().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#62a35c;&quot;&gt;unwrap&lt;&#x2F;span&gt;&lt;span&gt;();
&lt;&#x2F;span&gt;&lt;span&gt;    #[cfg(not(target_arch &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;wasm32&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;))]
&lt;&#x2F;span&gt;&lt;span&gt;    env_logger::init();
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span&gt;    info!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Logging is initialized!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;); &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; this will be `console.info` on web or handled and filtred by env_logger into stderr
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;with-embedded-logging-implementation&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#with-embedded-logging-implementation&quot; aria-label=&quot;Anchor link for: with-embedded-logging-implementation&quot;&gt;🔗&lt;&#x2F;a&gt;With embedded logging implementation&lt;&#x2F;h2&gt;
&lt;p&gt;If the main target platform is wasm - there are not much of a choice, just sapp_console_log. miniquad can provide its own logging macros, very similar to log-rs ones. Each logging call will be redirected into appropriate console.*() call on wasm and just into eprintln!() on desktop.&lt;&#x2F;p&gt;
&lt;p&gt;To use this, enable miniquad &amp;quot;log-impl&amp;quot; feature in Cargo.toml:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;toml&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-toml &quot;&gt;&lt;code class=&quot;language-toml&quot; data-lang=&quot;toml&quot;&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;#[dependencies]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;miniquad &lt;&#x2F;span&gt;&lt;span&gt;= { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;version &lt;&#x2F;span&gt;&lt;span&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;0.2&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#63a35c;&quot;&gt;features &lt;&#x2F;span&gt;&lt;span&gt;= [ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;log-impl&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;]}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And then all logging macros will be available just from miniquad:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;rust&quot; style=&quot;background-color:#ffffff;color:#323232;&quot; class=&quot;language-rust &quot;&gt;&lt;code class=&quot;language-rust&quot; data-lang=&quot;rust&quot;&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;use &lt;&#x2F;span&gt;&lt;span&gt;miniquad::info;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#a71d5d;&quot;&gt;fn &lt;&#x2F;span&gt;&lt;span style=&quot;font-weight:bold;color:#795da3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    info!(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#183691;&quot;&gt;&amp;quot;Logging is available!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;); &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#969896;&quot;&gt;&#x2F;&#x2F; this will be `console.info` on web and `eprintln!` on desktop
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
</feed>
