Urgent.News

What's breaking now, across thousands of outlets.

Tech

Fast simulation code is slow to write, so generators write it

I want to talk about code generators, domain specific languages (DSL), and simulating interactions. Me personally, I am a fan of games like Dwarf Fortress, Age of Empires and Might and Magic, and Role Playing Games in the broader sense. Now, no matter how you look at them, they all boil down to having a "state" (like a chess board), some "actors" (the little ants you interact with), and "the…

Fast simulation code can be time-consuming to write, leading some developers to create generators that automatically generate the code. Games like Dwarf Fortress, Age of Empires and Might and Magic, as well as Role Playing Games, share a common structure of having a state, actors, and rules governing their interactions. The author of the story experimented with cache optimized Go data structures, encoding them as annotations to generate code.

This approach led to the development of Ecclesia, an isometric pilgrimage through a world of countries drawn as Orthodox icons. Ecclesia is written as annotations on Go structs, with seven code generators working together to produce cache-friendly memory pools, behavior, the world, drawings, network frames, screens, and rules. The simulation runs on one thread at 0.21 ms per tick on an Intel i7-9750H, achieving around 8,192 classic Reynolds boids in 1 CPU at 60 FPS without using any goroutines.

The author's goal was to encode optimal cache data structures into metaprogramming generators, enabling Claude to write a high-level DSL and generate code down to the level of simulations. To achieve this, the author stacked three levels of generators on top of each other, starting from a basic generator that converts raw structs to SoA, wire codecs, and bitfields, followed by a generator for relations between entities, and finally a generator for game design and schema behavior.

Each generator reads its own annotations and writes Go code that the level above calls. The final output is a running world that can be visualized from various perspectives, including an isometric view and first-person view. The simulation runs on one core, with networking, disk I/O, and screen painting handled by separate cores.

The author sees potential in using this approach for MMORPGs, allowing players to create their own fantasy games by interacting with shared gamestate and rules.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Giving an AI Assistant Access to Your Accounts: What to Check

The most useful AI assistants are the ones connected to your real tools, because they can see the invoice, the calendar entry and the customer thread instead of asking you to paste them in.

  • AI assistants with tool access pose significant risk
  • Read access risks privacy, write access risks operations & finances
  • Start with read-only access, human approve write actions

More from Sunday 1 November →