{mach,ecs}: pass World to ECS event handlers
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
15e6f81df8
commit
f153133c30
3 changed files with 6 additions and 6 deletions
|
|
@ -21,6 +21,7 @@ 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
|
||||
|
|
@ -83,5 +84,5 @@ test "example" {
|
|||
try world.entities.setComponent(player2, .physics, .id, 1234);
|
||||
try world.entities.setComponent(player3, .physics, .id, 1234);
|
||||
|
||||
world.send(.tick);
|
||||
try world.send(.tick);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,12 +269,11 @@ pub fn World(comptime modules: anytype) type {
|
|||
}
|
||||
|
||||
/// Broadcasts a global message to all modules that are subscribed to it.
|
||||
pub fn send(world: *Self, comptime msg_tag: anytype) void {
|
||||
_ = world;
|
||||
pub fn send(world: *Self, comptime msg_tag: anytype) !void {
|
||||
inline for (std.meta.fields(@TypeOf(modules))) |module_field| {
|
||||
const module = @field(modules, module_field.name);
|
||||
if (@hasField(@TypeOf(module), "messages")) {
|
||||
if (@hasField(module.messages, @tagName(msg_tag))) module.update(msg_tag);
|
||||
if (@hasField(module.messages, @tagName(msg_tag))) try module.update(world, msg_tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub fn App(comptime modules: anytype) type {
|
|||
};
|
||||
app.engine.set(.mach, .core, &app.core);
|
||||
app.engine.set(.mach, .device, app.core.device());
|
||||
app.engine.send(.init);
|
||||
try app.engine.send(.init);
|
||||
}
|
||||
|
||||
pub fn deinit(app: *@This()) void {
|
||||
|
|
@ -44,7 +44,7 @@ pub fn App(comptime modules: anytype) type {
|
|||
}
|
||||
|
||||
pub fn update(app: *@This()) !bool {
|
||||
app.engine.send(.tick);
|
||||
try app.engine.send(.tick);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue