Core: use .app local init/deinit/tick events (avoid global events)
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
fb37f74d41
commit
2c8ba82aa3
9 changed files with 41 additions and 48 deletions
27
src/Core.zig
27
src/Core.zig
|
|
@ -10,12 +10,6 @@ pub const name = .mach_core;
|
|||
|
||||
pub const Mod = mach.Mod(@This());
|
||||
|
||||
pub const global_events = .{
|
||||
.init = .{ .handler = fn () void },
|
||||
.deinit = .{ .handler = fn () void },
|
||||
.tick = .{ .handler = fn () void },
|
||||
};
|
||||
|
||||
pub const local_events = .{
|
||||
.update = .{ .handler = update, .description =
|
||||
\\ Send this when window entities have been updated and you want the new values respected.
|
||||
|
|
@ -105,7 +99,7 @@ fn init(core: *Mod) !void {
|
|||
.main_window = main_window,
|
||||
});
|
||||
|
||||
core.sendGlobal(.init, .{});
|
||||
mach.core.mods.send(.app, .init, .{});
|
||||
core.send(.init_done, .{});
|
||||
}
|
||||
|
||||
|
|
@ -153,15 +147,14 @@ fn deinit(core: *Mod) void {
|
|||
}
|
||||
|
||||
_ = gpa.deinit();
|
||||
}
|
||||
|
||||
fn mainThreadTick(core: *Mod) !void {
|
||||
_ = try mach.core.update(null);
|
||||
|
||||
// Send .tick to anyone interested
|
||||
core.sendGlobal(.tick, .{});
|
||||
}
|
||||
|
||||
fn exit(core: *Mod) void {
|
||||
core.state().should_exit = true;
|
||||
}
|
||||
|
||||
fn mainThreadTick() !void {
|
||||
_ = try mach.core.update(null);
|
||||
mach.core.mods.send(.app, .tick, .{});
|
||||
}
|
||||
|
||||
fn exit() void {
|
||||
mach.core.mods.send(.app, .deinit, .{});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ var stack_space: [8 * 1024 * 1024]u8 = undefined;
|
|||
pub fn initModule() !void {
|
||||
// Initialize the global set of Mach modules used in the program.
|
||||
try mods.init(std.heap.c_allocator);
|
||||
mods.mod.mach_core.send(.init, .{});
|
||||
mods.send(.mach_core, .init, .{});
|
||||
|
||||
// Dispatch events until this .mach_core.init_done is sent
|
||||
try mods.dispatch(&stack_space, .{ .until = .{
|
||||
|
|
@ -28,7 +28,7 @@ pub fn initModule() !void {
|
|||
///
|
||||
/// Returns true if tick() should be called again, false if the application should exit.
|
||||
pub fn tick() !bool {
|
||||
mods.mod.mach_core.send(.main_thread_tick, .{});
|
||||
mods.send(.mach_core, .main_thread_tick, .{});
|
||||
|
||||
// Dispatch events until this .mach_core.main_thread_tick_done is sent
|
||||
try mods.dispatch(&stack_space, .{ .until = .{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue