examples: revert to 0.4 entrypoint / control API design

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-08-24 17:05:21 -07:00 committed by Stephen Gutekanst
parent a54d20daa2
commit 80be6b7bca
20 changed files with 105 additions and 56 deletions

View file

@ -18,6 +18,7 @@ const sysaudio = mach.sysaudio;
pub const App = @This();
// TODO: banish global allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
pub const name = .app;
@ -27,7 +28,7 @@ pub const systems = .{
.init = .{ .handler = init },
.after_init = .{ .handler = afterInit },
.deinit = .{ .handler = deinit },
.update = .{ .handler = update },
.tick = .{ .handler = tick },
.audio_state_change = .{ .handler = audioStateChange },
};
@ -37,7 +38,8 @@ 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 {
core.schedule(.init);
audio.schedule(.init);
app.schedule(.after_init);
@ -49,6 +51,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.schedule(.start);
}
fn afterInit(audio: *mach.Audio.Mod, app: *Mod) void {
@ -57,8 +61,9 @@ fn afterInit(audio: *mach.Audio.Mod, app: *Mod) void {
audio.state().on_state_change = app.system(.audio_state_change);
}
fn deinit(audio: *mach.Audio.Mod) void {
fn deinit(core: *mach.Core.Mod, audio: *mach.Audio.Mod) void {
audio.schedule(.deinit);
core.schedule(.deinit);
}
fn audioStateChange(
@ -90,7 +95,7 @@ fn audioStateChange(
}
}
fn update(
fn tick(
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
audio: *mach.Audio.Mod,