ecs: simplify how modules are written
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
85ffb37156
commit
4575080ca9
2 changed files with 64 additions and 80 deletions
|
|
@ -21,7 +21,6 @@ pub const Modules = @import("systems.zig").Modules;
|
|||
pub const Messages = @import("systems.zig").Messages;
|
||||
pub const MessagesTag = @import("systems.zig").MessagesTag;
|
||||
pub const World = @import("systems.zig").World;
|
||||
pub const View = @import("systems.zig").View;
|
||||
|
||||
// TODO:
|
||||
// * Iteration
|
||||
|
|
@ -37,33 +36,34 @@ test "inclusion" {
|
|||
test "example" {
|
||||
const allocator = testing.allocator;
|
||||
|
||||
const PhysicsMsg = Messages(.{
|
||||
.tick = void,
|
||||
});
|
||||
const physicsUpdate = (struct {
|
||||
pub fn physicsUpdate(msg: PhysicsMsg) void {
|
||||
const Physics2D = Module(struct {
|
||||
pointer: u8,
|
||||
|
||||
pub const name = .physics;
|
||||
pub const components = .{
|
||||
.id = u32,
|
||||
};
|
||||
pub const Message = .{
|
||||
.tick = void,
|
||||
};
|
||||
|
||||
pub fn update(msg: Message) void {
|
||||
switch (msg) {
|
||||
.tick => std.debug.print("\nphysics tick!\n", .{}),
|
||||
}
|
||||
}
|
||||
}).physicsUpdate;
|
||||
});
|
||||
|
||||
const Renderer = Module(struct {
|
||||
pub const name = .renderer;
|
||||
pub const components = .{
|
||||
.id = u16,
|
||||
};
|
||||
});
|
||||
|
||||
const modules = Modules(.{
|
||||
.physics = Module(.{
|
||||
.components = .{
|
||||
.id = u32,
|
||||
},
|
||||
.globals = struct {
|
||||
pointer: u8,
|
||||
},
|
||||
.messages = PhysicsMsg,
|
||||
.update = physicsUpdate,
|
||||
}),
|
||||
.renderer = Module(.{
|
||||
.components = .{
|
||||
.id = u16,
|
||||
},
|
||||
}),
|
||||
Physics2D,
|
||||
Renderer,
|
||||
});
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue