Core: use an explicit .start event sent by app to begin .tick events

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-29 18:25:57 -07:00 committed by Stephen Gutekanst
parent 8089d3356e
commit 15fd2c3a64
8 changed files with 67 additions and 25 deletions

View file

@ -58,6 +58,8 @@ fn init(game: *Mod, core: *mach.Core.Mod) !void {
.pipeline = pipeline,
});
try updateWindowTitle(core);
core.send(.start, .{});
}
// TODO(important): remove need for returning an error here

View file

@ -74,6 +74,8 @@ fn init(
.spawn_timer = try mach.Timer.start(),
.player = player,
});
core.send(.start, .{});
}
// TODO(important): remove need for returning an error here

View file

@ -46,7 +46,7 @@ fn deinit(core: *mach.Core.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs
core.send(.deinit, .{});
}
fn init(sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod, game: *Mod) !void {
fn init(core: *mach.Core.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod, game: *Mod) !void {
sprite_pipeline.send(.init, .{});
glyphs.send(.init, .{});
@ -55,6 +55,8 @@ fn init(sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod, game: *Mo
// Run our init code after glyphs module is initialized.
game.send(.after_init, .{});
core.send(.start, .{});
}
fn afterInit(

View file

@ -36,7 +36,7 @@ pub const components = .{
ghost_key_mode: bool = false,
fn init(audio: *mach.Audio.Mod, app: *Mod) void {
fn init(core: *mach.Core.Mod, audio: *mach.Audio.Mod, app: *Mod) void {
// Initialize audio module, telling it to send our module's .audio_state_change event when an
// entity's sound stops playing
audio.send(.init, .{app.event(.audio_state_change)});
@ -49,6 +49,8 @@ fn init(audio: *mach.Audio.Mod, app: *Mod) void {
std.debug.print("[spacebar] enable ghost-key mode (demonstrate seamless back-to-back sound playback)\n", .{});
std.debug.print("[arrow up] increase volume 10%\n", .{});
std.debug.print("[arrow down] decrease volume 10%\n", .{});
core.send(.start, .{});
}
fn deinit(core: *mach.Core.Mod, audio: *mach.Audio.Mod) void {

View file

@ -89,6 +89,8 @@ fn init(
.allocator = allocator,
.pipeline = pipeline,
});
core.send(.start, .{});
}
fn tick(

View file

@ -127,6 +127,8 @@ fn init(
.allocator = allocator,
.pipeline = pipeline,
});
core.send(.start, .{});
}
fn tick(