class final
#include <engine/input/input.hpp>
Input Resource which stores the input bindings for multiple players.
Its state is updated accordingly as events are received by the Input.
Public types
-
using Key = core::
io:: Key - Alias for core::
io:: Key. -
using GamepadButton = core::
io:: GamepadButton - Alias for core::
io:: GamepadButton. -
using GamepadAxis = core::
io:: GamepadAxis - Alias for core::
io:: GamepadAxis. -
using MouseButton = core::
io:: MouseButton - Alias for core::
io:: MouseButton.
Public static functions
-
static void handle(const core::
io:: Window& window, const core:: io:: WindowEvent& event) - Handle all other events - discards them.
Public functions
- void clear()
- Clears all bindings.
- void clear(int player)
- Clears all bindings for a specific player.
- void bind(const InputBindings& bindings, int player = 0)
- Sets the bindings for a specific player.
- void gamepad(int player, int gamepad)
- Sets the gamepad for a specific player.
- auto gamepad(int player) const -> int
- Gets the gamepad for a specific player.
- auto gamepadCount() const -> int
- Gets the number of currently connected gamepads.
- auto pressed(const char* actionName, int player = 0) const -> bool
- Gets an action state for a specific player.
- auto justPressed(const char* actionName, int player = 0) const -> bool
- Gets an action state for a specific player.
- auto justReleased(const char* actionName, int player = 0) const -> bool
- Gets an action state for a specific player.
- auto axis(const char* axisName, int player = 0) const -> float
- Gets an axis value for a specific player.
-
void handle(const core::
io:: Window& window, const core:: io:: KeyEvent& event) - Handle a key event.
-
void handle(const core::
io:: Window& window, const core:: io:: GamepadConnectionEvent& event) - Handle a gamepad connection event.
-
void handle(const core::
io:: Window& window, const core:: io:: MouseButtonEvent& event) - Handle a mouse button event.
-
void handle(const core::
io:: Window& window, const core:: io:: MouseMoveEvent& event) - Handle a mouse movement event.
- void updateMouse()
- Resets the previous mouse position to equal the current.
- void updateActions()
- Reset the previous Action justPressed and justReleased states.
- auto mousePosition() const -> glm::ivec2
- Gets the mouse position in screen space.
- auto previousMousePosition() const -> glm::ivec2
- Gets the mouse position in the previous frame in screen space.
- auto mouseDelta() const -> glm::ivec2
- Gets displacement of the mouse during the last frame, in screen space.
-
void pollGamepads(const core::
io:: Window& window) - Polls the input state of the gamepads.
- auto bindings() const -> const std::unordered_map<int, InputBindings>&
- Gets the bindings for each player.
Function documentation
static void cubos:: engine:: Input:: handle(const core:: io:: Window& window,
const core:: io:: WindowEvent& event)
Handle all other events - discards them.
Parameters | |
---|---|
window | Window that received the event. |
event | Event to discard. |
This is method exists so that std::visit
can be used with core::
void cubos:: engine:: Input:: clear(int player)
Clears all bindings for a specific player.
Parameters | |
---|---|
player | Player whose bindings will be cleared. |
void cubos:: engine:: Input:: bind(const InputBindings& bindings,
int player = 0)
Sets the bindings for a specific player.
Parameters | |
---|---|
bindings | Bindings to set. |
player | Player whose bindings will be set. |
void cubos:: engine:: Input:: gamepad(int player,
int gamepad)
Sets the gamepad for a specific player.
Parameters | |
---|---|
player | Player whose gamepad will be set. |
gamepad | Gamepad to set. |
int cubos:: engine:: Input:: gamepad(int player) const
Gets the gamepad for a specific player.
Parameters | |
---|---|
player | Player whose gamepad will be retrieved. |
Returns | Gamepad if it exists, -1 otherwise. |
int cubos:: engine:: Input:: gamepadCount() const
Gets the number of currently connected gamepads.
Returns | Number of connected gamepads. |
---|
bool cubos:: engine:: Input:: pressed(const char* actionName,
int player = 0) const
Gets an action state for a specific player.
Parameters | |
---|---|
actionName | Name of the action. |
player | Player whose action state will be retrieved. |
Returns | Whether the action exists and is pressed. |
bool cubos:: engine:: Input:: justPressed(const char* actionName,
int player = 0) const
Gets an action state for a specific player.
Parameters | |
---|---|
actionName | Name of the action. |
player | Player whose action state will be retrieved. |
Returns | Whether the action exists and was just pressed. |
bool cubos:: engine:: Input:: justReleased(const char* actionName,
int player = 0) const
Gets an action state for a specific player.
Parameters | |
---|---|
actionName | Name of the action. |
player | Player whose action state will be retrieved. |
Returns | Whether the action exists and was just released. |
float cubos:: engine:: Input:: axis(const char* axisName,
int player = 0) const
Gets an axis value for a specific player.
Parameters | |
---|---|
axisName | Name of the axis. |
player | Player whose axis value will be retrieved. |
Returns | Axis value if the axis exists, 0.0 otherwise. |
void cubos:: engine:: Input:: handle(const core:: io:: Window& window,
const core:: io:: KeyEvent& event)
Handle a key event.
Parameters | |
---|---|
window | Window that received the event. |
event | Key event. |
void cubos:: engine:: Input:: handle(const core:: io:: Window& window,
const core:: io:: GamepadConnectionEvent& event)
Handle a gamepad connection event.
Parameters | |
---|---|
window | Window that received the event. |
event | Gamepad connection event. |
void cubos:: engine:: Input:: handle(const core:: io:: Window& window,
const core:: io:: MouseButtonEvent& event)
Handle a mouse button event.
Parameters | |
---|---|
window | Window that received the event. |
event | Mouse button event. |
void cubos:: engine:: Input:: handle(const core:: io:: Window& window,
const core:: io:: MouseMoveEvent& event)
Handle a mouse movement event.
Parameters | |
---|---|
window | Window that received the event. |
event | Mouse movement event. |
glm::ivec2 cubos:: engine:: Input:: mousePosition() const
Gets the mouse position in screen space.
Returns | Mouse position. |
---|
glm::ivec2 cubos:: engine:: Input:: previousMousePosition() const
Gets the mouse position in the previous frame in screen space.
Returns | Mouse position in the previous frame. |
---|
glm::ivec2 cubos:: engine:: Input:: mouseDelta() const
Gets displacement of the mouse during the last frame, in screen space.
Returns | Mouse displacement. |
---|
void cubos:: engine:: Input:: pollGamepads(const core:: io:: Window& window)
Polls the input state of the gamepads.
Parameters | |
---|---|
window | Window to poll the gamepad state from. |
const std::unordered_map<int, InputBindings>& cubos:: engine:: Input:: bindings() const
Gets the bindings for each player.
Returns | Bindings for each player. |
---|