ecs: remove Module.update in favor of "one method per message" handler pattern
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
fcf9943d0f
commit
5c1414efb5
1 changed files with 3 additions and 2 deletions
|
|
@ -267,8 +267,9 @@ pub fn World(comptime modules: anytype) type {
|
||||||
pub fn send(world: *Self, comptime msg_tag: anytype) !void {
|
pub fn send(world: *Self, comptime msg_tag: anytype) !void {
|
||||||
inline for (std.meta.fields(@TypeOf(modules))) |module_field| {
|
inline for (std.meta.fields(@TypeOf(modules))) |module_field| {
|
||||||
const module = @field(modules, module_field.name);
|
const module = @field(modules, module_field.name);
|
||||||
if (@hasDecl(module, "Message")) {
|
if (@hasDecl(module, @tagName(msg_tag))) {
|
||||||
if (@hasField(module.Message, @tagName(msg_tag))) try module.update(world, msg_tag);
|
const handler = @field(module, @tagName(msg_tag));
|
||||||
|
try handler(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue