unify mach.Call and mach.Runner into one type

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-09-23 11:25:33 -07:00 committed by Emi Gutekanst
parent 14ccd5a93c
commit 8054d03b4d
19 changed files with 125 additions and 97 deletions

View file

@ -23,11 +23,10 @@ pub fn deinit(app: *App) void {
pub fn init(
app: *App,
core: *mach.Core,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Create our shader module
const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));

View file

@ -19,14 +19,10 @@ pipeline: *gpu.RenderPipeline,
pub fn init(
core: *mach.Core,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
// app_caller: mach.Caller(App),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
// core.on_tick = app_caller.tick;
// core.on_exit = app_caller.exit;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Create our shader module
const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));

View file

@ -20,7 +20,7 @@ direction: Vec2 = vec2(0, 0),
spawning: bool = false,
spawn_timer: mach.time.Timer,
// Components our game module defines.
// TODO(object)
pub const components = .{
// Whether an entity is a "follower" of our player entity or not. The type is void because we
// don't need any information, this is just a tag we assign to an entity with no data.
@ -49,11 +49,10 @@ fn init(
core: *mach.Core,
renderer: *Renderer,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Create our player entity.
const player = try entities.new();

View file

@ -15,6 +15,7 @@ uniform_buffer: *gpu.Buffer,
pub const mach_module = .renderer;
// TODO(object)
pub const components = .{
.position = .{ .type = Vec3 },
.rotation = .{ .type = Vec3 },

View file

@ -56,11 +56,10 @@ fn init(
glyphs: *Glyphs.Mod,
app: *App,
core: *mach.Core,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Create a sprite rendering pipeline
const texture = glyphs.state().texture;

View file

@ -80,12 +80,10 @@ fn init(
text: *gfx.Text.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_audio_state_change: mach.Call(App, .audio_state_change),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Configure the audio module to run our audio_state_change system when entities audio finishes
// playing

View file

@ -25,6 +25,7 @@ pub const mach_systems = .{ .start, .init, .deinit, .tick, .audio_state_change }
// TODO: banish global allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// TODO(object)
pub const components = .{
.play_after = .{ .type = f32 },
};
@ -41,12 +42,10 @@ fn init(
core: *mach.Core,
audio: *mach.Audio,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_audio_state_change: mach.Call(App, .audio_state_change),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Configure the audio module to send our app's .audio_state_change event when an entity's sound
// finishes playing.

View file

@ -19,6 +19,7 @@ pub const mach_module = .app;
pub const mach_systems = .{ .start, .init, .deinit, .tick, .audio_state_change };
// TODO(object)
pub const components = .{
.is_bgm = .{ .type = void },
};
@ -40,12 +41,10 @@ fn init(
core: *mach.Core,
audio: *mach.Audio,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_audio_state_change: mach.Call(App, .audio_state_change),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// Configure the audio module to send our app's .audio_state_change event when an entity's sound
// finishes playing.

View file

@ -58,11 +58,10 @@ fn init(
sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// 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

View file

@ -67,11 +67,10 @@ fn init(
text_pipeline: *gfx.TextPipeline.Mod,
text_style: *gfx.TextStyle.Mod,
app: *App,
app_tick: mach.Call(App, .tick),
app_deinit: mach.Call(App, .deinit),
app_mod: mach.Functions(App),
) !void {
core.on_tick = app_tick.id;
core.on_exit = app_deinit.id;
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;
// TODO: a better way to initialize entities with default values
// TODO(text): ability to specify other style options (custom font name, font color, italic/bold, etc.)