orxonox::InputManager Class Reference

Captures and distributes mouse and keyboard input. More...

#include <src/core/input/InputManager.h>

Inheritance diagram for orxonox::InputManager:

orxonox::OrxonoxClass OIS::KeyListener OIS::MouseListener OIS::JoyStickListener

List of all members.

Public Types

enum  InputManagerState {
  Uninitialised = 0x00, OISReady = 0x01, InternalsReady = 0x02, Ticking = 0x04,
  Calibrating = 0x08, ReloadRequest = 0x10, JoyStickSupport = 0x20
}

Public Member Functions

void clearBuffers ()
 Clears all buffers that store what keys/buttons are being pressed at the moment.
template<class T>
T * createInputState (const std::string &name, bool bAlwaysGetsInput=false, bool bTransparent=false, InputStatePriority priority=InputStatePriority::Dynamic)
 Creates a new InputState by type, name and priority.
InputStategetCurrentState ()
 Returns the current input state (there might be others active too!).
InputStategetState (const std::string &name)
 Returns the pointer to the requested InputState.
void initialise (size_t windowHnd, int windowWidth, int windowHeight, bool joyStickSupport=true)
 Creates the OIS::InputMananger, the keyboard, the mouse and the joysticks and assigns the key bindings.
 InputManager ()
 Constructor only sets member fields to initial zero values and registers the class in the class hierarchy.
unsigned int numberOfJoySticks ()
unsigned int numberOfKeyboards ()
unsigned int numberOfMice ()
void reloadInputSystem (bool joyStickSupport=true)
 Public interface. Only reloads immediately if the call stack doesn't include the update() method.
bool requestDestroyState (const std::string &name)
 Removes and destroys an input state internally.
bool requestEnterState (const std::string &name)
 Activates a specific input state. It might not be really activated if the priority is too low!
bool requestLeaveState (const std::string &name)
 Deactivates a specific input state.
void setKeyDetectorCallback (const std::string &command)
 Sets the the name of the command used by the KeyDetector as callback.
void setWindowExtents (const int width, const int height)
 Adjusts the mouse window metrics. This method has to be called every time the size of the window changes.
void update (const Clock &time)
 Updates the states and the InputState situation.
 ~InputManager ()
 Destroys all the created input devices and states.

Static Public Member Functions

static void calibrate ()
 Starts joy stick calibration.
static InputManagergetInstance ()
static InputManagergetInstancePtr ()
static void reload (bool joyStickSupport=true)
 Reloads the input system.

Static Public Attributes

static EmptyHandler EMPTY_HANDLER
static const unsigned int sliderAxes = 8

Private Member Functions

void _calibrationFileCallback ()
 Callback for the joy stick calibration config file.
void _clearBuffers ()
void _completeCalibration ()
bool _configureInputState (InputState *state, const std::string &name, bool bAlwaysGetsInput, bool bTransparent, int priority)
 Adds a new key handler.
void _configureJoySticks ()
 Sets the size of all the different lists that are dependent on the number of joy stick devices created and loads the joy stick calibration.
void _destroyJoySticks ()
 Destroys all the joy sticks and resizes the lists to 0.
void _destroyKeyboard ()
 Destroys the keyboard and sets it to 0.
void _destroyMouse ()
 Destroys the mouse and sets it to 0.
void _destroyState (InputState *state)
 Removes and destroys an InputState.
void _evaluateCalibration ()
void _fireAxis (unsigned int iJoyStick, int axis, int value)
 Calls the states for a particular axis with our enumeration. Used by OIS sliders and OIS axes.
unsigned int _getJoystick (const OIS::JoyStickEvent &arg)
 Returns the joy stick ID (orxonox) according to a OIS::JoyStickEvent.
void _initialiseJoySticks ()
 Creates all joy sticks and sets the event handler.
void _initialiseKeyboard ()
 Creates a keyboard and sets the event handler.
void _initialiseMouse ()
 Creates a mouse and sets the event handler.
void _loadCalibration ()
void _reload (bool joyStickSupport)
 Internal reload method. Destroys the OIS devices and loads them again.
