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

@ -1,4 +1,3 @@
const std = @import("std");
const mach = @import("mach");
const math = mach.math;
const Renderer = @import("Renderer.zig");
@ -25,7 +24,7 @@ pub const components = .{
pub const systems = .{
.init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.update = .{ .handler = update },
.tick = .{ .handler = tick },
};
// Define the globally unique name of our module. You can use any name here, but keep in mind no
@ -38,8 +37,9 @@ pub const name = .app;
// Note that Mod.state() returns an instance of our module struct.
pub const Mod = mach.Mod(@This());
pub fn deinit(renderer: *Renderer.Mod) void {
pub fn deinit(core: *mach.Core.Mod, renderer: *Renderer.Mod) void {
renderer.schedule(.deinit);
core.schedule(.deinit);
}
fn init(
@ -47,9 +47,11 @@ fn init(
// of the program we can have these types injected here, letting us work with other modules in
// our program seamlessly and with a type-safe API:
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
renderer: *Renderer.Mod,
game: *Mod,
) !void {
core.schedule(.init);
renderer.schedule(.init);
// Create our player entity.
@ -73,16 +75,16 @@ fn init(
.spawn_timer = try mach.Timer.start(),
.player = player,
});
core.schedule(.start);
}
fn update(
fn tick(
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
renderer: *Renderer.Mod,
game: *Mod,
) !void {
// TODO(important): event polling should occur in mach.Core module and get fired as ECS event.
// TODO(Core)
var iter = core.state().pollEvents();
var direction = game.state().direction;
var spawning = game.state().spawning;