From 4ba8addb3cfe9950bc26e00bf9ec72b78506c9b6 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Tue, 16 Apr 2024 20:48:04 -0700 Subject: [PATCH] core: synchronize global .init before first .tick Signed-off-by: Stephen Gutekanst --- src/Core.zig | 2 ++ src/core/main.zig | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/Core.zig b/src/Core.zig index a9e08547..c006e852 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -16,6 +16,7 @@ pub const global_events = .{ pub const local_events = .{ .init = .{ .handler = init }, + .init_done = .{ .handler = fn () void }, // TODO(important): need some way to tie event execution to a specific thread once we have a // multithreaded dispatch implementation @@ -45,6 +46,7 @@ fn init(core: *Mod) !void { }); core.sendGlobal(.init, .{}); + core.send(.init_done, .{}); } fn deinit(core: *Mod) void { diff --git a/src/core/main.zig b/src/core/main.zig index 27fd705a..c94bbc45 100644 --- a/src/core/main.zig +++ b/src/core/main.zig @@ -14,6 +14,12 @@ 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, .{}); + + // Dispatch events until this .mach_core.init_done is sent + try mods.dispatch(.{ .until = .{ + .module_name = mods.moduleNameToID(.mach_core), + .local_event = mods.localEventToID(.mach_core, .init_done), + } }); } /// Tick runs a single step of the main loop on the main OS thread.