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.
copygirl 248f0af204 Rename Iter.count and .deltaTime 7 months ago
libs Update Zig and Flecs, big refactor 7 months ago
src Rename Iter.count and .deltaTime 7 months ago
.editorconfig Initial commit 1 year ago
.gitignore Initial commit 1 year ago
.gitmodules Re-add Flecs as a submodule, v3.2.5 1 year ago
README.md Update Zig and Flecs, big refactor 7 months ago
UNLICENSE.txt Initial commit 1 year ago
build.zig Update Zig and Flecs, big refactor 7 months ago
build.zig.zon Update Zig and Flecs, big refactor 7 months ago

README.md

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.

Example

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;
    }
}