VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | Protected Member Functions | List of all members
InputRouter Class Reference

Routes ControllerEvents according to inherent ControllerFactory specifications. More...

Inheritance diagram for InputRouter:
GamepadRouter KeyboardRouter TouchNavigationRouter

Public Member Functions

void onControllerDisconnect (int deviceId)
 Notifies the ControllerManager of device disconnections for all VirtualControllers associated with the specified deviceId. More...
 
virtual bool routeControllerEvent (ControllerEvent *event)
 Routes the given ControllerEvent. More...
 

Protected Member Functions

 InputRouter ()
 Constructs an empty InputRouter. More...
 
bool conflictsWithExistingFactories (const ControllerFactory &factory) const
 Returns whether or not factory conficts (i.e. intersects) with ControllerFactorys previously added to this router. More...
 
bool hasFactoryRoutes () const
 Returns whether or not this InputRouter contains any ControllerFactorys to route by. More...
 
void addControllerFactory (ControllerFactory *factory)
 Adds a ControllerFactory to route by. More...
 
void clearFactories ()
 Clears all ControllerFactorys used for routing by this InputRouter. More...
 

Detailed Description

Routes ControllerEvents according to inherent ControllerFactory specifications.

InputRouter represents an additional layer of input abstraction on top of ControllerManager to allow events to be routed to different VirtualController instances rather than just according to a 1:1 mapping on deviceId. This is accomplished by using an intermediate layer of fake deviceIds. As a result, this allows splitting one device into many based on InputSchemes that compromise the resident ControllerFactorys.

Note
InputRouter implicitly handles both single (e.g. built in keyboard on Mac) and multi (e.g. connected gamepads on Android) instance devices.
By convention, all implementations of this interface should make the router a singleton by implementing a getInstance() method.

Constructor & Destructor Documentation

InputRouter::InputRouter ( )
protected

Constructs an empty InputRouter.

Member Function Documentation

void InputRouter::addControllerFactory ( ControllerFactory factory)
protected

Adds a ControllerFactory to route by.

Note
This method transfers ownership of the factory memory to this InputRouter.
Parameters
factoryControllerFactory to add to the InputRouter
void InputRouter::clearFactories ( )
protected

Clears all ControllerFactorys used for routing by this InputRouter.

bool InputRouter::conflictsWithExistingFactories ( const ControllerFactory factory) const
protected

Returns whether or not factory conficts (i.e. intersects) with ControllerFactorys previously added to this router.

Parameters
factoryControllerFactory to check for conflict
bool InputRouter::hasFactoryRoutes ( ) const
inlineprotected

Returns whether or not this InputRouter contains any ControllerFactorys to route by.

void InputRouter::onControllerDisconnect ( int  deviceId)

Notifies the ControllerManager of device disconnections for all VirtualControllers associated with the specified deviceId.

Parameters
deviceIdId of the device that disconnected. If the deviceId is negative, the device is assumed to be a singleton.
virtual bool InputRouter::routeControllerEvent ( ControllerEvent event)
virtual

Routes the given ControllerEvent.

Returns
true if the event was both routed properly and handled.
Note
Events without a deviceId are considered to be from singleton devices (i.e. devices for which there exists only a single global instance). Events with a deviceId are considered to be a possible multi-instance device.
ControllerEvents are currently manipulated which may affect subsequent routing.