This is a ECS (Entity Component System) API for Zig.
You can use zigup to easily get this specific version
Run the following commands
# 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 which has the public API. From there you can follow the deifinition to get more details.
Add ecez to build.zig.zon, example in terminal:
zig fetch --save git+https://github.com/Avokadoen/ecez.git/#HEAD
build.zig
const ecez = b.dependency("ecez", .{});
const ecez_module = ecez.module("ecez");
exe.addImport("ecez", ecez_module);
build.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"));
}
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:
python -m http.server 8000 -d ecez/zig-out/doc/ecez # you can then access the documentation at http://localhost:8000/#ecez.main
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 :)).
Systems can take 3 argument types:
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:
ecez uses a custom byte format to convert storages into a slice of bytes.
The codebase has integration with tracy to allow both the library itself, but also applications to profile using a tracy client. The extra work done by tracy is of course NOPs in builds without tracy!
Currently the project has two simple examples in the example folder:
There is also 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
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! ;)
Please see the issues for planned features.