Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 1.99 KB

README.md

File metadata and controls

64 lines (46 loc) · 1.99 KB

Lum::InputHandler

This is a basic input handling system built on top of GLFW. It allows you to define custom actions, specify how these actions are triggered, and map them to (from) various input sources

Features

  • Indirect Input : Create your own enum to define actions (e.g., Jump, Shoot), define callbacks for them and then (re)map keys to actions

  • Action Types : Specify how actions are triggered (for now these few. Any ideas?):

    • One-shot : Triggered once when the input is pressed.

    • Continuous : Triggered every frame while the input is held down.

Usage

  1. Create an Enum for Actions : Define your actions using an enumeration.
enum class GameAction {
    Jump,
    Shoot,
    LAST_ACTION // Always keep this as the last element
};
  1. Instantiate the InputHandler : Create an instance of Lum::InputHandler with your action enum
Lum::InputHandler<GameAction> inputHandler;
  1. Setup : Call the setup() initialize GLFW callbacks
inputHandler.setup(window);
  1. Define Actions : Bind keys, mouse buttons, and gamepad buttons to actions, set action types, and assign callbacks as needed.
inputHandler.rebindKey(GameAction::Jump, GLFW_KEY_SPACE);
inputHandler.rebindMouseButton(GameAction::Shoot, GLFW_MOUSE_BUTTON_LEFT);
inputHandler.setActionType(GameAction::Jump, ActionType::OneShot);
inputHandler.setActionType(GameAction::Shoot, ActionType::OneShot);
inputHandler.setActionCallback(GameAction::Jump, [](GameAction action) {
    // Handle jump action...
});
inputHandler.setActionCallback(GameAction::Shoot, [](GameAction action) {
    // Handle shoot action...
});
  1. Poll Updates : In your main game loop, call pollUpdates() to process input
while (!glfwWindowShouldClose(window)) {
    inputHandler.pollUpdates();
    // Other game logic...
}

TODO

  • InputState enum to manage different input contexts (like Esc in StateGame opens menu, but Esc in StateMenu closes menu)