Orxonox  0.0.5 Codename: Arcturus
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
orxonox::InputManager Class Reference

Manages the input devices (mouse, keyboard, joy sticks) and the input states. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/input/InputManager.h>

Inheritance diagram for orxonox::InputManager:
orxonox::Singleton< InputManager > orxonox::WindowEventListener orxonox::Listable orxonox::Identifiable

Public Types

enum  State { Nothing = 0x00, Bad = 0x02, Calibrating = 0x04 }
 Represents internal states of the InputManager. More...
 

Public Member Functions

 InputManager ()
 Loads the devices and initialises the KeyDetector and the Calibrator. More...
 
 ~InputManager ()
 Destroys all devices AND all input states! More...
 
void calibrate ()
 Starts joy stick calibration. More...
 
void clearBuffers ()
 Clears all input device buffers. This usually only includes the pressed button list. More...
 
InputStatecreateInputState (const std::string &name, bool bAlwaysGetsInput=false, bool bTransparent=false, InputStatePriority priority=InputStatePriority::Dynamic)
 Creates a new InputState that gets managed by the InputManager. More...
 
bool destroyState (const std::string &name)
 Removes and destroys an input state. More...
 
bool enterState (const std::string &name)
 Activates a specific input state. More...
 
unsigned int getJoyStickQuantity () const
 Returns the number of joy stick that have been created since the c'tor or last call to reload(). More...
 
std::pair< int, int > getMousePosition () const
 Returns the position of the cursor as std::pair of ints. More...
 
OIS::InputManagergetOISInputManager ()
 Returns a pointer to the OIS InputManager. Only you if you know what you're doing! More...
 
InputStategetState (const std::string &name)
 Returns a pointer to a InputState referenced by name. More...
 
bool isMouseExclusive () const
 Tells whether the mouse is used exclusively to the game. More...
 
bool leaveState (const std::string &name)
 Deactivates a specific input state. More...
 
void preUpdate (const Clock &time)
 Updates the devices (which distribute the input events) and the input states. More...
 
void pushCall (const std::function< void()> &function)
 
void reload ()
 Reloads all the input devices. More...
 
void setConfigValues ()
 
bool setMouseExclusive (const std::string &name, tribool value)
 Changes the mouse mode of an input state. More...
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 

Static Public Member Functions

static InputManagergetInstance ()
 
- Static Public Member Functions inherited from orxonox::Singleton< InputManager >
static bool exists ()
 Tells whether the singleton has been created. More...
 
static InputManagergetInstance ()
 Returns a reference to the singleton instance. More...
 

Private Member Functions

 InputManager (const InputManager &)=delete
 
void destroyDevices ()
 Destoys all input devices (joy sticks, mouse, keyboard and OIS::InputManager) More...
 
void destroyStateInternal (InputState *state)
 Destroys an InputState internally. More...
 
void loadDevices ()
 Creates the OIS::InputMananger, the keyboard, the mouse and the joys ticks. More...
 
void loadJoySticks ()
 Creates as many joy sticks as are available. More...
 
void loadMouse ()
 Creates a new orxonox::Mouse. More...
 
InputManageroperator= (const InputManager &)=delete
 
void reloadInternal ()
 Internal reload method. Destroys the OIS devices and loads them again. More...
 
void stopCalibration ()
 Tells all devices to stop the calibration and evaluate it. Buffers are being cleared as well! More...
 
void updateActiveStates ()
 Updates the currently active states (according to activeStates_) for each device. More...
 
virtual void windowFocusChanged (bool bFocus) override
 Gets called by WindowEventListener upon focus change –> clear buffers. More...
 

Private Attributes

std::map< int, InputState * > activeStates_
 Contains all active input states by priority (std::map is sorted!) More...
 
std::vector< InputState * > activeStatesTicked_
 Like activeStates_, but only contains the ones that currently receive events. More...
 
InputBuffercalibratorCallbackHandler_
 InputBuffer that reacts to the Enter key when calibrating the joy sticks. More...
 
