Knödel-ECS - Bevy's API in Zig

Knödel-ECS - Bevy’s API in Zig

Knoedel on GitHub

Today I want to present my pet project ‘Knödel’, which is another ECS abstraction.

I have been working for about 4 years with the popular rust ECS bevy, before discovering my passion for Zig. I wanted something similar in Zig, especially the scheduler, access patterns and auto concurrency. And that is, what I did.

For the last year, this has been become the foundation of my game engine, and it is at the state, where I feel confident enough to share it with the community.

  • Bevy’s plugin and systems API in Zig
  • Lock free auto concurrency
  • Queries, resources and system locals
  • Component hooks and Bevy’s ‘Required Component’ equivalent
  • Event and State extension
  • Archetype based storage
  • Relations/Hierarchy
  • Manual control
  • Can run inside a dylib (re-add plugins after reload)
  • A user defined scene codec interface for export/import

The first light test of my engine was a mini space survivor you can play in the browser:
Play space survivor game
(Uses an old version of the ECS)

For anybody interested: Sokol is used as platform layer.

Today I am working on an isometric colony sim / tycoon hybrid. Here are some of the debug API capabilities: A view, showing all schedules and system, color coded on what runs in parallel and how long it takes on average.

The lowest level API is type erased and allows for runtime manipulation. This is great for external tooling and bindings. For example, I also have a detailed debugging web interface, which gives me searchable live view into the running world with live component data.

Zig version

0.16.0

LLM disclosure

Knödel’s code is handwritten. LLMs are used for analyses and read-only purposes.

11 Likes

This is super cool! Out of curiosity, what aspects of zig make it preferable to you with respect to rust for this ECS game development type work?

The most compelling reason for me is the raw compile speed and the C interactions. For the first time I have a massive project, of which I own 100% of the code. There is no external dependencies. Everything compiles in 0.5s. The structure follows my design, everything is optimized for hot reloading and dynamic libraries. Making the game, feels like a game. Of course, you can achieve the same in rust and bevy. I just got curious, wanting to learn something new, and now I am stuck.

Cool to hear your perspective! I too am stuck on zig, keen to try rust but often “wish it were zig” within a few hundred lines or so. Also a skill issue on my part.

I also enjoyed your “Read-Only” LLM policy. Sometimes I cave and copy paste LLM code during a multi-hour zig session, always end up regretting how it affects the intentionality within and my understanding of the codebase! I will try this in my next project.