ecs: replace world.tick() with generic world.send(.tick) message passing
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
a1eda25ec2
commit
2879ad58b0
3 changed files with 5 additions and 5 deletions
|
|
@ -83,5 +83,5 @@ test "example" {
|
|||
try world.entities.setComponent(player2, .physics, .id, 1234);
|
||||
try world.entities.setComponent(player3, .physics, .id, 1234);
|
||||
|
||||
world.tick();
|
||||
world.send(.tick);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,13 +268,13 @@ pub fn World(comptime modules: anytype) type {
|
|||
) = value;
|
||||
}
|
||||
|
||||
/// Tick sends the global 'tick' message to all modules that are subscribed to it.
|
||||
pub fn tick(world: *Self) void {
|
||||
/// Broadcasts a global message to all modules that are subscribed to it.
|
||||
pub fn send(world: *Self, comptime msg_tag: anytype) void {
|
||||
_ = world;
|
||||
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, "tick")) module.update(.tick);
|
||||
if (@hasField(module.messages, @tagName(msg_tag))) module.update(msg_tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue