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 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 = .{};
|
||||||
|
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.
|
// 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 = .{};
|
||||||
|
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
|
// Create many entities
|
||||||
var world = try Entities(all_components).init(allocator);
|
var world = try Entities(all_components).init(allocator);
|
||||||
|
|
|
||||||
|
|
@ -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 = .{};
|
||||||
|
pub const components = .{
|
||||||
|
.{ .name = .name, .type = []const u8 },
|
||||||
|
};
|
||||||
},
|
},
|
||||||
.physics = struct {
|
struct {
|
||||||
pub const location = Location;
|
pub const name = .physics;
|
||||||
pub const rotation = Rotation;
|
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);
|
const Q = Query(all_components);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue