|
QuasarEngine
Cross-platform 3D engine and editor
|
The gamepads connected to the computer, up to MaxGamepads. More...
#include <quasar/core/Gamepads.h>
Public Types | |
| using | EventCallback = std::function<void(Event&)> |
| Function that receives the events of the gamepads. | |
| using | Reader = std::function<std::optional<GamepadReading>(GamepadId)> |
| Function that reads a gamepad: the reading, or no value when no gamepad has this id. | |
Public Member Functions | |
| Gamepads () | |
| Creates the gamepads, read with GLFW. GLFW must be started before the first call to Update(). | |
| Gamepads (Reader reader) | |
| Creates the gamepads, read with another function, for example by the tests. | |
| void | Update (const EventCallback &send) |
| Reads every gamepad, keeps its new state, and sends the events of the changes since the last call. | |
| bool | IsConnected (GamepadId gamepad) const |
| Returns true if a gamepad is connected with this id. | |
| const std::string & | GetName (GamepadId gamepad) const |
| Returns the name of the gamepad, or an empty string if no gamepad is connected with this id. | |
| bool | IsButtonPressed (GamepadId gamepad, GamepadButton button) const |
| Returns true if the button of the gamepad is held down. False when the gamepad is not connected. | |
| float | GetAxis (GamepadId gamepad, GamepadAxis axis) const |
| Returns the value of the axis of the gamepad, after the dead zones. | |
| GamepadSettings & | GetSettings () |
| Returns the settings of the dead zones and of the events, which can be changed at any time. | |
| const GamepadSettings & | GetSettings () const |
| Returns the settings of the dead zones and of the events. | |
| void | SetReader (Reader reader) |
| Replaces the function that reads the gamepads, for example to simulate gamepads in the tests. | |
The gamepads connected to the computer, up to MaxGamepads.
The application owns one and calls Update() once per frame, after the window processed the messages of the operating system. GLFW sends no events for the buttons and axes of a gamepad: Update() reads their state, compares it with the previous frame, and sends an event for each change. The connection and disconnection of a gamepad are also found by Update().
Only devices that GLFW knows as gamepads are listed, so that the buttons and axes are at the same place on every gamepad. GLFW includes the mappings of the SDL_GameControllerDB project.
| void Quasar::Gamepads::Update | ( | const EventCallback & | send | ) |
Reads every gamepad, keeps its new state, and sends the events of the changes since the last call.
For each gamepad, in this order:
The state is updated before the events are sent, so the functions of this class give the new state.
| send | The function that receives the events. |
| float Quasar::Gamepads::GetAxis | ( | GamepadId | gamepad, |
| GamepadAxis | axis ) const |
Returns the value of the axis of the gamepad, after the dead zones.
0 when the gamepad is not connected.
Stick axes go from -1 to 1, and triggers from 0 to 1. The value is the one of the last Update(), which can differ slightly from the last GamepadAxisMovedEvent. See GamepadSettings::AxisEventThreshold.