### Declare Component Structs Source: https://github.com/prime31/zig-ecs/blob/master/README.md Defines example component structures, Velocity and Position, which will be used with the ECS. ```zig pub const Velocity = struct { x: f32, y: f32 }; pub const Position = struct { x: f32, y: f32 }; ``` -------------------------------- ### Create Entities and Add Components Source: https://github.com/prime31/zig-ecs/blob/master/README.md Demonstrates creating entities and adding Position and Velocity components to them. ```zig const entity = reg.create(); reg.add(entity, Position{ .x = 0, .y = 0 }); reg.add(entity, Velocity{ .x = 5, .y = 7 }); ``` -------------------------------- ### Initialize ECS Registry Source: https://github.com/prime31/zig-ecs/blob/master/README.md Initializes the ECS Registry, which manages entity data and query execution. ```zig var reg = ecs.Registry.init(std.testing.allocator); ``` -------------------------------- ### Iterate Entities with a View Source: https://github.com/prime31/zig-ecs/blob/master/README.md Shows how to create and iterate a View that matches entities with both Velocity and Position components, accessing components mutably and immutably. ```zig var view = reg.view(.{ Velocity, Position }, .{}); var iter = view.entityIterator(); while (iter.next()) |entity| { const pos = view.getConst(Position, entity); // readonly copy var vel = view.get(Velocity, entity); // mutable } ``` -------------------------------- ### Iterate Entities with an Owning Group Source: https://github.com/prime31/zig-ecs/blob/master/README.md Demonstrates using an owning Group to iterate over entities and update their components using a callback function. ```zig var group = reg.group(.{ Velocity, Position }, .{}, .{}); group.each(each); fn each(e: struct { vel: *Velocity, pos: *Position }) void { e.pos.*.x += e.vel.x; e.pos.*.y += e.vel.y; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.