High-level wrapper around Flecs, a powerful ECS (Entity Component System) library, written in Zig language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

# flecs-zig-ble
.. is a [Zig] wrapper around [Flecs], the powerful and fast Entity Component System library. It provides higher-level abstractions around Flecs' primitives and uses Zig's meta-programming functionality for more easily readable and maintainable code.
This library is still very much work-in-progress and not ready for use. It's available for people to have a look, give feedback and take inspirations. I'm attempting to develop this project using a test-driven development approach, translating Flecs' C tests (and later, examples) to Zig, creating wrapper types and functions as I go.
[Zig]: https://ziglang.org/
[Flecs]: https://github.com/SanderMertens/flecs
## Example
```zig
const std = @import("std");
const flecs = @import("flecs-zig-ble");
const Context = flecs.Context(void);
const World = Context.World;
const Iter = Context.Iter;
const Position = struct { x: f32, y: f32 };
const Velocity = struct { x: f32, y: f32 };
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
flecs.init(gpa.allocator());
const world = try World.init();
defer world.deinit();
_ = try world.component(Position);
_ = try world.component(Velocity);
_ = try world.system("Move", move, flecs.c.EcsOnUpdate, "Position, Velocity");
const e = world.entity();
e.set(Position, .{ .x = 10, .y = 20 });
e.set(Velocity, .{ .x = 1, .y = 2 });
while (world.progress(0.0)) { }
}
fn move(it: Iter) void {
const pos_field = it.field(Position, 1);
const vel_field = it.field(Velocity, 2);
for (pos_field, vel_field) |*p, v| {
p.x += v.x;
p.y += v.y;
}
}
```