From c82c51aabf39d6200c7b25ae1855d6959ce83630 Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Tue, 15 Sep 2026 07:58:19 +0200 Subject: [PATCH] Cleaned/improved input manager. Added single frame actions for menus etc Cleaned up continuous actions and set both to be captured. --- src/input_manager.odin | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/input_manager.odin b/src/input_manager.odin index 57a2dd7..41a30d4 100644 --- a/src/input_manager.odin +++ b/src/input_manager.odin @@ -4,35 +4,42 @@ import rl "vendor:raylib" // ------------------------------------------------------------------------------ // Input Manager, captures input events and stores them into a struct. -// Passing the struct down allows for components to use inputs independantly +// Passing the struct down allows for components to use inputs independently // ------------------------------------------------------------------------------ Input_Event :: struct { - // Normalized and merged from keyboard + controller - move_dir: rl.Vector2, - pause_pressed: bool, + // Continuous movement normalized + move_dir: rl.Vector2, + + // single frame actions UI and triggers + up_pressed: bool, + down_pressed: bool, + confirm_pressed: bool, + pause_pressed: bool, } poll_input :: proc() -> Input_Event { input_event := Input_Event{} - input_dir := rl.Vector2{0,0} + input_dir := rl.Vector2{0, 0} - // ------------------------------------------------------------------------------------------------------ - // Keyboard - // ------------------------------------------------------------------------------------------------------ - if rl.IsKeyDown(.W) || rl.IsKeyDown(.UP) { input_dir.y -= 1 } - if rl.IsKeyDown(.S) || rl.IsKeyDown(.DOWN) { input_dir.y += 1 } + // -------------------------------------------------------------------------- + // Continuous Input ie movement code + // -------------------------------------------------------------------------- + if rl.IsKeyDown(.W) || rl.IsKeyDown(.UP) { input_dir.y -= 1 } + if rl.IsKeyDown(.S) || rl.IsKeyDown(.DOWN) { input_dir.y += 1 } - // single-fire == IsKeyPressed, held == IsKeyDown - input_event.pause_pressed = rl.IsKeyPressed(.P) - - // ------------------------------------------------------------------------------------------------------ - // Movement/direction needs update - // ------------------------------------------------------------------------------------------------------ if input_dir.x != 0 || input_dir.y != 0 { input_dir = rl.Vector2Normalize(input_dir) } input_event.move_dir = input_dir - return input_event + // -------------------------------------------------------------------------- + // actions single press ie menu navigation etc + // -------------------------------------------------------------------------- + input_event.up_pressed = rl.IsKeyPressed(.W) || rl.IsKeyPressed(.UP) + input_event.down_pressed = rl.IsKeyPressed(.S) || rl.IsKeyPressed(.DOWN) + input_event.confirm_pressed = rl.IsKeyPressed(.ENTER) || rl.IsKeyPressed(.SPACE) + input_event.pause_pressed = rl.IsKeyPressed(.P) + + return input_event } \ No newline at end of file