From 14ccd5a93cf1791207b59114af661a6c23974933 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 22 Sep 2024 22:53:02 -0700 Subject: [PATCH] settle module state initialization Signed-off-by: Stephen Gutekanst --- examples/core-custom-entrypoint/App.zig | 7 ++++--- examples/core-triangle/App.zig | 10 +++++++--- src/Core.zig | 6 +----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/core-custom-entrypoint/App.zig b/examples/core-custom-entrypoint/App.zig index 8152666d..007f9695 100644 --- a/examples/core-custom-entrypoint/App.zig +++ b/examples/core-custom-entrypoint/App.zig @@ -62,9 +62,10 @@ pub fn init( const pipeline = core.device.createRenderPipeline(&pipeline_descriptor); // Store our render pipeline in our module's state, so we can access it later on. - // TODO(object): module-state-init - app.title_timer = try mach.time.Timer.start(); - app.pipeline = pipeline; + app.* = .{ + .title_timer = try mach.time.Timer.start(), + .pipeline = pipeline, + }; // TODO(object): window-title // try updateWindowTitle(core); diff --git a/examples/core-triangle/App.zig b/examples/core-triangle/App.zig index 83b3de08..fdd84f8d 100644 --- a/examples/core-triangle/App.zig +++ b/examples/core-triangle/App.zig @@ -21,9 +21,12 @@ pub fn init( app: *App, app_tick: mach.Call(App, .tick), app_deinit: mach.Call(App, .deinit), + // app_caller: mach.Caller(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; // Create our shader module const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl")); @@ -58,9 +61,10 @@ pub fn init( const pipeline = core.device.createRenderPipeline(&pipeline_descriptor); // Store our render pipeline in our module's state, so we can access it later on. - // TODO(object): module-state-init - app.title_timer = try mach.time.Timer.start(); - app.pipeline = pipeline; + app.* = .{ + .title_timer = try mach.time.Timer.start(), + .pipeline = pipeline, + }; // TODO(object): window-title // try updateWindowTitle(core); diff --git a/src/Core.zig b/src/Core.zig index 652cc46f..5de2d4e6 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -57,8 +57,6 @@ windows: mach.Objects(struct { fullscreen: bool, }), -global: mach.Object(struct {}), - /// Callback system invoked per tick (e.g. per-frame) on_tick: ?mach.FunctionID = null, @@ -131,10 +129,8 @@ pub fn init(core: *Core) !void { // TODO: remove undefined initialization (disgusting!) const platform: Platform = undefined; core.* = .{ - // TODO: this is a good example of why not *all* state fields should be allowed, must copy - // the ones mach initialized + // Note: since core.windows is initialized for us already, we just copy the pointer. .windows = core.windows, - .global = core.global, .allocator = allocator, .main_window = main_window,