<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Armais (Astro Arcade)</title>
    <description>The latest articles on DEV Community by Armais (Astro Arcade) (@astroarcade).</description>
    <link>https://dev.to/astroarcade</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4276450%2Fd8ad6db1-0e96-4166-b515-0af071ea2824.png</url>
      <title>DEV Community: Armais (Astro Arcade)</title>
      <link>https://dev.to/astroarcade</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/astroarcade"/>
    <language>en</language>
    <item>
      <title>What broke determinism in our lockstep party game (and how we catch it now)</title>
      <dc:creator>Armais (Astro Arcade)</dc:creator>
      <pubDate>Wed, 02 Dec 2026 14:00:28 +0000</pubDate>
      <link>https://dev.to/astroarcade/what-broke-determinism-in-our-lockstep-party-game-and-how-we-catch-it-now-2fd0</link>
      <guid>https://dev.to/astroarcade/what-broke-determinism-in-our-lockstep-party-game-and-how-we-catch-it-now-2fd0</guid>
      <description>&lt;p&gt;My friend Alfonso and I make Orbit Rivals, a party board game for up to 4 players with 100 minigames. It runs on our own C++17 engine on SDL3, with one renderer for OpenGL 3.3, GLES 3.0 and WebGL2, so the same code ships on Windows, Linux, macOS, Android and the web.&lt;/p&gt;

&lt;p&gt;Online play is lockstep, and this post is about what that cost us.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;The server doesn't simulate anything. Each room has a 60 Hz clock. Every tick it takes the latest input from each seat, packs them into one frame and sends that same frame to everyone. Every client, the host included, steps the game with those frames in order.&lt;/p&gt;

&lt;p&gt;Your own input makes the round trip too. It sounds wasteful, but there's only one way into the game state and it's the same for everybody. The analog stick is quantized even offline, so local and online play feel the same.&lt;/p&gt;

&lt;p&gt;Nobody waits for anybody: a slow client doesn't stop the clock, its inputs just arrive later.&lt;/p&gt;

&lt;p&gt;All of this only works if every machine computes exactly the same thing from the same frames. Bit for bit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What broke it
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;libm.&lt;/strong&gt; sin, cos, atan2, exp and pow don't return the same bits on glibc, MSVC, musl (our web build), bionic (Android) and Apple. The game logic doesn't call any of them. It has its own small math header, and rendering can use whatever it likes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Evaluation order.&lt;/strong&gt; We had lines with two RNG calls in the same expression. C++ doesn't fix the order of operands, and GCC and Clang pick differently. Two minigames desynced between builds. The rule now is one RNG call per statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FMA.&lt;/strong&gt; On ARM64, GCC and Clang fuse &lt;code&gt;a*b+c&lt;/code&gt; into a fused multiply-add, which rounds differently. &lt;code&gt;-ffp-contract=off&lt;/code&gt; for the whole thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sorting with ties.&lt;/strong&gt; &lt;code&gt;std::sort&lt;/code&gt; doesn't promise an order for equal elements, and the standard libraries don't agree. We use &lt;code&gt;stable_sort&lt;/code&gt; or break ties by hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hashing memory.&lt;/strong&gt; It's tempting to hash structs as raw bytes, but padding is garbage. Our state hash goes field by field, and any new state has to be added to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we catch it
&lt;/h2&gt;

&lt;p&gt;At startup each build plays a short simulated match with synthetic players, a chunk per frame so nobody notices, and gets a fingerprint. It goes in the hello message, and if it doesn't match the host's, the server won't let that client in. A version mismatch or a platform that computes differently shows up before the match, not in the middle of it.&lt;/p&gt;

&lt;p&gt;For development there's &lt;code&gt;--dethash N&lt;/code&gt;: it simulates N online matches with lag and players dropping and coming back, and prints hashes we diff between compilers and platforms. Every change to the game logic runs it before a commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lag in timing minigames
&lt;/h2&gt;

&lt;p&gt;Some minigames are all about timing. With lockstep, your press reaches the game a round trip after what you saw. So the client sends the tick it had on screen when you pressed, and those minigames judge the press at t − lag, capped at 0.25 s. The server bounds that tick by what the client could really have had on screen, so faking an older one doesn't buy time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Was it worth it
&lt;/h2&gt;

&lt;p&gt;For a party game, yes. Only inputs travel, so bandwidth is tiny, reconnecting is replaying frames from the server's log, and the web build and the Android app play in the same rooms. The price is discipline: any line of game logic can break sync, and you only find out when two machines disagree.&lt;/p&gt;

&lt;p&gt;If you want to see it running, the game is free in the browser (&lt;a href="https://armaisdiaz.itch.io/orbitrivals" rel="noopener noreferrer"&gt;https://armaisdiaz.itch.io/orbitrivals&lt;/a&gt;) and on Google Play (&lt;a href="https://play.google.com/store/apps/details?id=com.astroarcade.orbitrivals&amp;amp;utm_source=devto&amp;amp;utm_medium=articulo&amp;amp;utm_campaign=lockstep" rel="noopener noreferrer"&gt;https://play.google.com/store/apps/details?id=com.astroarcade.orbitrivals&amp;amp;utm_source=devto&amp;amp;utm_medium=articulo&amp;amp;utm_campaign=lockstep&lt;/a&gt;). Questions about the netcode are welcome in the comments.&lt;/p&gt;

&lt;p&gt;By gamers, for gamers.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>cpp</category>
      <category>networking</category>
      <category>sdl</category>
    </item>
  </channel>
</rss>
