From 1f95bd48df98b9d33b1d6037b1a896ee68b4fda9 Mon Sep 17 00:00:00 2001 From: iddev5 Date: Mon, 9 May 2022 12:55:45 +0530 Subject: [PATCH] examples: use engine.core.setKeyCallback() instead of accessing glfw directly --- examples/advanced-gen-texture-light/main.zig | 10 +++------- examples/fractal-cube/main.zig | 8 +++----- examples/instanced-cube/main.zig | 8 +++----- examples/rotating-cube/main.zig | 8 +++----- examples/textured-cube/main.zig | 8 +++----- examples/two-cubes/main.zig | 8 +++----- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/examples/advanced-gen-texture-light/main.zig b/examples/advanced-gen-texture-light/main.zig index c16d1ddb..329deaac 100755 --- a/examples/advanced-gen-texture-light/main.zig +++ b/examples/advanced-gen-texture-light/main.zig @@ -38,7 +38,7 @@ const FrameParams = struct { }; pub fn init(app: *App, engine: *mach.Engine) !void { - engine.core.internal.window.setKeyCallback(keyCallback); + engine.core.setKeyCallback(keyCallback); // todo // engine.core.internal.window.setKeyCallback(struct { // fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { @@ -879,14 +879,10 @@ const Instance = struct { } }; -fn keyCallback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { - _ = window; - _ = scancode; - _ = mods; - +fn keyCallback(_: *App, engine: *mach.Engine, key: mach.Key, action: mach.Action) void { if (action == .press) { switch (key) { - .q, .escape, .space => window.setShouldClose(true), + .q, .escape, .space => engine.core.internal.window.setShouldClose(true), .w, .up => { global_params.keys |= FrameParams.up; }, diff --git a/examples/fractal-cube/main.zig b/examples/fractal-cube/main.zig index eaaf3bf9..277c5b4a 100755 --- a/examples/fractal-cube/main.zig +++ b/examples/fractal-cube/main.zig @@ -40,13 +40,11 @@ bgl: gpu.BindGroupLayout, pub fn init(app: *App, engine: *mach.Engine) !void { timer = try std.time.Timer.start(); - engine.core.internal.window.setKeyCallback(struct { - fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { - _ = scancode; - _ = mods; + engine.core.setKeyCallback(struct { + fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void { if (action == .press) { switch (key) { - .space => window.setShouldClose(true), + .space => eng.core.internal.window.setShouldClose(true), else => {}, } } diff --git a/examples/instanced-cube/main.zig b/examples/instanced-cube/main.zig index 2dc88c77..afdc7964 100755 --- a/examples/instanced-cube/main.zig +++ b/examples/instanced-cube/main.zig @@ -23,13 +23,11 @@ const App = @This(); pub fn init(app: *App, engine: *mach.Engine) !void { timer = try std.time.Timer.start(); - engine.core.internal.window.setKeyCallback(struct { - fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { - _ = scancode; - _ = mods; + engine.core.setKeyCallback(struct { + fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void { if (action == .press) { switch (key) { - .space => window.setShouldClose(true), + .space => eng.core.internal.window.setShouldClose(true), else => {}, } } diff --git a/examples/rotating-cube/main.zig b/examples/rotating-cube/main.zig index 876e00c6..c007b56a 100755 --- a/examples/rotating-cube/main.zig +++ b/examples/rotating-cube/main.zig @@ -24,13 +24,11 @@ pub fn init(app: *App, engine: *mach.Engine) !void { timer = try std.time.Timer.start(); // TODO: higher level input handlers - engine.core.internal.window.setKeyCallback(struct { - fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { - _ = scancode; - _ = mods; + engine.core.setKeyCallback(struct { + fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void { if (action == .press) { switch (key) { - .space => window.setShouldClose(true), + .space => eng.core.internal.window.setShouldClose(true), else => {}, } } diff --git a/examples/textured-cube/main.zig b/examples/textured-cube/main.zig index b4c9ebbf..afb32264 100644 --- a/examples/textured-cube/main.zig +++ b/examples/textured-cube/main.zig @@ -26,13 +26,11 @@ const App = @This(); pub fn init(app: *App, engine: *mach.Engine) !void { timer = try std.time.Timer.start(); - engine.core.internal.window.setKeyCallback(struct { - fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { - _ = scancode; - _ = mods; + engine.core.setKeyCallback(struct { + fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void { if (action == .press) { switch (key) { - .space => window.setShouldClose(true), + .space => eng.core.internal.window.setShouldClose(true), else => {}, } } diff --git a/examples/two-cubes/main.zig b/examples/two-cubes/main.zig index 6baab680..71c2065c 100755 --- a/examples/two-cubes/main.zig +++ b/examples/two-cubes/main.zig @@ -24,13 +24,11 @@ const App = @This(); pub fn init(app: *App, engine: *mach.Engine) !void { timer = try std.time.Timer.start(); - engine.core.internal.window.setKeyCallback(struct { - fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void { - _ = scancode; - _ = mods; + engine.core.setKeyCallback(struct { + fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void { if (action == .press) { switch (key) { - .space => window.setShouldClose(true), + .space => eng.core.internal.window.setShouldClose(true), else => {}, } }