Problem Statement
Input handling is tightly coupled to specific hardware keys (e.g., input.isKeyDown(.w)) throughout Player.zig, App.zig, and menus.zig. This makes key rebinding and gamepad support impossible without rewriting gameplay logic.
Proposed Architecture
Introduce an abstraction layer for Input Actions:
- Define Logical Actions: Create an enum
GameAction (e.g., MoveForward, Jump, Inventory, MenuBack).
InputMapper: A new struct responsible for mapping physical inputs (Key, MouseButton, GamepadButton) to logical GameActions.
- Update Usage: Refactor gameplay code to query
input.isActionPressed(.Jump) instead of checking specific keys.
Benefits
- Rebinding Support: Users can customize controls.
- Hardware Agnostic: Seamlessly support Keyboard, Mouse, and Gamepad via a unified interface.
- Clean Code (DIP): Gameplay logic depends on high-level intents, not low-level hardware details.
Problem Statement
Input handling is tightly coupled to specific hardware keys (e.g.,
input.isKeyDown(.w)) throughoutPlayer.zig,App.zig, andmenus.zig. This makes key rebinding and gamepad support impossible without rewriting gameplay logic.Proposed Architecture
Introduce an abstraction layer for Input Actions:
GameAction(e.g.,MoveForward,Jump,Inventory,MenuBack).InputMapper: A new struct responsible for mapping physical inputs (Key,MouseButton,GamepadButton) to logicalGameActions.input.isActionPressed(.Jump)instead of checking specific keys.Benefits