void _startCalibration ()
void _updateActiveStates ()
 Updates the currently active states (according to activeStates_) for each device. Also, a list of all active states (no duplicates!) is compiled for the general update().
bool axisMoved (const OIS::JoyStickEvent &arg, int axis)
bool buttonPressed (const OIS::JoyStickEvent &arg, int button)
bool buttonReleased (const OIS::JoyStickEvent &arg, int button)
 InputManager (const InputManager &)
bool keyPressed (const OIS::KeyEvent &arg)
 Event handler for the keyPressed Event.
bool keyReleased (const OIS::KeyEvent &arg)
 Event handler for the keyReleased Event.
bool mouseMoved (const OIS::MouseEvent &arg)
 Event handler for the mouseMoved Event.
bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id)
 Event handler for the mousePressed Event.
bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id)
 Event handler for the mouseReleased Event.
bool povMoved (const OIS::JoyStickEvent &arg, int id)
 Joystick Event, and povID.
void setConfigValues ()
 Sets the configurable values.
bool sliderMoved (const OIS::JoyStickEvent &arg, int id)
 Joystick Event, and sliderID.
bool vector3Moved (const OIS::JoyStickEvent &arg, int id)
 Joystick Event, and Vector3ID.

Private Attributes

std::map< int, InputState * > activeStates_
std::vector< InputState * > activeStatesTicked_
std::vector< std::vector
< InputState * > > 
activeStatesTriggered_
std::vector
< ConfigValueContainer * > 
calibrationConfigValueContainers_
std::string calibrationFilename_
 Joy stick calibration ini filename.
InputBuffercalibratorCallbackBuffer_
unsigned int devicesNum_
std::map< std::string,
InputState * > 
inputStatesByName_
OIS::InputManagerinputSystem_
 OIS input manager.
InputManagerState internalState_
 Current internal state.
std::vector< std::vector
< JoyStickButtonCode::ByEnum > > 
joyStickButtonsDown_
std::vector< JoyStickCalibrationjoyStickCalibrations_
std::vector< std::stringjoyStickIDs_
 Execution unique identification strings for the joy sticks.
std::vector< std::vector< int > > joyStickMaxValues_
std::vector< std::vector< int > > joyStickMiddleValues_
std::vector< std::vector< int > > joyStickMinValues_
std::vector< OIS::JoyStick * > joySticks_
 OIS joy sticks.
unsigned int joySticksSize_
OIS::Keyboardkeyboard_
 OIS mouse.
unsigned int keyboardModifiers_
 Bit mask representing keyboard modifiers.
KeyDetectorkeyDetector_
 KeyDetector instance.
std::vector< KeykeysDown_
OIS::Mousemouse_
 OIS keyboard.
std::vector
< MouseButtonCode::ByEnum
mouseButtonsDown_
std::vector< POVStatespovStates_
 Keeps track of the joy stick POV states.
std::vector< SliderStatessliderStates_
 Keeps track of the possibly two slider axes.
std::set< InputState * > stateDestroyRequests_
 Request to destroy a state.
SimpleInputStatestateEmpty_
std::set< InputState * > stateEnterRequests_
 Request to enter a new state.
std::set< InputState * > stateLeaveRequests_
 Request to leave a running state.
size_t windowHnd_
 Render window handle.

Static Private Attributes

static InputManagersingletonRef_s = 0

Friends

class ClassIdentifier< InputManager >


Detailed Description

Captures and distributes mouse and keyboard input.

Member Enumeration Documentation

Enumerator:
Uninitialised 
OISReady 
InternalsReady 
Ticking 
Calibrating 
ReloadRequest 
JoyStickSupport 


Constructor & Destructor Documentation

orxonox::InputManager::InputManager (  ) 

Constructor only sets member fields to initial zero values and registers the class in the class hierarchy.

References RegisterRootObject, setConfigValues(), and singletonRef_s.

orxonox::InputManager::~InputManager (  ) 

orxonox::InputManager::InputManager ( const InputManager  )  [private]


Member Function Documentation

