{Core,examples}: set window title via component

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-21 22:48:30 -07:00 committed by Stephen Gutekanst
parent 79dccb4d73
commit 68677b3448
5 changed files with 104 additions and 19 deletions

View file

@ -51,9 +51,6 @@ fn init(
sprite_pipeline: *gfx.SpritePipeline.Mod,
game: *Mod,
) !void {
// The Mach .core is where we set window options, etc.
mach.core.setTitle("gfx.Sprite example");
// We can create entities, and set components on them. Note that components live in a module
// namespace, e.g. the `.mach_gfx_sprite` module could have a 3D `.location` component with a different
// type than the `.physics2d` module's `.location` component if you desire.
@ -215,7 +212,7 @@ fn tick(
game.state().time += delta_time;
}
fn endFrame(game: *Mod) !void {
fn endFrame(game: *Mod, core: *mach.Core.Mod) !void {
// Finish render pass
game.state().frame_render_pass.end();
const label = @tagName(name) ++ ".endFrame";
@ -229,7 +226,13 @@ fn endFrame(game: *Mod) !void {
// Every second, update the window title with the FPS
if (game.state().fps_timer.read() >= 1.0) {
try mach.core.printTitle("gfx.Sprite example [ FPS: {d} ] [ Sprites: {d} ]", .{ game.state().frame_count, game.state().sprites });
try mach.Core.printTitle(
core,
core.state().main_window,
"sprite [ FPS: {d} ] [ Sprites: {d} ]",
.{ game.state().frame_count, game.state().sprites },
);
core.send(.update, .{});
game.state().fps_timer.reset();
game.state().frame_count = 0;
}