std::vector< std::function< void()> > callBuffer_
 Caches all calls from InputStates to be executed afterwards (see preUpdate) More...
 
std::vector< InputDevice * > devices_
 List of all input devices (keyboard, mouse, joy sticks) More...
 
InputStateemptyState_
 Lowest priority states (makes handling easier) More...
 
bool exclusiveMouse_
 Currently applied mouse mode. More...
 
State internalState_
 Current internal state. More...
 
OIS::InputManageroisInputManager_
 OIS input manager. More...
 
std::map< std::string, InputState * > statesByName_
 Contains all the created input states by name. More...
 

Static Private Attributes

static InputManagersingletonPtr_s = nullptr
 Pointer reference to the singleton. More...
 

Friends

class Singleton< InputManager >
 

Additional Inherited Members

- Protected Member Functions inherited from orxonox::Singleton< InputManager >
 Singleton ()
 Constructor sets the singleton instance pointer. More...
 
virtual ~Singleton ()
 Destructor resets the singleton instance pointer. More...
 
- Protected Member Functions inherited from orxonox::WindowEventListener
 WindowEventListener ()
 
virtual ~WindowEventListener ()=default
 
unsigned int getWindowHeight () const
 Returns the current render window height. More...
 
unsigned int getWindowWidth () const
 Returns the current render window width. More...
 

Detailed Description

Manages the input devices (mouse, keyboard, joy sticks) and the input states.

Every input device has its own wrapper class which does the actually input event distribution. The InputManager only creates reloads (on request) those devices.

The other functionality concerns handling InputStates. They act as a layer between InputHandlers (like the KeyBinder or the GUIManager) and InputDevices. InputStates are memory managed by the IputManager. You cannot create or destroy them on your own. Therefore all states get destroyed with the InputManager d'tor.

Note

Member Enumeration Documentation

Represents internal states of the InputManager.

Enumerator
Nothing 
Bad 
Calibrating 

Constructor & Destructor Documentation

orxonox::InputManager::InputManager ( )

Loads the devices and initialises the KeyDetector and the Calibrator.

If either the OIS input system and/or the keyboard could not be created, the constructor fails with an std::exception.

orxonox::InputManager::~InputManager ( )

Destroys all devices AND all input states!

orxonox::InputManager::InputManager ( const InputManager )
privatedelete

Member Function Documentation

void orxonox::InputManager::calibrate ( )

Starts joy stick calibration.

void orxonox::InputManager::clearBuffers ( )

Clears all input device buffers. This usually only includes the pressed button list.

InputState * orxonox::InputManager::createInputState ( const std::string &  name,
bool  bAlwaysGetsInput = false,
bool  bTransparent = false,
InputStatePriority  priority = InputStatePriority::Dynamic 
)

Creates a new InputState that gets managed by the InputManager.

Remarks
The InputManager will take care of the state completely. That also means it gets deleted when the InputManager is destroyed!
Parameters
nameUnique name of the InputState when referenced as string
bAlwaysGetsInputInputState always gets the input when activated
bTransparentInputState will not prevent underlaying state from receiving input
priorityPriority matters when multiple states are active. You can specify any number, but 1 - 99 is preferred (99 means high priority).
void orxonox::InputManager::destroyDevices ( )
private

Destoys all input devices (joy sticks, mouse, keyboard and OIS::InputManager)

Exceptions
Methoddoes not throw
bool orxonox::InputManager::destroyState ( const std::string &  name)

Removes and destroys an input state.

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::preUpdate() is currently running.
void orxonox::InputManager::destroyStateInternal ( InputState state)
private

Destroys an InputState internally.

bool orxonox::InputManager::enterState ( const std::string &  name)

Activates a specific input state.

It might not actually be activated if the priority is too low!

Returns
False if name was not found, true otherwise.
static InputManager& orxonox::InputManager::getInstance ( )
inlinestatic
unsigned int orxonox::InputManager::getJoyStickQuantity ( ) const
inline