void orxonox::InputManager::_calibrationFileCallback (  )  [private]

void orxonox::InputManager::_clearBuffers (  )  [private]

void orxonox::InputManager::_completeCalibration (  )  [private]

bool orxonox::InputManager::_configureInputState ( InputState state,
const std::string name,
bool  bAlwaysGetsInput,
bool  bTransparent,
int  priority 
) [private]

Adds a new key handler.

Parameters:
handler Pointer to the handler object.
name Unique name of the handler.
priority Determines which InputState gets the input. Higher is better. Use 0 to handle it implicitely by the order of activation. Otherwise numbers larger than maxStateStackSize_s have to be used!
Returns:
True if added, false if name or priority already existed.

References orxonox::InputState::bAlwaysGetsInput_, orxonox::InputState::bTransparent_, COUT, orxonox::InputStatePriority::Empty, orxonox::InputStatePriority::HighPriority, inputStatesByName_, numberOfJoySticks(), orxonox::InputState::setName(), orxonox::InputState::setNumOfJoySticks(), and orxonox::InputState::setPriority().

Referenced by createInputState().

void orxonox::InputManager::_configureJoySticks (  )  [private]

Sets the size of all the different lists that are dependent on the number of joy stick devices created and loads the joy stick calibration.

Remarks:
No matter whether there are a mouse and/or keyboard, they will always occupy 2 places in the device number dependent lists.

References _evaluateCalibration(), activeStatesTriggered_, devicesNum_, inputStatesByName_, joyStickButtonsDown_, joyStickCalibrations_, joyStickIDs_, joyStickMaxValues_, joyStickMiddleValues_, joyStickMinValues_, joySticks_, joySticksSize_, orxonox::loadCalibration(), orxonox::multi_cast(), OIS::OIS_Axis, OIS::OIS_Button, OIS::OIS_POV, OIS::OIS_Slider, OIS::OIS_Vector3, povStates_, sliderAxes, and sliderStates_.

Referenced by initialise().

void orxonox::InputManager::_destroyJoySticks (  )  [private]

Destroys all the joy sticks and resizes the lists to 0.

References CCOUT, OIS::InputManager::destroyInputObject(), inputSystem_, joySticks_, and joySticksSize_.

Referenced by _reload(), and ~InputManager().

void orxonox::InputManager::_destroyKeyboard (  )  [private]

Destroys the keyboard and sets it to 0.

References CCOUT, OIS::InputManager::destroyInputObject(), inputSystem_, and keyboard_.

Referenced by _reload(), and ~InputManager().

void orxonox::InputManager::_destroyMouse (  )  [private]

Destroys the mouse and sets it to 0.

References CCOUT, OIS::InputManager::destroyInputObject(), inputSystem_, and mouse_.

Referenced by _reload(), and ~InputManager().

void orxonox::InputManager::_destroyState ( InputState state  )  [private]

Removes and destroys an InputState.

Returns:
True if state was removed immediately, false if postponed.

References _updateActiveStates(), activeStates_, orxonox::InputState::getName(), orxonox::InputState::getPriority(), inputStatesByName_, internalState_, and Ticking.

Referenced by requestDestroyState(), update(), and ~InputManager().

void orxonox::InputManager::_evaluateCalibration (  )  [private]

void orxonox::InputManager::_fireAxis ( unsigned int  iJoyStick,
int  axis,
int  value 
) [private]

Calls the states for a particular axis with our enumeration. Used by OIS sliders and OIS axes.

References activeStatesTriggered_, Calibrating, internalState_, joyStickCalibrations_, joyStickMaxValues_, and joyStickMinValues_.

Referenced by axisMoved(), and sliderMoved().

unsigned int orxonox::InputManager::_getJoystick ( const OIS::JoyStickEvent arg  )  [inline, private]

Returns the joy stick ID (orxonox) according to a OIS::JoyStickEvent.

References OIS::EventArg::device, joySticks_, and joySticksSize_.

Referenced by axisMoved(), buttonPressed(), buttonReleased(), povMoved(), and sliderMoved().

void orxonox::InputManager::_initialiseJoySticks (  )  [private]

