ASGE
3.2.0
Simple Game Framework in GL
|
#include <Input.hpp>
Public Types | |
using | CallbackID = std::string |
Public Member Functions | |
Input () | |
Input (const Input &rhs)=delete | |
Input & | operator= (const Input &rhs)=delete |
virtual | ~Input () |
virtual bool | init (Renderer *renderer)=0 |
virtual void | update ()=0 |
virtual void | updateGamePadMappings (const std::filesystem::path &mappings_file)=0 |
virtual void | getCursorPos (double &xpos, double &ypos) const =0 |
virtual void | setCursorMode (ASGE::MOUSE::CursorMode mode)=0 |
virtual void | setCursorPos (double x, double y) const =0 |
virtual GamePadData | getGamePad (int idx) const =0 |
virtual GamePadData | getGamePad () const =0 |
virtual std::vector< GamePadData > | getGamePads () const =0 |
void | sendEvent (EventType type, SharedEventData data) |
template<typename T , typename T2 > | |
CallbackID | addCallbackFnc (EventType type, T fncPtr, T2 *obj) |
template<typename T > | |
CallbackID | addCallbackFnc (EventType type, T fncPtr) |
void | unregisterCallback (CallbackID id) |
Public Attributes | |
bool | use_threads = false |
The input handler system.
The input class is designed to work alongside the renderer and is responsible for sending events to interested parties. It will also provide helper functions that can retrieve non-event driven data such as the cursor position or the gamepad status. Much of the underlying implementation will be platform specific, with input offering a compatible interface.
ASGE::Input::Input | ( | ) |
Default Constructor.
|
virtual |
Destructor. Clears all callback functions.
|
inline |
Adds a callback function. Many events are callback driven. This function allows the use of a function to be called when the event happens.
[in] | type | The type of event being listened for. |
[in] | fncPtr | The function pointer. |
|
inline |
Adds a callback function. Many events are callback driven. This function allows the use of a member function to be called when the event happens.
[in] | type | The type of event being listened for. |
[in] | fncPtr | The function pointer. |
[in] | obj | The object (this ptr) the function belongs to. |
|
pure virtual |
Gets the cursor's (mouse) position. Grabs the current position in screen space of the mouse cursor. This can be used to detect the location of clicks as well as its current position. The positions are stored directly in the two parameters passed in.
[in] | xpos | The position in the X axis. |
[in] | ypos | The position in the Y axis. |
|
pure virtual |
Obtains the first connected controllers data. Searches for the first connected controller and then returns any data relating to it, including naming, axis and button states. This is currently polled (demanded) rather than event driven and is normally handled by the renderer's window.
|
pure virtual |
Obtains the controllers data. Searches for a controller connected at a specific idx and returns any data relating to it, including naming, axis and button states. This is currently polled (demanded) rather than event driven and is normally handled by the renderer's window.
[in] | idx | The id of the connected controller. |
|
pure virtual |
Retrieves a list of all connected game pads. Searches for all possible connected gamepads and retrieves the data for each one. If no attached gamepads are present then the vector will be empty. This can be used to easily process all connected inputs in a single call, rather than individually checking for each index to see if a gamepad is connected.
Example:
|
pure virtual |
Destructor. Initialises and sets up the input system.
renderer | A pointer to the linked renderer system. |
void ASGE::Input::sendEvent | ( | EventType | type, |
SharedEventData | data | ||
) |
Sends an event. When an event happens, the type of event and the data relating to it is forwarded to any interested parties via their function pointer. NOTE: the data is shared because the events can be sent using threads and this ensures their lifespan.
[in] | type | The type of event registered. |
[in] | data | The data relating to the event. |
|
pure virtual |
Sets the cursor's (mouse) mode. Allows control over the mouse cursors visibility and whether or not it should be locked to the window.
[in] | mode | The cursor mode to set. |
|
pure virtual |
Sets the cursor's current position
[in] | x | The x position to move the mouse to. |
[in] | y | The y position to move the mouse to. |
void ASGE::Input::unregisterCallback | ( | CallbackID | id | ) |
Removes a callback function.
This requires a valid handle to work correctly. The handle is returned when the function event is added. This prevents callbacks happening for classes or functions that no longer exist.
[in] | id | The handle for the registered callback. |
|
pure virtual |
Updates the input handler.
|
pure virtual |
Updates the GamePad mappings used. The engine makes use of a third party solution to correctly map button presses to connected gamepads in a consistent way, regardless of manufacturer or type. The aims is to solve the problem with the "X" button differs depending on the model of gamepad used. The file format should follow the project SDL_GameControllerDB which is the mapping system uses.
[in] | mappings_file | The updated GamePad mappings. |
bool ASGE::Input::use_threads = false |