Returns the number of joy stick that have been created since the c'tor or last call to reload().

std::pair< int, int > orxonox::InputManager::getMousePosition ( ) const

Returns the position of the cursor as std::pair of ints.

OIS::InputManager* orxonox::InputManager::getOISInputManager ( )
inline

Returns a pointer to the OIS InputManager. Only you if you know what you're doing!

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

Returns a pointer to a InputState referenced by name.

Returns
Returns nullptr if state was not found.
bool orxonox::InputManager::isMouseExclusive ( ) const
inline

Tells whether the mouse is used exclusively to the game.

bool orxonox::InputManager::leaveState ( const std::string &  name)

Deactivates a specific input state.

Returns
False if name was not found, true otherwise.
void orxonox::InputManager::loadDevices ( )
private

Creates the OIS::InputMananger, the keyboard, the mouse and the joys ticks.

If either of the first two fail, this method throws an exception.

void orxonox::InputManager::loadJoySticks ( )
private

Creates as many joy sticks as are available.

void orxonox::InputManager::loadMouse ( )
private

Creates a new orxonox::Mouse.

InputManager& orxonox::InputManager::operator= ( const InputManager )
privatedelete
void orxonox::InputManager::preUpdate ( const Clock time)

Updates the devices (which distribute the input events) and the input states.

Any InpuStates changes (destroy, enter, leave) and happens here. If a reload request was submitted while updating, the request will be postponed until the next update call.

void orxonox::InputManager::pushCall ( const std::function< void()> &  function)
inline
void orxonox::InputManager::reload ( )

Reloads all the input devices.

Use this method to initialise new joy sticks.

Note
Only reloads immediately if the call stack doesn't include the preUpdate() method.
void orxonox::InputManager::reloadInternal ( )
private

Internal reload method. Destroys the OIS devices and loads them again.

void orxonox::InputManager::setConfigValues ( void  )
bool orxonox::InputManager::setMouseExclusive ( const std::string &  name,
tribool  value 
)

Changes the mouse mode of an input state.

Returns
True if the call was successful, fals if the name was not found
void orxonox::InputManager::stopCalibration ( )
private

Tells all devices to stop the calibration and evaluate it. Buffers are being cleared as well!

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 preUpdate().

void orxonox::InputManager::windowFocusChanged ( bool  bFocus)
overrideprivatevirtual

Gets called by WindowEventListener upon focus change –> clear buffers.

Reimplemented from orxonox::WindowEventListener.

Friends And Related Function Documentation

friend class Singleton< InputManager >
friend

Member Data Documentation

std::map<int, InputState*> orxonox::InputManager::activeStates_
private

Contains all active input states by priority (std::map is sorted!)

std::vector<InputState*> orxonox::InputManager::activeStatesTicked_
private

Like activeStates_, but only contains the ones that currently receive events.

InputBuffer* orxonox::InputManager::calibratorCallbackHandler_
private

InputBuffer that reacts to the Enter key when calibrating the joy sticks.

std::vector<std::function<void ()> > orxonox::InputManager::callBuffer_
private

Caches all calls from InputStates to be executed afterwards (see preUpdate)

std::vector<InputDevice*> orxonox::InputManager::devices_
private

List of all input devices (keyboard, mouse, joy sticks)

InputState* orxonox::InputManager::emptyState_
private

Lowest priority states (makes handling easier)

bool orxonox::InputManager::exclusiveMouse_
private

Currently applied mouse mode.

State orxonox::InputManager::internalState_
private

Current internal state.

OIS::InputManager* orxonox::InputManager::oisInputManager_
private

OIS input manager.

InputManager * orxonox::InputManager::singletonPtr_s = nullptr
staticprivate

Pointer reference to the singleton.

std::map<std::string, InputState*> orxonox::InputManager::statesByName_
private

Contains all the created input states by name.


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