Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::InputManager Class Reference

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.
 
ActionContextoperator[] (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, UnmappedInputValuemInputComboStates {}
 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
 

Detailed Description

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.

Member Function Documentation

◆ getRawValue()

double InputManager::getRawValue ( const InputFilter & inputFilter,
const SDL_Event & inputEvent ) const
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.

Parameters
inputFilterThe InputFilter this value corresponds to.
inputEventThe event used as the basis for the value for the InputFilter.
Returns
double The computed value for the InputFilter.

◆ loadInputConfiguration()

void InputManager::loadInputConfiguration ( const nlohmann::json & inputConfiguration)

Loads a full input configuration based on its JSON description.

See also
registerActionContext()
registerAction()
registerInputBind()
Parameters
inputConfigurationA JSON description of an input configuration.

◆ operator[]()

ActionContext & InputManager::operator[] ( const ::std::string & actionContext)

Retrieves an action context based on its name.

Parameters
actionContextThe name of an ActionContext.
Returns
ActionContext& A reference to the ActionContext.

◆ queueInput()

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

◆ registerAction()

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:

{
"attributes": {
"has_button_value": false,
"has_change_value": true,
"has_negative": false,
"has_state_value": false,
"n_axes": 2,
"state_is_location": false
},
"context": "Camera",
"name": "Rotate",
"value_type": "change"
}
See also
ActionDefinition
ActionData
Parameters
actionParametersThe JSON representation of an ActionDefinition

◆ registerActionContext()

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.

◆ registerInputBind()

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:

  • One InputCombo (some combination of axis values of different controls from attached input devices)
  • One ActionDefinition (the target action the input will (partly) populate)
  • One AxisFilter (axis of the action to which the source input combo is mapped)

Example:

{
"action": "Rotate",
"context": "Camera",
"input_combo": {
"deadzone": 0.0,
"main_control": {
"filter": "+dx",
"input_source": {
"control": 0,
"control_type": "point",
"device": 0,
"device_type": "mouse"
}
},
"modifier_1": {
"filter": "simple",
"input_source": {
"control": 0,
"control_type": "na",
"device": 0,
"device_type": "na"
}
},
"modifier_2": {
"filter": "simple",
"input_source": {
"control": 0,
"control_type": "na",
"device": 0,
"device_type": "na"
}
},
"threshold": 0.5,
"trigger": "on-change"
},
"target_axis": "+x"
}

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.

See also
InputCombo
ActionDefinition
ActionData
Parameters
inputBindingParametersA JSON description of the relationship between an InputCombo and the action it maps to.

◆ unregisterInputCombos() [1/2]

void InputManager::unregisterInputCombos ( )
private

Remove all input binds.

◆ unregisterInputCombos() [2/2]

void ToyMaker::InputManager::unregisterInputCombos ( const ::std::string & actionContext)
private

Remove entry for all inputs bound within an action context.

Member Data Documentation

◆ mInputComboStates

::std::unordered_map<InputCombo, UnmappedInputValue> ToyMaker::InputManager::mInputComboStates {}
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.

See also
mRawInputState

The documentation for this class was generated from the following files: