Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
A container for actions that make sense within a given context. More...
#include <input_system.hpp>
Public Member Functions | |
ActionContext (InputManager &inputManager, const ContextName &name) | |
Construct a new action context. | |
ActionContext (InputManager &&inputManager, const ContextName &name)=delete | |
Construct a new action context. | |
::std::vector<::std::pair< ActionDefinition, ActionData > > | getTriggeredActions () |
Returns a list of triggered actions following input mapping in this context. | |
void | registerAction (const ActionName &name, InputAttributesType attributes) |
Creates an action and specifies its attributes. | |
void | registerAction (const nlohmann::json &actionParameters) |
Creates an action and specifies its attributes based on its JSON description. | |
void | unregisterAction (const ActionName &name) |
Removes an action from this context. | |
void | registerInputBind (const ActionName &forAction, AxisFilter targetAxis, const InputCombo &withInput) |
Register a binding from an input-sign-axis-modifiers combination to a specific axis of an action. | |
void | registerInputBind (const nlohmann::json &inputBindParameters) |
Register a binding from an input-sign-axis-modifiers combination to a specific axis of an action. | |
void | unregisterInputBind (const InputCombo &inputCombo) |
Remove the binding from this input-sign-axis-modifier combination to whatever action it's bound to. | |
void | unregisterInputBinds (const ActionName &forAction) |
Removes all input binds associated with a particular action. | |
void | unregisterInputBinds () |
Removes all input combo -> action-axis bindings. | |
bool | propagateAllowed () |
Checks whether this context allows propagation to lower priority contexts. | |
void | setPropagateAllowed (bool allowPropagate) |
Enables or disables input propagation to lower priority contexts. | |
bool | enabled () |
Checks whether this context is active and able to process input events. | |
void | setEnabled (bool enable) |
Enable or disable this context, allowing it to or preventing it from receiving input events. | |
Static Public Member Functions | |
static ActionData | ApplyInput (const ActionDefinition &actionDefinition, const ActionData &actionData, const AxisFilter targetAxis, const UnmappedInputValue &inputValue) |
Returns the result of applying an unmapped input combo value to its target action-axis. | |
Private Member Functions | |
void | resetActionData (const ActionName &forAction, uint32_t timestamp) |
Sets action data for this action to 0.f or false, and queues a corresponding RESET action. | |
void | resetActionData (uint32_t timestamp) |
Sets all action data to 0.f or false for ALL actions, and queues related RESET actions. | |
void | mapToAction (const UnmappedInputValue &inputValue, const InputCombo &inputCombo) |
Maps the given input value to its assigned action state. | |
Private Attributes | |
InputManager & | mInputManager |
const ContextName | mName |
The name of this action context. | |
bool | mEnabled { true } |
Determines whether this action context is active and allowed to process any bound input events. | |
bool | mPropagateInput { false } |
Determines whether, after mapping an input event to its corresponding action, other contexts waiting for the input event are allowed to have a go at processing it also. | |
::std::unordered_map< ActionDefinition, ActionData > | mActions {} |
All actions defined for this context and their most recently triggered state. | |
::std::vector<::std::pair< ActionDefinition, ActionData > > | mPendingTriggeredActions {} |
Action state changes that have recently been triggered, in the order that they were triggered. | |
::std::unordered_map< ActionDefinition, ::std::set< InputCombo > > | mActionToInputBinds {} |
All input bindings associated with a specific action. | |
::std::unordered_map< InputCombo, ::std::pair< AxisFilter, ActionDefinition > > | mInputBindToAction {} |
Mapping from unmapped input controls, provided by the input manager, to their associated action definitions. | |
Friends | |
class | InputManager |
A container for actions that make sense within a given context.
Different contexts might have different requirements, even with the same set of inputs. For example, it might make sense to have a "slash" action in the game world, but in the context of a game menu, slash cannot have meaning.
Action Contexts turn those requirements into a container object, where the semantics of an input event are indicated by the action and context, and are one degree removed from the inputs themselves.
This can be useful, for example, when a game requires input for character movement across multiple platforms. For a console, or when a controller is present, it would make sense to query the value of the left analog stick. However, no such control exists on a keyboard, which is the most common input device for a PC.
Action Contexts, among other things, allow it so that multiple mappings to the same type of input are possible, and the handlers of the input don't have to reason about differences in platforms. In the example above, that mapping might look something like this:
This allows developers to reason about input somewhat uniformly during game development. The input mappings themselves are a matter of wiring inputs to high level actions during configuration, separate from game logic.
In this case, all a game programmer need know is that they want signed non-location state input on 2 axes, and that they want it for "Move".
|
inline |
Construct a new action context.
inputManager | The input manager in charge of this context. |
name | The name of the context. |
|
delete |
Construct a new action context.
inputManager | The input manager in charge of this context. |
name | The name of the context. |
|
static |
Returns the result of applying an unmapped input combo value to its target action-axis.
actionDefinition | Action definition of target action (but usually just a context-action name string pair). |
actionData | The previous value of the data associated with the action. |
targetAxis | The axis of the action affected. |
inputValue | The value associated with the input combo being applied. |
std::vector< std::pair< ActionDefinition, ActionData > > ActionContext::getTriggeredActions | ( | ) |
Returns a list of triggered actions following input mapping in this context.
|
private |
Maps the given input value to its assigned action state.
inputValue | The value of the input combo to be mapped to an axis of an action belonging to this action's context. |
inputCombo | The combo whose value is being mapped. |
|
inline |
Checks whether this context allows propagation to lower priority contexts.
true | Allows propagation to lower priority contexts; |
false | Disallows propagation to lower priority contexts; |
void ActionContext::registerAction | ( | const ActionName & | name, |
InputAttributesType | attributes ) |
Creates an action and specifies its attributes.
name | The name of the action. |
attributes | The attributes of the action (no. of axes, state or change, etc.) |
void ActionContext::registerAction | ( | const nlohmann::json & | actionParameters | ) |
Creates an action and specifies its attributes based on its JSON description.
actionParameters | The action's description in JSON. |
void ActionContext::registerInputBind | ( | const ActionName & | forAction, |
AxisFilter | targetAxis, | ||
const InputCombo & | withInput ) |
Register a binding from an input-sign-axis-modifiers combination to a specific axis of an action.
forAction | The action being mapped to. |
targetAxis | The axis of the action affected. |
withInput | The combo responsible for changing the action's value. |
void ActionContext::registerInputBind | ( | const nlohmann::json & | inputBindParameters | ) |
Register a binding from an input-sign-axis-modifiers combination to a specific axis of an action.
inputBindParameters | A JSON description of the input bind. |
|
private |
Sets action data for this action to 0.f or false, and queues a corresponding RESET action.
forAction | The action whose vlaue is being reset. |
timestamp | The time of the reset, in milliseconds since application start. |
|
private |
Sets all action data to 0.f or false for ALL actions, and queues related RESET actions.
timestamp | The time of the reset, in milliseconds since application start. |
|
inline |
Enables or disables input propagation to lower priority contexts.
allowPropagate | Whether propagation is permitted (for handled actions) |
void ActionContext::unregisterAction | ( | const ActionName & | name | ) |
Removes an action from this context.
name | The name of the action being removed. |
void ActionContext::unregisterInputBind | ( | const InputCombo & | inputCombo | ) |
Remove the binding from this input-sign-axis-modifier combination to whatever action it's bound to.
inputCombo | The combo of the input bind being removed. |
void ActionContext::unregisterInputBinds | ( | const ActionName & | forAction | ) |
Removes all input binds associated with a particular action.
forAction | The action whose input binds are being removed. |