ecs: update tests

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-03-26 20:55:32 -07:00 committed by Stephen Gutekanst
parent b1d8c2a009
commit df263685ab
2 changed files with 41 additions and 26 deletions

View file

@ -7,6 +7,7 @@ const query_mod = @import("query.zig");
const Archetype = @import("Archetype.zig"); const Archetype = @import("Archetype.zig");
const StringTable = @import("StringTable.zig"); const StringTable = @import("StringTable.zig");
const comp = @import("comptime.zig"); const comp = @import("comptime.zig");
const NamespacedComponents = @import("../module.zig").NamespacedComponents;
/// An entity ID uniquely identifies an entity globally within an Entities set. /// An entity ID uniquely identifies an entity globally within an Entities set.
pub const EntityID = u64; pub const EntityID = u64;
@ -749,16 +750,17 @@ test "example" {
const Rotation = struct { degrees: f32 }; const Rotation = struct { degrees: f32 };
const all_components = .{ const all_components = NamespacedComponents(.{
.entity = struct { struct {
pub const id = EntityID; pub const name = .game;
}, pub const events = .{};
.game = struct { pub const components = .{
pub const location = Location; .{ .name = .name, .type = []const u8 },
pub const name = []const u8; .{ .name = .location, .type = Location },
pub const rotation = Rotation; .{ .name = .rotation, .type = Rotation },
},
}; };
},
}){};
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Create a world. // Create a world.
@ -853,16 +855,17 @@ test "many entities" {
const Rotation = struct { degrees: f32 }; const Rotation = struct { degrees: f32 };
const all_components = .{ const all_components = NamespacedComponents(.{
.entity = struct { struct {
pub const id = EntityID; pub const name = .game;
}, pub const events = .{};
.game = struct { pub const components = .{
pub const location = Location; .{ .name = .name, .type = []const u8 },
pub const name = []const u8; .{ .name = .location, .type = Location },
pub const rotation = Rotation; .{ .name = .rotation, .type = Rotation },
},
}; };
},
}){};
// Create many entities // Create many entities
var world = try Entities(all_components).init(allocator); var world = try Entities(all_components).init(allocator);

View file

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const testing = std.testing; const testing = std.testing;
const NamespacedComponents = @import("../module.zig").NamespacedComponents;
pub const QueryTag = enum { pub const QueryTag = enum {
any, any,
@ -69,16 +70,27 @@ test "query" {
const Rotation = struct { degrees: f32 }; const Rotation = struct { degrees: f32 };
const all_components = .{ const all_components = NamespacedComponents(.{
.game = struct { struct {
pub const name = []const u8; pub const name = .game;
}, pub const events = .{};
.physics = struct { pub const components = .{
pub const location = Location; .{ .name = .name, .type = []const u8 },
pub const rotation = Rotation;
},
.renderer = struct {},
}; };
},
struct {
pub const name = .physics;
pub const events = .{};
pub const components = .{
.{ .name = .location, .type = Location },
.{ .name = .rotation, .type = Rotation },
};
},
struct {
pub const name = .renderer;
pub const events = .{};
},
}){};
const Q = Query(all_components); const Q = Query(all_components);