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 @@
// TODO(important): review all code in this file in-depth
const std = @import("std");
const mach = @import("mach");
const gpu = mach.gpu;
@ -35,17 +34,19 @@ pub const Mod = mach.Mod(@This());
pub const systems = .{
.init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.update = .{ .handler = update },
.tick = .{ .handler = tick },
.after_init = .{ .handler = afterInit },
.end_frame = .{ .handler = endFrame },
};
fn deinit(sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod) !void {
fn deinit(core: *mach.Core.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod) !void {
sprite_pipeline.schedule(.deinit);
glyphs.schedule(.deinit);
core.schedule(.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 {
core.schedule(.init);
sprite_pipeline.schedule(.init);
glyphs.schedule(.init);
@ -62,6 +63,7 @@ fn afterInit(
sprite_pipeline: *gfx.SpritePipeline.Mod,
glyphs: *Glyphs.Mod,
game: *Mod,
core: *mach.Core.Mod,
) !void {
// Create a sprite rendering pipeline
const texture = glyphs.state().texture;
@ -93,9 +95,11 @@ fn afterInit(
.time = 0,
.pipeline = pipeline,
});
core.schedule(.start);
}
fn update(
fn tick(
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
sprite: *gfx.Sprite.Mod,
@ -253,6 +257,7 @@ fn endFrame(game: *Mod, core: *mach.Core.Mod) !void {
"glyphs [ FPS: {d} ] [ Sprites: {d} ]",
.{ game.state().frame_count, game.state().sprites },
);
core.schedule(.update);
game.state().fps_timer.reset();
game.state().frame_count = 0;
}

View file

@ -1,4 +1,3 @@
// TODO(important): review all code in this file in-depth
const mach = @import("mach");
const gpu = mach.gpu;
const ft = @import("freetype");
@ -16,6 +15,7 @@ pub const systems = .{
const RegionMap = std.AutoArrayHashMapUnmanaged(u21, mach.gfx.Atlas.Region);
// TODO: banish global allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
texture_atlas: mach.gfx.Atlas,

View file

@ -1,4 +1,3 @@
const std = @import("std");
const mach = @import("mach");
// The global list of Mach modules registered for use in our application.