core: refactor
This commit is contained in:
parent
c254337e4b
commit
266e7a548b
38 changed files with 4119 additions and 4836 deletions
|
|
@ -40,7 +40,7 @@ pub const systems = .{
|
|||
.init = .{ .handler = init },
|
||||
.deinit = .{ .handler = deinit },
|
||||
.after_init = .{ .handler = afterInit },
|
||||
.tick = .{ .handler = tick },
|
||||
.update = .{ .handler = update },
|
||||
.end_frame = .{ .handler = endFrame },
|
||||
};
|
||||
|
||||
|
|
@ -53,11 +53,9 @@ fn deinit(
|
|||
}
|
||||
|
||||
fn init(
|
||||
core: *mach.Core.Mod,
|
||||
sprite_pipeline: *gfx.SpritePipeline.Mod,
|
||||
game: *Mod,
|
||||
) !void {
|
||||
core.schedule(.init);
|
||||
sprite_pipeline.schedule(.init);
|
||||
game.schedule(.after_init);
|
||||
}
|
||||
|
|
@ -99,11 +97,9 @@ fn afterInit(
|
|||
.allocator = allocator,
|
||||
.pipeline = pipeline,
|
||||
});
|
||||
|
||||
core.schedule(.start);
|
||||
}
|
||||
|
||||
fn tick(
|
||||
fn update(
|
||||
entities: *mach.Entities.Mod,
|
||||
core: *mach.Core.Mod,
|
||||
sprite: *gfx.Sprite.Mod,
|
||||
|
|
@ -112,7 +108,7 @@ fn tick(
|
|||
) !void {
|
||||
// TODO(important): event polling should occur in mach.Core module and get fired as ECS events.
|
||||
// TODO(Core)
|
||||
var iter = mach.core.pollEvents();
|
||||
var iter = core.state().pollEvents();
|
||||
var direction = game.state().direction;
|
||||
var spawning = game.state().spawning;
|
||||
while (iter.next()) |event| {
|
||||
|
|
@ -201,7 +197,7 @@ fn tick(
|
|||
|
||||
// Grab the back buffer of the swapchain
|
||||
// TODO(Core)
|
||||
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
||||
const back_buffer_view = core.state().swap_chain.getCurrentTextureView().?;
|
||||
defer back_buffer_view.release();
|
||||
|
||||
// Begin render pass
|
||||
|
|
@ -242,13 +238,11 @@ fn endFrame(game: *Mod, core: *mach.Core.Mod) !void {
|
|||
|
||||
// Every second, update the window title with the FPS
|
||||
if (game.state().fps_timer.read() >= 1.0) {
|
||||
try mach.Core.printTitle(
|
||||
core,
|
||||
try core.state().printTitle(
|
||||
core.state().main_window,
|
||||
"sprite [ FPS: {d} ] [ Sprites: {d} ]",
|
||||
.{ game.state().frame_count, game.state().sprites },
|
||||
);
|
||||
core.schedule(.update);
|
||||
game.state().fps_timer.reset();
|
||||
game.state().frame_count = 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue