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::ActionDispatch Class Reference

An object responsible for tracking action listeners for a given project. More...

#include <input_system.hpp>

Public Member Functions

void registerActionHandler (const QualifiedActionName &contextActionPair, ::std::weak_ptr< IActionHandler > actionHandler)
 Registers a handler for an action.
 
void unregisterActionHandler (const QualifiedActionName &contextActionPair, ::std::weak_ptr< IActionHandler > actionHandler)
 Removes a handler for a particular action.
 
void unregisterActionHandler (::std::weak_ptr< IActionHandler > actionHandler)
 Removes an action handler from all its subscribed actions.
 
bool dispatchAction (const ::std::pair< ActionDefinition, ActionData > &pendingAction)
 Sends data for an action to all of that action's registered handlers.
 

Private Attributes

::std::map< QualifiedActionName, ::std::set<::std::weak_ptr< IActionHandler >, ::std::owner_less<::std::weak_ptr< IActionHandler > > >, ::std::less< QualifiedActionName > > mActionHandlers {}
 Pointers to all action handler instances waiting for a particular action.
 

Detailed Description

An object responsible for tracking action listeners for a given project.

Triggered actions created by ActionContext do not actually reach their intended listeners until they have been (manually) sent via an ActionDispatch object. This affords developers some control over when and where actions are received.

In the engine's scene system, for example, while every ViewportNode has an associated ActionDispatch object, descendant viewports do not see triggered actions unless their parent viewports allow actions to propagate to them.

Usage:

class ViewportNode: public BaseSceneNode<ViewportNode>, public Resource<ViewportNode> {
// ...
ActionDispatch mActionDispatch {};
// ...
};
// ...
// This viewport method receives an action somehow, and then ...
bool ViewportNode::handleAction(std::pair<ActionDefinition, ActionData> pendingAction) {
// ...
// ... sends it along to any action listeners it has.
bool actionHandled { false };
actionHandled = mActionDispatch.dispatchAction(pendingAction);
// ...
}
An object responsible for tracking action listeners for a given project.
Definition input_system.hpp:586
bool dispatchAction(const ::std::pair< ActionDefinition, ActionData > &pendingAction)
Sends data for an action to all of that action's registered handlers.
Definition action_context.cpp:269
A CRTP template for all the scene node types present in the project.
Definition scene_system.hpp:699
The base class for any type whose creation and storage should be managed by the ResourceDatabase.
Definition resource_database.hpp:372
A type of node capable of and responsible for interacting sensibly with the engine's RenderSystem and...
Definition scene_system.hpp:844
bool handleAction(std::pair< ActionDefinition, ActionData > pendingAction)
Handles an action received by this viewport, generally by dispatching it to subscribed listeners and ...
Definition scene_system.cpp:896

Member Function Documentation

◆ dispatchAction()

bool ActionDispatch::dispatchAction ( const ::std::pair< ActionDefinition, ActionData > & pendingAction)

Sends data for an action to all of that action's registered handlers.

Parameters
pendingActionThe full action, including its definition and data.
Return values
trueThe action was handled by one of this ActionDispatch's subscribers.
falseThe action was not handled by any of this ActionDispatch's subscribers.

◆ registerActionHandler()

void ActionDispatch::registerActionHandler ( const QualifiedActionName & contextActionPair,
::std::weak_ptr< IActionHandler > actionHandler )

Registers a handler for an action.

Parameters
contextActionPairThe full name of the action.
actionHandlerA pointer to the action handler.

◆ unregisterActionHandler() [1/2]

void ToyMaker::ActionDispatch::unregisterActionHandler ( ::std::weak_ptr< IActionHandler > actionHandler)

Removes an action handler from all its subscribed actions.

Parameters
actionHandlerA pointer to the action handler.

◆ unregisterActionHandler() [2/2]

void ToyMaker::ActionDispatch::unregisterActionHandler ( const QualifiedActionName & contextActionPair,
::std::weak_ptr< IActionHandler > actionHandler )

Removes a handler for a particular action.

Parameters
contextActionPairThe full name of the action.
actionHandlerA pointer to the action handler.

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