Low cortisol simple Archetype ECS
Find a file
2026-08-03 15:39:11 +01:00
src Improved documentation 2026-08-03 15:39:11 +01:00
.gitignore Hello World! 2026-08-01 21:34:45 +01:00
build.zig Hello World! 2026-08-01 21:34:45 +01:00
build.zig.zon Hello World! 2026-08-01 21:34:45 +01:00
README.md Update README.md 2026-08-01 20:57:35 +00:00

NYXWorld

Low cortisol simple Archetype ECS

Examples

Basic

const Exclude = struct {};
const Zombie = struct {};
const Player = struct { name: []const u8 };
const Vehicle = struct {};
const Transform = struct { pos: @Vector(2, f32) = .{ 0, 0 }, scale: @Vector(2, f32) = .{ 32, 32 } };
const Velocity = struct { value: @Vector(2, f32) = .{ 0, 0 } };

test "basic" {
    // --- WORLD ---
    var world: World = .init(std.testing.allocator);
    defer world.deinit();

    // --- PLAYER ---
    try world.spawn(.{
        Player{ .name = "abux" },
        Transform{},
        Velocity{},
    });

    // --- QUERY ---
    var it = world.query(struct {
        player: ?*const Player,
        zombie: ?*const Zombie,
        vehicle: ?*const Velocity,

        transform: *Transform,
        velocity: *Velocity,
    }, .{
        .without = &.{
            Exclude,
        },
    });

    while (it.next()) |e| {
        // --- MOVE ---
        e.velocity.value[0] += 2;
        e.velocity.value[1] += 4;

        // --- APPLY VELOCITY ---
        e.transform.pos[0] += e.velocity.value[0];
        e.transform.pos[1] += e.velocity.value[1];

        // --- DEBUG PLAYER ---
        if (e.player) |player| {
            std.debug.print(
                \\({f})PLAYER
                \\| Name:     {s}
                \\| Position: {}
                \\| Scale:    {}
                \\
            , .{
                it.entity(),
                player.name,
                e.transform.pos,
                e.transform.scale,
            });
        }
    }
}

Output

(1) PLAYER
| Name:     abux
| Position: { 2, 4 }
| Scale:    { 32, 32 }