Creates all joy sticks and sets the event handler.

Returns:
False joy stick stay uninitialised, true otherwise.

References CCOUT, OIS::InputManager::createInputObject(), OIS::Exception::eText, OIS::Object::getID(), OIS::InputManager::getNumberOfDevices(), inputSystem_, joySticks_, joySticksSize_, OIS::OISJoyStick, ORX_DEBUG, ORX_WARNING, and OIS::JoyStick::setEventCallback().

Referenced by initialise().

void orxonox::InputManager::_initialiseKeyboard (  )  [private]

Creates a keyboard and sets the event handler.

Returns:
False if keyboard stays uninitialised, true otherwise.

References CCOUT, OIS::InputManager::createInputObject(), OIS::InputManager::getNumberOfDevices(), inputSystem_, keyboard_, OIS::OISKeyboard, ORX_DEBUG, OIS::Keyboard::setEventCallback(), and ThrowException.

Referenced by initialise().

void orxonox::InputManager::_initialiseMouse (  )  [private]

Creates a mouse and sets the event handler.

Returns:
False if mouse stays uninitialised, true otherwise.

References CCOUT, OIS::InputManager::createInputObject(), OIS::Exception::eText, OIS::InputManager::getNumberOfDevices(), inputSystem_, mouse_, OIS::OISMouse, ORX_DEBUG, ORX_WARNING, and OIS::Mouse::setEventCallback().

Referenced by initialise().

void orxonox::InputManager::_loadCalibration (  )  [private]

void orxonox::InputManager::_reload ( bool  joyStickSupport  )  [private]

void orxonox::InputManager::_startCalibration (  )  [private]

void orxonox::InputManager::_updateActiveStates (  )  [private]

Updates the currently active states (according to activeStates_) for each device. Also, a list of all active states (no duplicates!) is compiled for the general update().

References activeStates_, activeStatesTicked_, activeStatesTriggered_, devicesNum_, and mouseButtonsDown_.

Referenced by _destroyState(), initialise(), and update().

bool orxonox::InputManager::axisMoved ( const OIS::JoyStickEvent arg,
int  axis 
) [private, virtual]

Remarks:
Joystick axis moved event

Implements OIS::JoyStickListener.

References _fireAxis(), _getJoystick(), sliderAxes, and OIS::JoyStickEvent::state.

bool orxonox::InputManager::buttonPressed ( const OIS::JoyStickEvent arg,
int  button 
) [private, virtual]

Remarks:
Joystick button down event

Implements OIS::JoyStickListener.

References _getJoystick(), activeStatesTriggered_, and joyStickButtonsDown_.

Referenced by povMoved().

bool orxonox::InputManager::buttonReleased ( const OIS::JoyStickEvent arg,
int  button 
) [private, virtual]

Remarks:
Joystick button up event

Implements OIS::JoyStickListener.

References _getJoystick(), activeStatesTriggered_, and joyStickButtonsDown_.

Referenced by povMoved().

void orxonox::InputManager::calibrate (  )  [static]

Starts joy stick calibration.

References _startCalibration(), COUT, and getInstance().

void orxonox::InputManager::clearBuffers (  ) 

Clears all buffers that store what keys/buttons are being pressed at the moment.

References joyStickButtonsDown_, joySticksSize_, keysDown_, and mouseButtonsDown_.

Referenced by orxonox::GSGraphics::windowFocusChanged().

template<class T>
T * orxonox::InputManager::createInputState ( const std::string name,
bool  bAlwaysGetsInput = false,
bool  bTransparent = false,
InputStatePriority  priority = InputStatePriority::Dynamic 
) [inline]

Creates a new InputState by type, name and priority.

You will have to use this method because the c'tors and d'tors are private.

Remarks:
The InputManager will take care of the state completely. That also means it gets deleted when the InputManager is destroyed!
Parameters:
name Name of the InputState when referenced as string
priority Priority matters when multiple states are active. You can specify any number, but 1 - 99 is preferred (99 means high).

References _configureInputState(), and orxonox::KeyCode::T.

