ControlMapper Class Reference

Interface between input (keys) and controls (orders). More...

#include <ControlMapper.h>

Inheritance diagram for ControlMapper:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 ControlMapper ()
 ControlMapper (const Bindings *pBindings, const AxisBindings *pAxisBindings)
virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
const BindingsgetBindings () const
void setBindings (const Bindings *pBindings)
const AxisBindingsgetAxisBindings () const
void setAxisBindings (const AxisBindings *pAxisBindings)
void setBindings (const Bindings *pBindings, const AxisBindings *pAxisBindings)
Mouse pointer options
bool isPointerMouse ()
 Indicates if the mouse is a standard pointer (true) or a game axis (false).
void enablePointerMouse ()
 Sets the mouse to be a standard pointer.
void disablePointerMouse ()
 Sets the mouse to be a game axis (like a joystick).
void computePickPos (osgViewer::View &view, osg::NodePath *pPickNodePath=NULL)
 Updates the pick position (for a mouse pointer) of the Controller's state.
Unmapped switches options
Defines if the unmapped keys of the keyboard have to be processed as mapped keys.

void setSendUnmappedKeyboard (bool state)
void setSendUnmappedButtons (bool state)
 Defines if the unmapped buttons (mouse or joystick) have to be processed as mapped buttons.
bool getSendUnmappedKeyboard () const
 Indicates if the unmapped keys of the keyboard have to be processed as mapped keys.
bool getSendUnmappedButtons () const
 Indicates if the unmapped buttons (mouse or joystick) have to be processed as mapped buttons.
Networking
void onControlEventReceived (const ControlEvent &ce)
 Processes an external (networked) event. Method called upon event reception (usually on server).

Protected Types

typedef std::pair< UINT,
THandlerList
THandlerListP
 Handler list with an order index.
typedef std::map< UINT,
THandlerList
THandlerListsList
 List of lists with their priorities.
typedef std::pair
< THandlerList
*, THandlerList::iterator > 
THandlerLocation

Protected Member Functions

THandlerListgetHandlerList (UINT orderIndex)
THandlerListgetOrCreateHandlerList (UINT orderIndex)
 Gets the handler list with the given order index, creating it if necessary.
THandlerLocation findHandler (ControlEventHandler *pHandler)
bool processHandlerLists (const ControlEvent &ce)
 Process all handlers, and returns true if handled, false if not.
void removeDeletedHandlers ()
bool processHandlerListsOrAppend (const ControlEvent &ce)
 Process all handlers, and add to vEvents if not handled.
void processHandlerListsOrDoSwitch (double curTime, ControlState::ESwitchId switchId, int unmappedKey, bool pushed)
 Push down or release a switch if not handled.
void processHandlerListsOrAxisMove (double curTime, ControlState::EAxisId axisId, float movement)
 Do as if an axis was moved if not handled.
float computeMouseMovement (float mouseDiff, const AxisControl &ac)
 Computes mouse axis movement (applies acceleration, sensitivity...) for a non pointer (= game axis) mouse.

Protected Attributes

THandlerListsList handlerLists
bool pointerMouse
 Indicates if the mouse is a standard pointer (true) or a game axis (false).
bool sendUnmappedKeyboard
 Indicates if the unmapped keys of the keyboard have to be sent.
bool sendUnmappedButtons
 Indicates if the unmapped buttons (mouse or joystick) have to be sent.
float prevMouseX
float prevMouseY
const BindingspBindings
 Pointer to keys/buttons mapping - Must not be NULL.
const AxisBindingspAxisBindings
 Pointer to axis mapping - Must not be NULL.

Handlers lists

Handlers are objects that can respond (or not) to a control.

Notes :

  • The control mapper does not own ControlEventHandler's.
  • There are as many handler lists as existing priorities.


enum  EHandlerOrderIndexes { HANDLER_ORDER_CRITICAL, HANDLER_ORDER_MENU, HANDLER_ORDER_UNIT }
 Order indexes for control event handlers. The lower the value is, the higher the priority is. More...
typedef std::vector
< osg::observer_ptr
< ControlEventHandler > > 
THandlerList
const THandlerListgetHandlerList (UINT orderIndex) const
 Gets the handler list with the given order index.
void addHandlerBack (ControlEventHandler *pHandler, UINT orderIndex)
 Adds a handler at the end of the given order index list. Creates the list if it doesn't exist.
void removeHandler (ControlEventHandler *pHandler)
 Adds a handler at the beginning of the given order index list. Creates the list if it doesn't exist.
void removeHandler (ControlEventHandler *pHandler, UINT orderIndex)
void removeHandlers (UINT orderIndex)
void replaceHandler (ControlEventHandler *pOldHandler, ControlEventHandler *pNewHandler, UINT orderIndex)
void clearHandlers ()


Detailed Description

Interface between input (keys) and controls (orders).

