SpritePipeline: make .init and .deinit explicit

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-28 11:09:53 -07:00 committed by Stephen Gutekanst
parent 3504dfcab6
commit ed9137fe98
4 changed files with 22 additions and 10 deletions

View file

@ -34,6 +34,7 @@ pub const Mod = mach.Mod(@This());
pub const global_events = .{ pub const global_events = .{
.init = .{ .handler = init }, .init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.tick = .{ .handler = tick }, .tick = .{ .handler = tick },
}; };
@ -42,9 +43,16 @@ pub const local_events = .{
.end_frame = .{ .handler = endFrame }, .end_frame = .{ .handler = endFrame },
}; };
fn init(glyphs: *Glyphs.Mod, game: *Mod) !void { fn deinit(sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod) !void {
// Prepare which glyphs we will render sprite_pipeline.send(.deinit, .{});
glyphs.send(.deinit, .{});
}
fn init(sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs: *Glyphs.Mod, game: *Mod) !void {
sprite_pipeline.send(.init, .{});
glyphs.send(.init, .{}); glyphs.send(.init, .{});
// Prepare which glyphs we will render
glyphs.send(.prepare, .{&[_]u21{ '?', '!', 'a', 'b', '#', '@', '%', '$', '&', '^', '*', '+', '=', '<', '>', '/', ':', ';', 'Q', '~' }}); glyphs.send(.prepare, .{&[_]u21{ '?', '!', 'a', 'b', '#', '@', '%', '$', '&', '^', '*', '+', '=', '<', '>', '/', ':', ';', 'Q', '~' }});
// Run our init code after glyphs module is initialized. // Run our init code after glyphs module is initialized.

View file

@ -8,12 +8,9 @@ const assets = @import("assets");
pub const name = .glyphs; pub const name = .glyphs;
pub const Mod = mach.Mod(@This()); pub const Mod = mach.Mod(@This());
pub const global_events = .{
.deinit = .{ .handler = deinit },
};
pub const local_events = .{ pub const local_events = .{
.init = .{ .handler = init }, .init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.prepare = .{ .handler = prepare }, .prepare = .{ .handler = prepare },
}; };

View file

@ -38,6 +38,7 @@ pub const Mod = mach.Mod(@This());
pub const global_events = .{ pub const global_events = .{
.init = .{ .handler = init }, .init = .{ .handler = init },
.deinit = .{ .handler = deinit },
.tick = .{ .handler = tick }, .tick = .{ .handler = tick },
}; };
@ -45,12 +46,20 @@ pub const local_events = .{
.end_frame = .{ .handler = endFrame }, .end_frame = .{ .handler = endFrame },
}; };
fn deinit(
sprite_pipeline: *gfx.SpritePipeline.Mod,
) !void {
sprite_pipeline.send(.init, .{});
}
fn init( fn init(
core: *mach.Core.Mod, core: *mach.Core.Mod,
sprite: *gfx.Sprite.Mod, sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod,
game: *Mod, game: *Mod,
) !void { ) !void {
sprite_pipeline.send(.init, .{});
// We can create entities, and set components on them. Note that components live in a module // 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 // 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. // type than the `.physics2d` module's `.location` component if you desire.

View file

@ -59,11 +59,9 @@ pub const components = .{
.built = .{ .type = BuiltPipeline, .description = "internal" }, .built = .{ .type = BuiltPipeline, .description = "internal" },
}; };
pub const global_events = .{
.deinit = .{ .handler = deinit },
};
pub const local_events = .{ pub const local_events = .{
.init = .{ .handler = fn () void },
.deinit = .{ .handler = deinit },
.update = .{ .handler = update }, .update = .{ .handler = update },
.pre_render = .{ .handler = preRender }, .pre_render = .{ .handler = preRender },
.render = .{ .handler = render }, .render = .{ .handler = render },