Cogs.Core
|
Input manager responsible for handling input from various devices, including mouse, keyboard, game controllers etc. More...
#include <InputManager.h>
Classes | |
struct | InputActionMapping |
struct | InputAxisMapping |
struct | SourceActionMapping |
struct | SourceAxisMapping |
Public Member Functions | |
InputManager (ViewContext *viewContext) | |
Constructs a new InputManager. | |
~InputManager () | |
Destructs the InputManager. | |
InputManager (const InputManager &)=delete | |
InputManager & | operator= (const InputManager &)=delete |
void | initialize () |
Initialize the input managers default configuration. | |
void | addProvider (std::unique_ptr< IInputProvider > provider) |
Register a new input provider. | |
void | createAxisMapping (const InputIdentifier &axisId, const StringView &name) |
Map input axis to a friendly name. | |
void | createActionMapping (const InputIdentifier &actionId, const StringView &name) |
Map input button to a friendly action name. | |
float | getAxisValue (const StringView &name) const |
Get last value for the given mapped axis. | |
bool | getActionState (const StringView &name) const |
Get last action state for the given mapped action. | |
void | update () |
Update the input state. | |
Cogs::Core::InputIdentifier | getAxis (std::string driver, std::string device, std::string axis) |
size_t | getAxisIndex (InputDeviceState *device, const StringView &inputAxis) const |
void | addAxisMapping (const StringView &name, const StringView &device, const StringView &inputAxis, float scale=1.0f, int flags=0) |
void | addAxisMapping (const StringView &name, InputDeviceState *device, const StringView &inputAxis, float scale=1.0f, int flags=0) |
size_t | getButtonIndex (InputDeviceState *device, const StringView &inputAction) const |
void | addActionMapping (const StringView &name, const StringView &device, const StringView &inputAction, int placeholder=0) |
void | addActionMapping (const StringView &name, InputDeviceState *device, const StringView &inputAction, int placeholder=0) |
void | gainedFocus (double timestamp_ms) |
void | lostFocus (double timestamp_ms) |
void | triggerPointerPress (PointerType pointerType, PointerId pointerId, MouseButton button, const glm::ivec2 &position, double timestamp_ms) |
void | triggerPointerRelease (PointerType pointerType, PointerId pointerId, MouseButton button, const glm::ivec2 &position, double timestamp_ms) |
void | triggerPointerMove (PointerType pointerType, PointerId pointerId, const glm::ivec2 &position, double timestamp_ms) |
void | triggerMouseWheel (int32_t deltaValue, double timestamp_ms) |
void | triggerKeyDown (Key key, double timestamp_ms) |
void | triggerKeyUp (Key key, double timestamp_ms) |
void | triggerKeyChar (std::string ch, double timestamp_ms) |
InputDeviceState & | getDevice (InputDevices::EValues deviceId) |
ViewContext * | getView () const |
Private Member Functions | |
void | updateConnections () |
void | updateInputs () |
void | updateActions () |
void | updateAxes () |
double | checkTimeStamp (double timestamp_ms) |
void | readInputConfig (const StringView &path) |
InputDeviceState * | getDevice (const StringView &name) |
Private Attributes | |
ViewContext * | view = nullptr |
double | prevTimeStamp = 0.0 |
std::vector< InputDeviceState > | deviceStates |
std::unordered_map< size_t, InputAxisMapping > | axisMappings |
std::unordered_map< size_t, InputActionMapping > | actionMappings |
std::vector< std::unique_ptr< IInputProvider > > | inputProviders |
std::vector< InputDeviceIdentifier > | pendingDevices |
Static Private Attributes | |
static constexpr size_t | NoAxis = static_cast<size_t>(-1) |
static constexpr size_t | NoButton = static_cast<size_t>(-1) |
static constexpr size_t | ErrorAxis = static_cast<size_t>(-2) |
static constexpr size_t | ErrorButton = static_cast<size_t>(-2) |
Friends | |
void | inputInspector (Context *context, bool *show) |
Input manager responsible for handling input from various devices, including mouse, keyboard, game controllers etc.
Definition at line 36 of file InputManager.h.
|
explicit |
Constructs a new InputManager.
Definition at line 70 of file InputManager.cpp.
Cogs::Core::InputManager::~InputManager | ( | ) |
Destructs the InputManager.
Definition at line 76 of file InputManager.cpp.
void Cogs::Core::InputManager::addActionMapping | ( | const StringView & | name, |
const StringView & | device, | ||
const StringView & | inputAction, | ||
int | placeholder = 0 |
||
) |
Definition at line 283 of file InputManager.cpp.
void Cogs::Core::InputManager::addActionMapping | ( | const StringView & | name, |
InputDeviceState * | device, | ||
const StringView & | inputAction, | ||
int | placeholder = 0 |
||
) |
Definition at line 292 of file InputManager.cpp.
void Cogs::Core::InputManager::addAxisMapping | ( | const StringView & | name, |
const StringView & | device, | ||
const StringView & | inputAxis, | ||
float | scale = 1.0f , |
||
int | flags = 0 |
||
) |
Definition at line 238 of file InputManager.cpp.
void Cogs::Core::InputManager::addAxisMapping | ( | const StringView & | name, |
InputDeviceState * | device, | ||
const StringView & | inputAxis, | ||
float | scale = 1.0f , |
||
int | flags = 0 |
||
) |
Definition at line 247 of file InputManager.cpp.
void Cogs::Core::InputManager::addProvider | ( | std::unique_ptr< IInputProvider > | provider | ) |
Register a new input provider.
Definition at line 186 of file InputManager.cpp.
|
private |
Ensure time stamp is numerically greater than the previous.
timestamp_ms | - Time stamp of input event. |
Ensure that timestamp of event N > timestamp of event N-1
Definition at line 590 of file InputManager.cpp.
void Cogs::Core::InputManager::createActionMapping | ( | const InputIdentifier & | actionId, |
const StringView & | name | ||
) |
Map input button to a friendly action name.
Definition at line 152 of file InputManager.cpp.
References Cogs::Core::InputIdentifier::deviceId, Cogs::Core::InputDeviceIdentifier::driver, Cogs::Core::InputDeviceIdentifier::id, and Cogs::Core::InputIdentifier::inputName.
void Cogs::Core::InputManager::createAxisMapping | ( | const InputIdentifier & | axisId, |
const StringView & | name | ||
) |
Map input axis to a friendly name.
Definition at line 145 of file InputManager.cpp.
References Cogs::Core::InputIdentifier::deviceId, Cogs::Core::InputDeviceIdentifier::driver, Cogs::Core::InputDeviceIdentifier::id, and Cogs::Core::InputIdentifier::inputName.
void Cogs::Core::InputManager::gainedFocus | ( | double | timestamp_ms | ) |
Definition at line 310 of file InputManager.cpp.
bool Cogs::Core::InputManager::getActionState | ( | const StringView & | name | ) | const |
Get last action state for the given mapped action.
Definition at line 397 of file InputManager.cpp.
References Cogs::StringView::hash().
|
inline |
Definition at line 70 of file InputManager.h.
size_t Cogs::Core::InputManager::getAxisIndex | ( | InputDeviceState * | device, |
const StringView & | inputAxis | ||
) | const |
Definition at line 221 of file InputManager.cpp.
float Cogs::Core::InputManager::getAxisValue | ( | const StringView & | name | ) | const |
Get last value for the given mapped axis.
Definition at line 385 of file InputManager.cpp.
References Cogs::StringView::hash().
size_t Cogs::Core::InputManager::getButtonIndex | ( | InputDeviceState * | device, |
const StringView & | inputAction | ||
) | const |
Definition at line 267 of file InputManager.cpp.
|
private |
Definition at line 191 of file InputManager.cpp.
Cogs::Core::InputDeviceState & Cogs::Core::InputManager::getDevice | ( | InputDevices::EValues | deviceId | ) |
Definition at line 380 of file InputManager.cpp.
|
inline |
Definition at line 100 of file InputManager.h.
void Cogs::Core::InputManager::initialize | ( | ) |
Initialize the input managers default configuration.
Definition at line 80 of file InputManager.cpp.
void Cogs::Core::InputManager::lostFocus | ( | double | timestamp_ms | ) |
Definition at line 314 of file InputManager.cpp.
|
private |
Definition at line 159 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerKeyChar | ( | std::string | ch, |
double | timestamp_ms | ||
) |
Definition at line 373 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerKeyDown | ( | Key | key, |
double | timestamp_ms | ||
) |
Definition at line 359 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerKeyUp | ( | Key | key, |
double | timestamp_ms | ||
) |
Definition at line 366 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerMouseWheel | ( | int32_t | deltaValue, |
double | timestamp_ms | ||
) |
Definition at line 351 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerPointerMove | ( | PointerType | pointerType, |
PointerId | pointerId, | ||
const glm::ivec2 & | position, | ||
double | timestamp_ms | ||
) |
Definition at line 341 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerPointerPress | ( | PointerType | pointerType, |
PointerId | pointerId, | ||
MouseButton | button, | ||
const glm::ivec2 & | position, | ||
double | timestamp_ms | ||
) |
Definition at line 321 of file InputManager.cpp.
void Cogs::Core::InputManager::triggerPointerRelease | ( | PointerType | pointerType, |
PointerId | pointerId, | ||
MouseButton | button, | ||
const glm::ivec2 & | position, | ||
double | timestamp_ms | ||
) |
Definition at line 331 of file InputManager.cpp.
void Cogs::Core::InputManager::update | ( | ) |
Update the input state.
Definition at line 409 of file InputManager.cpp.
|
private |
Definition at line 565 of file InputManager.cpp.
|
private |
Definition at line 520 of file InputManager.cpp.
|
private |
Definition at line 444 of file InputManager.cpp.
|
private |
Definition at line 474 of file InputManager.cpp.
|
private |
Definition at line 169 of file InputManager.h.
|
private |
Definition at line 168 of file InputManager.h.
|
private |
Definition at line 166 of file InputManager.h.
|
staticconstexprprivate |
Definition at line 124 of file InputManager.h.
|
staticconstexprprivate |
Definition at line 125 of file InputManager.h.
|
private |
Definition at line 171 of file InputManager.h.
|
staticconstexprprivate |
Definition at line 121 of file InputManager.h.
|
staticconstexprprivate |
Definition at line 122 of file InputManager.h.
|
private |
Definition at line 173 of file InputManager.h.
|
private |
Definition at line 119 of file InputManager.h.
|
private |
Definition at line 117 of file InputManager.h.