This class is just here to retreive inputs and map them to controls (keeping up-to-date conrols states), and to store events. It allows client classes to know only about controls, regardless of the keyboard layout (English, French, German, and so on), the key mapping, or the parameters on axis (Such as acceleration and sensitivity). IMPORTANT NOTE : the control mapper does NOT relay mouse movement events, because it updates mouse mouvement on each GFX frame. The control mapper also have front handler lists, which will receive controls first. If no one handles the control event, then it will be stored in the mapper.

Todo:
Redesign this class for support of multiple players (each binding is associated to a player). Idea : store controls in an external Controler (remove derivation). Idea 2 : simply use a control mapper per player, and cascade them.

Must be thread safe, for almost every access.

[Platforms: All but Win32] Keeps grabing the mouse even when app doesn't have the focus. See appHasFocus() in ControlMapper.cpp.

See also:
This class is part of the Driven manipulator system. See also ControlState and ControlEvent
Author:
Sukender
Version:
0.2.0

Definition at line 105 of file ControlMapper.h.


Member Typedef Documentation

typedef std::vector<osg::observer_ptr<ControlEventHandler> > ControlMapper::THandlerList

Definition at line 119 of file ControlMapper.h.

typedef std::pair<UINT, THandlerList> ControlMapper::THandlerListP [protected]

Handler list with an order index.

Definition at line 190 of file ControlMapper.h.

typedef std::map<UINT, THandlerList> ControlMapper::THandlerListsList [protected]

List of lists with their priorities.

Definition at line 191 of file ControlMapper.h.

typedef std::pair<THandlerList *, THandlerList::iterator> ControlMapper::THandlerLocation [protected]

Definition at line 199 of file ControlMapper.h.


Member Enumeration Documentation

Order indexes for control event handlers. The lower the value is, the higher the priority is.

Enumerator:
HANDLER_ORDER_CRITICAL  Order index for critical control events.
HANDLER_ORDER_MENU  Order index for standard menus.
HANDLER_ORDER_UNIT  Order index for units and standard player input.

Definition at line 125 of file ControlMapper.h.


Constructor & Destructor Documentation

ControlMapper::ControlMapper (  )  [inline]

Definition at line 107 of file ControlMapper.h.

ControlMapper::ControlMapper ( const Bindings pBindings,
const AxisBindings pAxisBindings 
) [inline]

Definition at line 109 of file ControlMapper.h.


Member Function Documentation

void ControlMapper::addHandlerBack ( ControlEventHandler pHandler,
UINT  orderIndex 
) [inline]

Adds a handler at the end of the given order index list. Creates the list if it doesn't exist.

Definition at line 132 of file ControlMapper.h.

References ControlEventHandler::onAddedToControler().

Referenced by replaceHandler().

void ControlMapper::clearHandlers (  )  [inline]

Definition at line 139 of file ControlMapper.h.

float ControlMapper::computeMouseMovement ( float  mouseDiff,
const AxisControl ac 
) [protected]

Computes mouse axis movement (applies acceleration, sensitivity...) for a non pointer (= game axis) mouse.

Definition at line 414 of file ControlMapper.cpp.

References AxisControl::accel, copySign(), AxisControl::deadzone, and AxisControl::sensitivity.

Referenced by handle().

void ControlMapper::computePickPos ( osgViewer::View &  view,
osg::NodePath *  pPickNodePath = NULL 
)

Updates the pick position (for a mouse pointer) of the Controller's state.

Definition at line 430 of file ControlMapper.cpp.

References ASSERT, ControlState::getPointerX(), ControlState::getPointerY(), ControlState::setPickPosition(), and Controler::state.

void ControlMapper::disablePointerMouse (  )  [inline]

Sets the mouse to be a game axis (like a joystick).

Definition at line 156 of file ControlMapper.h.

void ControlMapper::enablePointerMouse (  )  [inline]

Sets the mouse to be a standard pointer.

Definition at line 154 of file ControlMapper.h.

ControlMapper::THandlerLocation ControlMapper::findHandler ( ControlEventHandler pHandler  )  [protected]

Definition at line 153 of file ControlMapper.cpp.

References handlerLists.

Referenced by removeHandler().

const AxisBindings* ControlMapper::getAxisBindings (  )  const [inline]

Definition at line 144 of file ControlMapper.h.

const Bindings* ControlMapper::getBindings (  )  const [inline]

Definition at line 142 of file ControlMapper.h.

ControlMapper::THandlerList & ControlMapper::getHandlerList ( UINT  orderIndex  )  [protected]

Definition at line 131 of file ControlMapper.cpp.

References handlerLists, and THROW_TRACED_FMT_EXCEPTION.

const ControlMapper::THandlerList & ControlMapper::getHandlerList ( UINT  orderIndex  )  const

Gets the handler list with the given order index.

Exceptions:
TracedException if list with the given order index doesn't exist.

Definition at line 137 of file ControlMapper.cpp.

References handlerLists, and THROW_TRACED_FMT_EXCEPTION.

Referenced by removeHandler(), and replaceHandler().

ControlMapper::THandlerList & ControlMapper::getOrCreateHandlerList ( UINT  orderIndex  )  [protected]

Gets the handler list with the given order index, creating it if necessary.

Definition at line 143 of file ControlMapper.cpp.

