Cleaned/improved input manager.

Added single frame actions for menus etc
Cleaned up continuous actions and set both to be captured.
This commit is contained in:
2026-09-15 07:58:19 +02:00
parent cb523a3d6f
commit c82c51aabf
+24 -17
View File
@@ -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
}