Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
The class that acts as the main interface between the rest of the project and the input system. More...
#include <input_system.hpp>
Public Types | |
enum | ActionContextPriority : uint8_t { VERY_LOW =0 , LOW =1 , DEFAULT =2 , HIGH =3 , VERY_HIGH =4 , TOTAL =5 } |
The priority associated with an action context, which as yet has no real bearing on their evaluation. | |
Public Member Functions | |
void | queueInput (const SDL_Event &inputEvent) |
Maps an event to its internal representation, if one is available. | |
void | registerInputBind (const nlohmann::json &inputBindingParameters) |
The full description of an input binding, to be tracked and signaled by the InputManager. | |
void | registerAction (const nlohmann::json &actionParameters) |
Registers an action definition against a defined action context. | |
void | registerActionContext (const ::std::string &name, ActionContextPriority priority=DEFAULT) |
Registers a new action context with a given name. | |
void | unregisterActionContext (const ::std::string &name) |
Removes the action context associated with this name. | |
void | loadInputConfiguration (const nlohmann::json &inputConfiguration) |
Loads a full input configuration based on its JSON description. | |
ActionContext & | operator[] (const ::std::string &actionContext) |
Retrieves an action context based on its name. | |
::std::vector<::std::pair< ActionDefinition, ActionData > > | getTriggeredActions (uint32_t targetTimeMillis) |
Dispatches all mapped inputs received before the target time to action contexts that can handle them. | |
Private Member Functions | |
double | getRawValue (const InputFilter &inputFilter, const SDL_Event &inputEvent) const |
Get the value associated with a single InputFilter, a number between 0 and 1. | |
void | registerInputCombo (const ::std::string &actionContext, const InputCombo &inputCombo) |
Register a listener for a certain input combination on behalf of actionContext . | |
void | unregisterInputCombo (const ::std::string &actionContext, const InputCombo &inputCombo) |
Remove entry for a specific input within an action context. | |
void | unregisterInputCombos (const ::std::string &actionContext) |
void | unregisterInputCombos () |
Private Attributes | |
::std::unordered_map< ContextName, ::std::pair< ActionContext, ActionContextPriority > > | mActionContexts {} |
All action context names -> contexts. | |
::std::unordered_map< InputFilter, double > | mRawInputState {} |
The current, raw state of the control+axis associated with each input filter, each between 0.f and 1.f (button controls get 0.f and 1.f when unpressed and pressed respectively) | |
::std::unordered_map< InputFilter, ::std::set< InputCombo > > | mInputFilterToCombos {} |
All active input combinations associated with a given input. | |
::std::unordered_map< InputCombo, ::std::array< ::std::set< ContextName >, ActionContextPriority::TOTAL > > | mInputComboToActionContexts {} |
All action contexts associated with a given input combination, organized by priority. | |
::std::unordered_map< InputCombo, UnmappedInputValue > | mInputComboStates {} |
Input combination values, up to the most recently fired input trigger. | |
::std::queue<::std::pair< InputCombo, UnmappedInputValue > > | mUnmappedInputs {} |
Queue of input state changes, to be consumed by whichever action contexts require them. | |
float | mModifierThreshold { .7f } |
Button threshold for axes or buttons that map to modifiers, beyond which those modifiers are considered active (like buttons). | |
Friends | |
class | ActionContext |
The class that acts as the main interface between the rest of the project and the input system.
Processes raw SDL input events into unmapped inputs, and later reports bind value changes to an ActionContext for conversion into corresponding action events.
|
private |
Get the value associated with a single InputFilter, a number between 0 and 1.
Each InputFilter value, taken along with other InputFilter values, makes up the value for an InputCombo used in a binding.
inputFilter | The InputFilter this value corresponds to. |
inputEvent | The event used as the basis for the value for the InputFilter. |
void InputManager::loadInputConfiguration | ( | const nlohmann::json & | inputConfiguration | ) |
Loads a full input configuration based on its JSON description.
inputConfiguration | A JSON description of an input configuration. |
ActionContext & InputManager::operator[] | ( | const ::std::string & | actionContext | ) |
Retrieves an action context based on its name.
actionContext | The name of an ActionContext. |
void InputManager::queueInput | ( | const SDL_Event & | inputEvent | ) |
Maps an event to its internal representation, if one is available.
Called by the main thread at the start of every event loop. The kind of events supported are described in input_manager.cpp
void InputManager::registerAction | ( | const nlohmann::json & | actionParameters | ) |
Registers an action definition against a defined action context.
The action contains also a description of its type, axes, and other things. See for example:
actionParameters | The JSON representation of an ActionDefinition |
void InputManager::registerActionContext | ( | const ::std::string & | name, |
ActionContextPriority | priority = DEFAULT ) |
Registers a new action context with a given name.
Optionally takes an argument indicating the context's priority. ActionContextPriority determines when InputCombos for this context are evaluated relative to other contexts'.
This matters, for example, when a higher priority context resolving an action should prevent further action contexts from being evaluated.
There is no defined precedence for contexts within the same priority level.
void InputManager::registerInputBind | ( | const nlohmann::json & | inputBindingParameters | ) |
The full description of an input binding, to be tracked and signaled by the InputManager.
Such an input binding must name:
Example:
Modifiers 1 and 2 are non-sources, and are always considered active. The +dx of the main control, or motion in the +x axis of the mouse, is mapped to the +x axis of the action Camera Rotate.
inputBindingParameters | A JSON description of the relationship between an InputCombo and the action it maps to. |
|
private |
Remove all input binds.
|
private |
Remove entry for all inputs bound within an action context.
|
private |
Input combination values, up to the most recently fired input trigger.
If all modifiers for an InputCombo are active, then the main control alone determines the value of the combo as a whole. These are computed with InputFilter values.