References ASSERT, and handlerLists.

bool ControlMapper::getSendUnmappedButtons (  )  const [inline]

Indicates if the unmapped buttons (mouse or joystick) have to be processed as mapped buttons.

In that case, an event with the ControlState::NONE switch will be send.

Definition at line 172 of file ControlMapper.h.

bool ControlMapper::getSendUnmappedKeyboard (  )  const [inline]

Indicates if the unmapped keys of the keyboard have to be processed as mapped keys.

In that case, an event with the ControlState::NONE switch will be send.

Definition at line 169 of file ControlMapper.h.

bool ControlMapper::handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  aa 
) [virtual]

bool ControlMapper::isPointerMouse (  )  [inline]

Indicates if the mouse is a standard pointer (true) or a game axis (false).

Definition at line 152 of file ControlMapper.h.

void ControlMapper::onControlEventReceived ( const ControlEvent ce  )  [inline]

bool ControlMapper::processHandlerLists ( const ControlEvent ce  )  [protected]

Process all handlers, and returns true if handled, false if not.

Definition at line 234 of file ControlMapper.cpp.

References DBG_TRY_BLOCK_END, DBG_TRY_BLOCK_START, handlerLists, Controler::pConnection, and removeDeletedHandlers().

Referenced by handle().

bool ControlMapper::processHandlerListsOrAppend ( const ControlEvent ce  )  [inline, protected]

Process all handlers, and add to vEvents if not handled.

Returns:
true if the event has been handled or sent.

Definition at line 209 of file ControlMapper.h.

Referenced by handle().

void ControlMapper::processHandlerListsOrAxisMove ( double  curTime,
ControlState::EAxisId  axisId,
float  movement 
) [inline, protected]

Do as if an axis was moved if not handled.

Definition at line 221 of file ControlMapper.h.

Referenced by handle().

void ControlMapper::processHandlerListsOrDoSwitch ( double  curTime,
ControlState::ESwitchId  switchId,
int  unmappedKey,
bool  pushed 
) [inline, protected]

Push down or release a switch if not handled.

Definition at line 214 of file ControlMapper.h.

Referenced by handle().

void ControlMapper::removeDeletedHandlers (  )  [protected]

Definition at line 216 of file ControlMapper.cpp.

References handlerLists.

Referenced by processHandlerLists().

void ControlMapper::removeHandler ( ControlEventHandler pHandler,
UINT  orderIndex 
)

void ControlMapper::removeHandler ( ControlEventHandler pHandler  ) 

Adds a handler at the beginning of the given order index list. Creates the list if it doesn't exist.

Definition at line 163 of file ControlMapper.cpp.

References findHandler(), LOG_ERROR, and ControlEventHandler::onRemovedFromControler().

Referenced by replaceHandler().

void ControlMapper::removeHandlers ( UINT  orderIndex  ) 

Definition at line 207 of file ControlMapper.cpp.

References handlerLists.

void ControlMapper::replaceHandler ( ControlEventHandler pOldHandler,
ControlEventHandler pNewHandler,
UINT  orderIndex 
)

void ControlMapper::setAxisBindings ( const AxisBindings pAxisBindings  )  [inline]

Definition at line 145 of file ControlMapper.h.

void ControlMapper::setBindings ( const Bindings pBindings,
const AxisBindings pAxisBindings 
) [inline]

Definition at line 146 of file ControlMapper.h.

void ControlMapper::setBindings ( const Bindings pBindings  )  [inline]

Definition at line 143 of file ControlMapper.h.

void ControlMapper::setSendUnmappedButtons ( bool  state  )  [inline]

Defines if the unmapped buttons (mouse or joystick) have to be processed as mapped buttons.

Definition at line 166 of file ControlMapper.h.

void ControlMapper::setSendUnmappedKeyboard ( bool  state  )  [inline]

Definition at line 164 of file ControlMapper.h.


Member Data Documentation

Pointer to axis mapping - Must not be NULL.

Definition at line 238 of file ControlMapper.h.

Referenced by handle().

const Bindings* ControlMapper::pBindings [protected]

Pointer to keys/buttons mapping - Must not be NULL.

Definition at line 237 of file ControlMapper.h.

Referenced by handle().

bool ControlMapper::pointerMouse [protected]

Indicates if the mouse is a standard pointer (true) or a game axis (false).

Definition at line 231 of file ControlMapper.h.

Referenced by handle().

float ControlMapper::prevMouseX [protected]

Definition at line 235 of file ControlMapper.h.

Referenced by handle().

float ControlMapper::prevMouseY [protected]

Definition at line 235 of file ControlMapper.h.

Referenced by handle().

Indicates if the unmapped buttons (mouse or joystick) have to be sent.

Definition at line 233 of file ControlMapper.h.

Referenced by handle().

Indicates if the unmapped keys of the keyboard have to be sent.

Definition at line 232 of file ControlMapper.h.

Referenced by handle().


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

Generated on Sun Jan 17 11:39:27 2010 for PVLE (Pro-Vocation Light Engine) by  doxygen 1.5.9