From 20e0c1b3ee801adbf926cd162141be4fe207e54c Mon Sep 17 00:00:00 2001 From: Peter Li Date: Mon, 5 May 2025 00:58:05 -0700 Subject: [PATCH] input debugger --- engine/core/src/inputs/inputStack.zig | 2 +- extras/gameExtras/src/FpCamera.zig | 1 + extras/gameExtras/src/gameExtras.zig | 2 ++ extras/gameExtras/src/inputDebugger.zig | 35 +++++++++++++++++++++++++ projects/sampleGame/main.zig | 4 ++- 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 extras/gameExtras/src/inputDebugger.zig diff --git a/engine/core/src/inputs/inputStack.zig b/engine/core/src/inputs/inputStack.zig index c79e482..8a977e4 100644 --- a/engine/core/src/inputs/inputStack.zig +++ b/engine/core/src/inputs/inputStack.zig @@ -31,7 +31,7 @@ pub fn convertEvent(event: *const sdl3.Event) ?IOEvent { .key = .{ .key = scan, .scancode = scan, - .action = if (event.key.down) .keyDown else .keyUp, + .action = if (event.button.down) .keyDown else .keyUp, .mods = 0, }, }; diff --git a/extras/gameExtras/src/FpCamera.zig b/extras/gameExtras/src/FpCamera.zig index a5f5e89..ec41d32 100644 --- a/extras/gameExtras/src/FpCamera.zig +++ b/extras/gameExtras/src/FpCamera.zig @@ -96,3 +96,4 @@ const std = @import("std"); const backlog = @import("Backlog"); const core = backlog.core; const rend = backlog.rend; +const ig = backlog.imgui.api; diff --git a/extras/gameExtras/src/gameExtras.zig b/extras/gameExtras/src/gameExtras.zig index 187bcd0..1c16184 100644 --- a/extras/gameExtras/src/gameExtras.zig +++ b/extras/gameExtras/src/gameExtras.zig @@ -1 +1,3 @@ pub const FpCamera = @import("FpCamera.zig"); + +pub const inputDebugger = @import("inputDebugger.zig"); diff --git a/extras/gameExtras/src/inputDebugger.zig b/extras/gameExtras/src/inputDebugger.zig new file mode 100644 index 0000000..9bd87f3 --- /dev/null +++ b/extras/gameExtras/src/inputDebugger.zig @@ -0,0 +1,35 @@ +allocator: std.mem.Allocator, + +fn log(comptime fmt: []const u8, args: anytype) void { + core.engine_log("[InputDebugger] " ++ fmt, args); +} + +fn debugShowKeys(binding: anytype) void { + ig.textFmt("{s} ({s}) keysDown count: {d}", .{ binding.data.name.utf8(), @typeName(@TypeOf(binding)), binding.data.keysDown.count() }) catch return; +} + +pub fn tick() void { + const stack = core.inputs.getInputStack(); + if (ig.begin("input stack", null, .{})) { + for (stack.active.bindingStack.items) |binding| { + switch (binding) { + .action => |b| { + debugShowKeys(b); + }, + .axis1d => |b| { + debugShowKeys(b); + }, + .axis2d => |b| { + debugShowKeys(b); + }, + } + } + ig.end(); + } +} + +const std = @import("std"); +const backlog = @import("Backlog"); +const core = backlog.core; +const rend = backlog.rend; +const ig = backlog.imgui.api; diff --git a/projects/sampleGame/main.zig b/projects/sampleGame/main.zig index 01e7ed6..fbe0164 100644 --- a/projects/sampleGame/main.zig +++ b/projects/sampleGame/main.zig @@ -292,6 +292,7 @@ pub fn getMouseMovement(self: *@This()) core.Vector2f { pub fn tick(self: *@This(), dt: f64) void { const fdt: f32 = @floatCast(dt); + extras.inputDebugger.tick(); self.videoplayer.tick(dt); self.doomplayer.tick(dt); self.fpcamera.tick(dt); @@ -354,7 +355,8 @@ pub fn main() anyerror!void { const DoomPlayer = @import("doomplayer"); const VideoPlayer = @import("videoplayer"); -const FpCamera = @import("gameExtras").FpCamera; +const extras = @import("gameExtras"); +const FpCamera = extras.FpCamera; const std = @import("std"); const backlog = @import("Backlog"); const assets = backlog.assets;