ecs: update tests
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
b1d8c2a009
commit
df263685ab
2 changed files with 41 additions and 26 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue