diff --git a/src/ecs/entities.zig b/src/ecs/entities.zig index 0fe97d76..a92a8e3d 100644 --- a/src/ecs/entities.zig +++ b/src/ecs/entities.zig @@ -7,6 +7,7 @@ const query_mod = @import("query.zig"); const Archetype = @import("Archetype.zig"); const StringTable = @import("StringTable.zig"); const comp = @import("comptime.zig"); +const NamespacedComponents = @import("../module.zig").NamespacedComponents; /// An entity ID uniquely identifies an entity globally within an Entities set. pub const EntityID = u64; @@ -749,16 +750,17 @@ test "example" { const Rotation = struct { degrees: f32 }; - const all_components = .{ - .entity = struct { - pub const id = EntityID; + const all_components = NamespacedComponents(.{ + struct { + pub const name = .game; + pub const events = .{}; + pub const components = .{ + .{ .name = .name, .type = []const u8 }, + .{ .name = .location, .type = Location }, + .{ .name = .rotation, .type = Rotation }, + }; }, - .game = struct { - pub const location = Location; - pub const name = []const u8; - pub const rotation = Rotation; - }, - }; + }){}; //------------------------------------------------------------------------- // Create a world. @@ -853,16 +855,17 @@ test "many entities" { const Rotation = struct { degrees: f32 }; - const all_components = .{ - .entity = struct { - pub const id = EntityID; + const all_components = NamespacedComponents(.{ + struct { + pub const name = .game; + pub const events = .{}; + pub const components = .{ + .{ .name = .name, .type = []const u8 }, + .{ .name = .location, .type = Location }, + .{ .name = .rotation, .type = Rotation }, + }; }, - .game = struct { - pub const location = Location; - pub const name = []const u8; - pub const rotation = Rotation; - }, - }; + }){}; // Create many entities var world = try Entities(all_components).init(allocator); diff --git a/src/ecs/query.zig b/src/ecs/query.zig index 7c08658d..51ee74d0 100644 --- a/src/ecs/query.zig +++ b/src/ecs/query.zig @@ -1,5 +1,6 @@ const std = @import("std"); const testing = std.testing; +const NamespacedComponents = @import("../module.zig").NamespacedComponents; pub const QueryTag = enum { any, @@ -69,16 +70,27 @@ test "query" { const Rotation = struct { degrees: f32 }; - const all_components = .{ - .game = struct { - pub const name = []const u8; + const all_components = NamespacedComponents(.{ + struct { + pub const name = .game; + pub const events = .{}; + pub const components = .{ + .{ .name = .name, .type = []const u8 }, + }; }, - .physics = struct { - pub const location = Location; - pub const rotation = Rotation; + struct { + pub const name = .physics; + pub const events = .{}; + pub const components = .{ + .{ .name = .location, .type = Location }, + .{ .name = .rotation, .type = Rotation }, + }; }, - .renderer = struct {}, - }; + struct { + pub const name = .renderer; + pub const events = .{}; + }, + }){}; const Q = Query(all_components);