#include <ControlMapper.h>
Public Member Functions | |
ControlMapper () | |
ControlMapper (const Bindings *pBindings, const AxisBindings *pAxisBindings) | |
virtual bool | handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) |
const Bindings * | getBindings () const |
void | setBindings (const Bindings *pBindings) |
const AxisBindings * | getAxisBindings () 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 | |
THandlerList & | getHandlerList (UINT orderIndex) |
THandlerList & | getOrCreateHandlerList (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 Bindings * | pBindings |
Pointer to keys/buttons mapping - Must not be NULL. | |
const AxisBindings * | pAxisBindings |
Pointer to axis mapping - Must not be NULL. | |
Handlers lists | |
Handlers are objects that can respond (or not) to a control. Notes :
| |
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 THandlerList & | getHandlerList (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 () |
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.
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.
Definition at line 105 of file ControlMapper.h.
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] |
typedef std::map<UINT, THandlerList> ControlMapper::THandlerListsList [protected] |
typedef std::pair<THandlerList *, THandlerList::iterator> ControlMapper::THandlerLocation [protected] |
Definition at line 199 of file ControlMapper.h.
Order indexes for control event handlers. The lower the value is, the higher the priority is.
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.
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.
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] |
void ControlMapper::enablePointerMouse | ( | ) | [inline] |
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.
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] |
Definition at line 267 of file ControlMapper.cpp.
References appHasFocus(), ASSERT, AXIS_MOUSE_MODIFIER, BUTTON_MOUSE_MODIFIER, computeMouseMovement(), DBG_TRY_BLOCK_END, DBG_TRY_BLOCK_START, getMousePosition(), ControlEvent::GFX_FRAME, ControlEvent::GFX_RESIZE, ControlState::NONE, pAxisBindings, pBindings, pointerMouse, prevMouseX, prevMouseY, processHandlerLists(), processHandlerListsOrAppend(), processHandlerListsOrAxisMove(), processHandlerListsOrDoSwitch(), sendUnmappedButtons, sendUnmappedKeyboard, ControlState::setPointer(), Controler::state, and Controler::vEvents.
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] |
Processes an external (networked) event. Method called upon event reception (usually on server).
Definition at line 179 of file ControlMapper.h.
References ASSERT, ControlEvent::AXIS, ControlEvent::getAxisId(), ControlEvent::getAxisMovement(), ControlEvent::getSwitchId(), ControlEvent::getTime(), ControlEvent::getType(), ControlEvent::getUnmappedKey(), ControlEvent::GFX_FRAME, ControlEvent::GFX_RESIZE, ControlEvent::SWITCH_DOWN, and ControlEvent::SWITCH_UP.
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.
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 | |||
) |
Definition at line 172 of file ControlMapper.cpp.
References getHandlerList(), LOG_ERROR, and ControlEventHandler::onRemovedFromControler().
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 | ) |
void ControlMapper::replaceHandler | ( | ControlEventHandler * | pOldHandler, | |
ControlEventHandler * | pNewHandler, | |||
UINT | orderIndex | |||
) |
Definition at line 182 of file ControlMapper.cpp.
References addHandlerBack(), ASSERT, getHandlerList(), ControlEventHandler::onAddedToControler(), ControlEventHandler::onRemovedFromControler(), removeHandler(), and THROW_TRACED_EXCEPTION.
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.
THandlerListsList ControlMapper::handlerLists [protected] |
Definition at line 192 of file ControlMapper.h.
Referenced by findHandler(), getHandlerList(), getOrCreateHandlerList(), processHandlerLists(), removeDeletedHandlers(), and removeHandlers().
const AxisBindings* ControlMapper::pAxisBindings [protected] |
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] |
float ControlMapper::prevMouseY [protected] |
bool ControlMapper::sendUnmappedButtons [protected] |
Indicates if the unmapped buttons (mouse or joystick) have to be sent.
Definition at line 233 of file ControlMapper.h.
Referenced by handle().
bool ControlMapper::sendUnmappedKeyboard [protected] |
Indicates if the unmapped keys of the keyboard have to be sent.
Definition at line 232 of file ControlMapper.h.
Referenced by handle().