Referenced by orxonox::GSMainMenu::activate(), orxonox::GSLevel::activate(), orxonox::GSGraphics::activate(), and orxonox::InGameConsole::initialise().

InputState * orxonox::InputManager::getCurrentState (  ) 

Returns the current input state (there might be others active too!).

Returns:
The current highest prioritised active input state.

References activeStates_.

static InputManager& orxonox::InputManager::getInstance (  )  [inline, static]

static InputManager* orxonox::InputManager::getInstancePtr (  )  [inline, static]

InputState * orxonox::InputManager::getState ( const std::string name  ) 

Returns the pointer to the requested InputState.

Parameters:
name Unique name of the state.
Returns:
Pointer to the instance, 0 if name was not found.

References inputStatesByName_.

void orxonox::InputManager::initialise ( size_t  windowHnd,
int  windowWidth,
int  windowHeight,
bool  joyStickSupport = true 
)

bool orxonox::InputManager::keyPressed ( const OIS::KeyEvent e  )  [private, virtual]

bool orxonox::InputManager::keyReleased ( const OIS::KeyEvent e  )  [private, virtual]

bool orxonox::InputManager::mouseMoved ( const OIS::MouseEvent e  )  [private, virtual]

Event handler for the mouseMoved Event.

Parameters:
e Event information

Implements OIS::MouseListener.

References activeStatesTriggered_, orxonox::InputDevice::Mouse, and OIS::MouseEvent::state.

bool orxonox::InputManager::mousePressed ( const OIS::MouseEvent e,
OIS::MouseButtonID  id 
) [private, virtual]

Event handler for the mousePressed Event.

Parameters:
e Event information
id The ID of the mouse button

Implements OIS::MouseListener.

References activeStatesTriggered_, orxonox::InputDevice::Mouse, and mouseButtonsDown_.

bool orxonox::InputManager::mouseReleased ( const OIS::MouseEvent e,
OIS::MouseButtonID  id 
) [private, virtual]

Event handler for the mouseReleased Event.

Parameters:
e Event information
id The ID of the mouse button

Implements OIS::MouseListener.

References activeStatesTriggered_, orxonox::InputDevice::Mouse, and mouseButtonsDown_.

unsigned int orxonox::InputManager::numberOfJoySticks (  )  [inline]

unsigned int orxonox::InputManager::numberOfKeyboards (  )  [inline]

unsigned int orxonox::InputManager::numberOfMice (  )  [inline]

bool orxonox::InputManager::povMoved ( const OIS::JoyStickEvent arg,
int  index 
) [private, virtual]

void orxonox::InputManager::reload ( bool  joyStickSupport = true  )  [static]

Reloads the input system.

References getInstance(), and reloadInputSystem().

void orxonox::InputManager::reloadInputSystem ( bool  joyStickSupport = true  ) 

Public interface. Only reloads immediately if the call stack doesn't include the update() method.

Parameters:
joyStickSupport Whether or not to initialise joy sticks as well.

References _reload(), CCOUT, internalState_, JoyStickSupport, OISReady, ReloadRequest, Ticking, and Uninitialised.

Referenced by reload().

bool orxonox::InputManager::requestDestroyState ( const std::string name  ) 

Removes and destroys an input state internally.

Parameters:
name Name of the handler.
Returns:
True if removal was successful, false if name was not found.
Remarks:
You can't remove the internal states "empty", "calibrator" and "detector". The removal process is being postponed if InputManager::update() is currently running.

References _destroyState(), activeStates_, COUT, inputStatesByName_, internalState_, stateDestroyRequests_, stateLeaveRequests_, and Ticking.

Referenced by orxonox::GSMainMenu::deactivate(), orxonox::GSLevel::deactivate(), orxonox::GSGraphics::deactivate(), orxonox::InGameConsole::~InGameConsole(), and ~InputManager().

bool orxonox::InputManager::requestEnterState ( const std::string name  ) 

Activates a specific input state. It might not be really activated if the priority is too low!

Parameters:
name Unique name of the state.
Returns:
False if name was not found, true otherwise.

