Class template that associates identifiers with dynamic actions. More...
Inherits NonCopyable.
Public Types | |
typedef EventSystem< ActionContext< ActionId >, ActionId > | CallbackSystem |
EventSystem to connect ActionMap with event listeners. | |
Public Member Functions | |
ActionMap () | |
Default constructor. | |
ActionMap (ActionMap &&source) | |
Move constructor. | |
ActionMap & | operator= (ActionMap &&source) |
Move assignment operator. | |
void | update (sf::Window &window) |
Clears old events and polls the window for new ones. More... | |
void | pushEvent (const sf::Event &event) |
Feeds the action map with a SFML event, that can be used during the current frame. More... | |
void | clearEvents () |
Removes the events that have been temporarily stored. More... | |
Action & | operator[] (const ActionId &id) |
Returns the action associated with a given action identifier. More... | |
void | removeAction (const ActionId &id) |
Remove the action associated with the specified id. | |
void | clearActions () |
Removes all actions associated with this map. | |
bool | isActive (const ActionId &id) const |
Returns whether the action associated with the specified identifier is currently in effect. More... | |
void | invokeCallbacks (CallbackSystem &system, sf::Window *window) const |
Forwards active actions to a callback system. More... | |
Class template that associates identifiers with dynamic actions.
You can use this template to map identifiers like strings or enumerators to a specific combination of SFML events (sf::Event) and real time input states (sf::Mouse, sf::Keyboard, sf::Joystick). After the initialization, isActive() provides an easy way to check whether a specified identifier is associated with an active action. Furthermore, it is possible to map the actions to callbacks, which can be achieved with InvokeCallbacks().
ActionId | The type of ID you want to map to actions. This can be a string, an enum, or anything with a < operator and value semantics. |
void thor::ActionMap< ActionId >::clearEvents | ( | ) |
Removes the events that have been temporarily stored.
You only need this function in combination with pushEvent(), if you want to feed the action map manually with events. Otherwise, you can just call update().
void thor::ActionMap< ActionId >::invokeCallbacks | ( | CallbackSystem & | system, |
sf::Window * | window | ||
) | const |
Forwards active actions to a callback system.
system | Callback system of type EventSystem< ActionContext<ActionId>, ActionId > |
window | Window pointer which is stored in the ActionContext passed to the callbacks. Can be nullptr. |
For every action that is currently active, the action ID is passed to system, where all listener functions associated with the ID are invoked. For a given action registered in the action map, the callback system is invoked at most once, even if the action has been combined with logical operators and multiple sub-actions are active. That is, an action Shift&&X won't lead to an invocation for both Shift and X. This is the expected behavior.
bool thor::ActionMap< ActionId >::isActive | ( | const ActionId & | id | ) | const |
Returns whether the action associated with the specified identifier is currently in effect.
To be in effect, the boolean operation of the assigned action must yield true. Note that in contrast to registered callbacks, isActive() doesn't take into account the situation where multiple events of the same type occur in a single frame.
Action& thor::ActionMap< ActionId >::operator[] | ( | const ActionId & | id | ) |
Returns the action associated with a given action identifier.
Use this function to create new associations. If the action id hasn't been stored yet, it is inserted and an empty action is returned. Assign an object of type thor::Action to it. Example:
void thor::ActionMap< ActionId >::pushEvent | ( | const sf::Event & | event | ) |
Feeds the action map with a SFML event, that can be used during the current frame.
When you use the update() method, you needn't invoke pushEvent(). This method exists for more flexibility: You can push user-defined events, and you can do something else with the polled events before calling pushEvent().
void thor::ActionMap< ActionId >::update | ( | sf::Window & | window | ) |