Core: use .app local init/deinit/tick events (avoid global events)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-28 11:45:59 -07:00 committed by Stephen Gutekanst
parent fb37f74d41
commit 2c8ba82aa3
9 changed files with 41 additions and 48 deletions

View file

@ -22,10 +22,10 @@ pub const components = .{
.follower = .{ .type = void },
};
// Global events that we will listen for.
pub const global_events = .{
.init = .{ .handler = init }, // Event sent on app startup
.tick = .{ .handler = tick }, // Event sent on each frame
pub const local_events = .{
.init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.tick = .{ .handler = tick },
};
// Define the globally unique name of our module. You can use any name here, but keep in mind no
@ -38,6 +38,10 @@ pub const name = .app;
// Note that Mod.state() returns an instance of our module struct.
pub const Mod = mach.Mod(@This());
pub fn deinit(core: *mach.Core.Mod) void {
core.send(.deinit, .{});
}
// TODO(important): remove need for returning an error here
fn init(
// These are injected dependencies - as long as these modules were registered in the top-level

View file

@ -27,7 +27,7 @@ pub const components = .{
.scale = .{ .type = f32 },
};
pub const global_events = .{
pub const local_events = .{
.init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.tick = .{ .handler = tick },