References activeStates_, inputStatesByName_, stateDestroyRequests_, and stateEnterRequests_.

Referenced by _startCalibration(), orxonox::InGameConsole::activate(), orxonox::GSMainMenu::activate(), orxonox::GSLevel::activate(), orxonox::GSGraphics::activate(), orxonox::GUIOverlay::changedVisibility(), orxonox::GSLevel::keybindInternal(), orxonox::GSLevel::showIngameGUI(), and orxonox::PickupInventory::toggleInventory().

bool orxonox::InputManager::requestLeaveState ( const std::string name  ) 

void orxonox::InputManager::setConfigValues (  )  [private]

Sets the configurable values.

Reimplemented from orxonox::OrxonoxClass.

References _calibrationFileCallback(), calibrationFilename_, and SetConfigValue.

Referenced by InputManager().

void orxonox::InputManager::setKeyDetectorCallback ( const std::string command  ) 

Sets the the name of the command used by the KeyDetector as callback.

Parameters:
command Command name as string

References keyDetector_, and orxonox::KeyDetector::setCallbackCommand().

Referenced by orxonox::GSLevel::activate().

void orxonox::InputManager::setWindowExtents ( const int  width,
const int  height 
)

Adjusts the mouse window metrics. This method has to be called every time the size of the window changes.

Parameters:
width The new width of the render window
 The new height of the render window

References OIS::Mouse::getMouseState(), and mouse_.

Referenced by initialise(), and orxonox::GSGraphics::windowResized().

bool orxonox::InputManager::sliderMoved ( const OIS::JoyStickEvent ,
int  index 
) [private, virtual]

Joystick Event, and sliderID.

Reimplemented from OIS::JoyStickListener.

References _fireAxis(), _getJoystick(), sliderStates_, and OIS::JoyStickEvent::state.

void orxonox::InputManager::update ( const Clock time  ) 

bool orxonox::InputManager::vector3Moved ( const OIS::JoyStickEvent arg,
int  index 
) [inline, private, virtual]

Joystick Event, and Vector3ID.

Reimplemented from OIS::JoyStickListener.


Friends And Related Function Documentation

friend class ClassIdentifier< InputManager > [friend]


Member Data Documentation

Referenced by _updateActiveStates(), and update().

std::vector<std::vector<InputState*> > orxonox::InputManager::activeStatesTriggered_ [private]

Joy stick calibration ini filename.

Referenced by _calibrationFileCallback(), and setConfigValues().

Referenced by initialise(), and ~InputManager().

unsigned int orxonox::InputManager::devicesNum_ [private]

Execution unique identification strings for the joy sticks.

Referenced by _completeCalibration(), and _configureJoySticks().

std::vector<std::vector<int> > orxonox::InputManager::joyStickMaxValues_ [private]

std::vector<std::vector<int> > orxonox::InputManager::joyStickMiddleValues_ [private]

std::vector<std::vector<int> > orxonox::InputManager::joyStickMinValues_ [private]

unsigned int orxonox::InputManager::joySticksSize_ [private]

Bit mask representing keyboard modifiers.

Referenced by _clearBuffers(), keyPressed(), keyReleased(), and update().

std::vector<Key> orxonox::InputManager::keysDown_ [private]

Keeps track of the joy stick POV states.

Referenced by _clearBuffers(), _configureJoySticks(), and povMoved().

Referenced by InputManager(), and ~InputManager().

const unsigned int orxonox::InputManager::sliderAxes = 8 [static]

Keeps track of the possibly two slider axes.

Referenced by _clearBuffers(), _configureJoySticks(), and sliderMoved().

Request to destroy a state.

Referenced by requestDestroyState(), requestEnterState(), and update().

Referenced by initialise(), and ~InputManager().

Request to enter a new state.

Referenced by requestEnterState(), and update().

Request to leave a running state.

Referenced by requestDestroyState(), requestLeaveState(), and update().

Render window handle.

Referenced by _reload(), and initialise().


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

Generated on Tue Jul 28 16:22:39 2009 for Orxonox by  doxygen 1.5.6