https://github.com/Avokadoen/ecez
An ECS API for Zig!
https://github.com/Avokadoen/ecez
data-oriented-programming ecs zig
Last synced: 10 months ago
JSON representation
An ECS API for Zig!
- Host: GitHub
- URL: https://github.com/Avokadoen/ecez
- Owner: Avokadoen
- License: mit
- Created: 2022-07-04T11:19:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-29T17:57:49.000Z (10 months ago)
- Last Synced: 2025-05-03T21:30:03.115Z (10 months ago)
- Topics: data-oriented-programming, ecs, zig
- Language: Zig
- Homepage:
- Size: 1.53 MB
- Stars: 31
- Watchers: 1
- Forks: 2
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - Avokadoen/ecez - An archetype based ECS library written in pure Zig. (Multimedia & Graphics / Game Development)
README

# ECEZ - An ECS API
This is a ECS (Entity Component System) API for Zig.
## Try it yourself!
### Requirements
The [zig compiler 0.14.0](https://ziglang.org)
You can use zigup to easily get this specific version
### Steps
Run the following commands
```bash
# Clone the repo
git clone https://github.com/Avokadoen/ecez.git
# Run tests
zig build test
# Run GOL example, use '-Denable-tracy=true' at the end to add tracy functionality
zig build run-game-of-life
```
You should also checkout [src/root.zig](https://github.com/Avokadoen/ecez/blob/main/src/root.zig) which has the public API. From there you can follow the deifinition to get more details.
### Include ecez and optionally tracy in your project
Add ecez to build.zig.zon, example in terminal:
```
zig fetch --save git+https://github.com/Avokadoen/ecez.git/#HEAD
```
#### Basic ecez build
build.zig
```zig
const ecez = b.dependency("ecez", .{});
const ecez_module = ecez.module("ecez");
exe.addImport("ecez", ecez_module);
```
#### Using ztracy with ecez:
build.zig:
```zig
const options = .{
.enable_ztracy = b.option(
bool,
"enable_ztracy",
"Enable Tracy profile markers",
) orelse false,
.enable_fibers = b.option(
bool,
"enable_fibers",
"Enable Tracy fiber support",
) orelse false,
.on_demand = b.option(
bool,
"on_demand",
"Build tracy with TRACY_ON_DEMAND",
) orelse false,
};
// link ecez and ztracy
{
const ecez = b.dependency("ecez", .{
.enable_ztracy = options.enable_ztracy,
.enable_fibers = options.enable_fibers,
.on_demand = options.on_demand,
});
const ecez_module = ecez.module("ecez");
exe.root_module.addImport("ecez", ecez_module);
exe_unit_tests.root_module.addImport("ecez", ecez_module);
const ztracy_dep = ecez.builder.dependency("ztracy", .{
.enable_ztracy = options.enable_ztracy,
.enable_fibers = options.enable_fibers,
.on_demand = options.on_demand,
});
const ztracy_module = ztracy_dep.module("root");
exe.root_module.addImport("ztracy", ztracy_module);
exe_unit_tests.root_module.addImport("ztracy", ztracy_module);
exe.linkLibrary(ztracy_dep.artifact("tracy"));
}
```
## Zig documentation
You can generate the ecez API documentation using `zig build docs`. This will produce some web resources in `zig-out/doc/ecez`.
You will need a local server to serve the documentation since browsers will block resources loaded by the index.html.
The simplest solution to this is just using a basic python server:
```bash
python -m http.server 8000 -d ecez/zig-out/doc/ecez # you can then access the documentation at http://localhost:8000/#ecez.main
```
## Features
### Compile time based and type safe API
Zig's comptime feature is utilized to perform static reflection on the usage of the API to validate usage and report useful messages to the user (in theory :)).
https://github.com/Avokadoen/ecez/blob/7210c43d2dbe6202806acf3e5ac361cbbaed11af/examples/readme/main.zig#L1-L190
### System arguments
Systems can take 3 argument types:
* Queries - Storage queries requesting a certain entity composition. T
* Storage.Subset - A subset of the storage. This is just the normal storage with limitations on which
components can be touched. You can create entities, (un)set components .. etc
* EventArgument - Any non query or subset. Can be useful as a "context" for the event
### Implicit multithreading of systems
When you trigger a system dispatch or an event with multiple systems then ecez will schedule this work over multiple threads.
Synchronization is handled by ecez although there are some caveats that you should be aware of:
* Dont request write access (query result members that are of pointer type) unless you need it.
* Writes has more limitations on what can run in parallel
* Be specific, only request the types you will use.
* EventArgument will not be considered when synchronizing. This means that if you mutate an event argument then you must take some care in order to ensure legal behaviour
### Serialization through the ezby format
ecez uses a custom byte format to convert storages into a slice of bytes.
#### Example
https://github.com/Avokadoen/ecez/blob/7210c43d2dbe6202806acf3e5ac361cbbaed11af/examples/readme/main.zig#L191-L201
### Tracy integration using [ztracy](https://github.com/michal-z/zig-gamedev/tree/main/libs/ztracy)

The codebase has integration with tracy to allow both the library itself, but also applications to profile using a [tracy client](https://github.com/wolfpld/tracy). The extra work done by tracy is of course NOPs in builds without tracy!
### Demo/Examples
Currently the project has two simple examples in the [example folder](https://github.com/Avokadoen/ecez/tree/main/examples):
* Implementation of [conway's game of life](https://github.com/Avokadoen/ecez/blob/main/examples/game-of-life/main.zig) which also integrate tracy
* The code from this [readme](https://github.com/Avokadoen/ecez/blob/main/examples/readme/main.zig)
There is also [wizard rampage](https://github.com/Avokadoen/wizard_rampage) which is closer to actual game code. This was originally a game jam so some of the code is "hacky" but the ecez usage should be a practical example
### Test Driven Development
The codebase also utilize TDD to ensure a certain level of robustness, altough I can assure you that there are many bugs to find yet! ;)
### Planned
Please see the issues for planned features.