From 93c27830060788dea1c364465d29e44d05a3064e Mon Sep 17 00:00:00 2001 From: iamcheeseman <[hidden email]> Date: Sat, 14 Feb 2026 18:02:47 -0500 Subject: Only process keys that are bound to an action --- src/fw/input.odin | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'src/fw/input.odin') diff --git a/src/fw/input.odin b/src/fw/input.odin index 2c15017..3c1236f 100644 --- a/src/fw/input.odin +++ b/src/fw/input.odin @@ -1,6 +1,8 @@ package fw import "core:c" +import "core:log" + import "vendor:glfw" Keyboard_Input :: union { @@ -13,57 +15,43 @@ Controller_Input :: union { Keybind :: struct { input: Keyboard_Input, - pressed: bool, + was_pressed: bool, just_pressed: bool, } -key_down_last_frame: #sparse [Key]bool -key_just_down: #sparse [Key]bool - -mouse_down_last_frame: #sparse [Mouse_Button]bool -mouse_just_down: #sparse [Mouse_Button]bool - -@(private) -_update_input :: proc() { - for key in Key { - status := glfw.GetKey(window, c.int(key)) - key_pressed := status == glfw.PRESS - key_just_down[key] = key_pressed && !key_down_last_frame[key] +update_keybind :: proc(keybind: ^Keybind) { + pressed: bool - key_down_last_frame[key] = key_pressed + switch val in keybind.input { + case Key: + pressed = glfw.GetKey(window, c.int(val)) == glfw.PRESS + case Mouse_Button: + pressed = glfw.GetMouseButton(window, c.int(val)) == glfw.PRESS } - for mb in Mouse_Button { - status := glfw.GetMouseButton(window, c.int(mb)) - mouse_pressed := status == glfw.PRESS - mouse_just_down[mb] = mouse_pressed && !mouse_down_last_frame[mb] - - mouse_down_last_frame[mb] = mouse_pressed - } + keybind.just_pressed = !keybind.was_pressed && pressed + keybind.was_pressed = pressed } +@(require_results) is_keybind_down :: proc(keybind: Keybind) -> bool { switch val in keybind.input { case Key: return glfw.GetKey(window, c.int(val)) == glfw.PRESS case Mouse_Button: return glfw.GetMouseButton(window, c.int(val)) == glfw.PRESS + case: + log.warn("Keybind input is invalid") + return false } - - assert(false) - return false } +@(require_results) is_keybind_just_down :: proc(keybind: Keybind) -> bool { - switch val in keybind.input { - case Key: return key_just_down[val] - case Mouse_Button: return mouse_just_down[val] - } - - assert(false) - return false + return keybind.just_pressed } +@(require_results) get_mouse_pos :: proc() -> (mouse_pos: Vec2) { w_width, w_height := glfw.GetWindowSize(window) mx, my := glfw.GetCursorPos(window) -- cgit v1.3-2-g0d8e