FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
FIFE::JoystickManager Class Reference

Joystick Manager manages all events related to Joysticks and Gamecontrollers. More...

#include <joystickmanager.h>

+ Inheritance diagram for FIFE::JoystickManager:
+ Collaboration diagram for FIFE::JoystickManager:

Public Member Functions

 JoystickManager ()
 Constructor. More...
 
virtual ~JoystickManager ()
 Destructor. More...
 
JoystickaddJoystick (int32_t deviceIndex)
 Adds a joystick with the given device index. More...
 
JoystickgetJoystick (int32_t instanceId)
 Return the joystick with the given instance id. More...
 
void removeJoystick (Joystick *joystick)
 Removes the given joystick, can be reused. More...
 
uint8_t getJoystickCount () const
 Return the number of joysticks / gamecontrollers. More...
 
void loadMapping (const std::string &file)
 Loads controller mappings from given file and if possible, it opens the related controllers. More...
 
void saveMapping (const std::string guid, const std::string &file)
 Saves controller mapping for given GUID in the specified file. More...
 
void saveMappings (const std::string &file)
 Saves all controller mappings that were used during the season. More...
 
std::string getStringMapping (const std::string &guid)
 Return the controller mapping for given GUID as string. More...
 
void setStringMapping (const std::string &mapping)
 Sets controller mapping from string and adds or updates the related controllers. More...
 
void addJoystickListener (IJoystickListener *listener)
 Adds a listener to the back of the listener deque Listener will be notified via the corresponding events. More...
 
void addJoystickListenerFront (IJoystickListener *listener)
 Adds a listener to the front of the listener deque Listener will be notified via the corresponding events. More...
 
void removeJoystickListener (IJoystickListener *listener)
 Removes an added listener from the controller. More...
 
void processJoystickEvent (SDL_Event event)
 Creates and process joystick events. More...
 
void processControllerEvent (SDL_Event event)
 Creates and process gamecontroller events. More...
 
void dispatchJoystickEvent (JoystickEvent &evt)
 Dispatches joystick / controller events. More...
 
EventSourceType getEventSourceType ()
 Gets the source type of this event. More...
 
- Public Member Functions inherited from FIFE::IJoystickController
virtual ~IJoystickController ()
 
- Public Member Functions inherited from FIFE::IEventSource
virtual ~IEventSource ()
 

Private Member Functions

std::string getGuidString (int32_t deviceIndex)
 Return GUID for given device index as string. More...
 
float convertRange (int16_t value)
 Converts the int16 in -1.0 to 1.0 range. More...
 
void addControllerGuid (Joystick *joystick)
 Adds GUID from controller. More...
 
void removeControllerGuid (Joystick *joystick)
 Removes / decal controller GUID. More...
 

Private Attributes

ControllerMappingLoader m_mappingLoader
 Loader for gamecontroller mapping. More...
 
ControllerMappingSaver m_mappingSaver
 Saver for gamecontroller mapping. More...
 
std::vector< Joystick * > m_activeJoysticks
 All active / connected Joysticks. More...
 
std::vector< Joystick * > m_joysticks
 All "known" Joysticks. Useful if a user reconnect a Joystick. More...
 
std::map< int32_t, uint32_t > m_joystickIndices
 
std::map< std::string, uint8_t > m_gamepadGuids
 Each sort of gamepad have a GUID from SDL. Indicates the number of gamepads with given GUID are connected. More...
 
std::deque< IJoystickListener * > m_joystickListeners
 
std::deque< IJoystickListener * > m_pendingJoystickListeners
 
std::deque< IJoystickListener * > m_pendingJoystickListenersFront
 
std::deque< IJoystickListener * > m_pendingJoystickDeletions
 

Detailed Description

Joystick Manager manages all events related to Joysticks and Gamecontrollers.

Definition at line 54 of file joystickmanager.h.

Constructor & Destructor Documentation

FIFE::JoystickManager::JoystickManager ( )

Constructor.

Definition at line 43 of file joystickmanager.cpp.

References addJoystick(), m_mappingLoader, and m_mappingSaver.

FIFE::JoystickManager::~JoystickManager ( )
virtual

Destructor.

Definition at line 61 of file joystickmanager.cpp.

References m_joysticks.

Member Function Documentation

void FIFE::JoystickManager::addControllerGuid ( Joystick joystick)
private

Adds GUID from controller.

Needed for saving.

Definition at line 353 of file joystickmanager.cpp.

References FIFE::Joystick::getGuid(), FIFE::Joystick::isController(), and m_gamepadGuids.

Referenced by addJoystick(), loadMapping(), and setStringMapping().

+ Here is the caller graph for this function:

Joystick * FIFE::JoystickManager::addJoystick ( int32_t  deviceIndex)

Adds a joystick with the given device index.

Definition at line 69 of file joystickmanager.cpp.

References addControllerGuid(), getGuidString(), FIFE::Joystick::getInstanceId(), FIFE::Joystick::getJoystickId(), m_activeJoysticks, m_joystickIndices, m_joysticks, FIFE::Joystick::open(), and FIFE::Joystick::setDeviceIndex().

Referenced by JoystickManager(), and processJoystickEvent().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::addJoystickListener ( IJoystickListener listener)
virtual

Adds a listener to the back of the listener deque Listener will be notified via the corresponding events.

Parameters
listenerlistener to add

Implements FIFE::IJoystickController.

Definition at line 180 of file joystickmanager.cpp.

References m_pendingJoystickListeners.

Referenced by FIFE::EventManager::addJoystickListener().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::addJoystickListenerFront ( IJoystickListener listener)
virtual

Adds a listener to the front of the listener deque Listener will be notified via the corresponding events.

Parameters
listenerlistener to add

Implements FIFE::IJoystickController.

Definition at line 184 of file joystickmanager.cpp.

References m_pendingJoystickListenersFront.

Referenced by FIFE::EventManager::addJoystickListenerFront().

+ Here is the caller graph for this function:

float FIFE::JoystickManager::convertRange ( int16_t  value)
private

Converts the int16 in -1.0 to 1.0 range.

Definition at line 340 of file joystickmanager.cpp.

References FIFE::Math< T >::FAbs().

Referenced by processControllerEvent(), and processJoystickEvent().

+ Here is the caller graph for this function:

EventSourceType FIFE::JoystickManager::getEventSourceType ( )
virtual

Gets the source type of this event.

Returns
source type of this event

Implements FIFE::IEventSource.

Definition at line 328 of file joystickmanager.cpp.

References FIFE::ES_ENGINE.

std::string FIFE::JoystickManager::getGuidString ( int32_t  deviceIndex)
private

Return GUID for given device index as string.

Definition at line 332 of file joystickmanager.cpp.

Referenced by addJoystick().

+ Here is the caller graph for this function:

Joystick * FIFE::JoystickManager::getJoystick ( int32_t  instanceId)

Return the joystick with the given instance id.

Definition at line 96 of file joystickmanager.cpp.

References m_joystickIndices, and m_joysticks.

Referenced by FIFE::EventManager::getJoystick(), and processJoystickEvent().

+ Here is the caller graph for this function:

uint8_t FIFE::JoystickManager::getJoystickCount ( ) const

Return the number of joysticks / gamecontrollers.

Definition at line 115 of file joystickmanager.cpp.

References m_activeJoysticks.

Referenced by FIFE::EventManager::getJoystickCount().

+ Here is the caller graph for this function:

std::string FIFE::JoystickManager::getStringMapping ( const std::string &  guid)

Return the controller mapping for given GUID as string.

Definition at line 144 of file joystickmanager.cpp.

Referenced by FIFE::EventManager::getGamepadStringMapping(), saveMapping(), and saveMappings().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::loadMapping ( const std::string &  file)

Loads controller mappings from given file and if possible, it opens the related controllers.

Definition at line 119 of file joystickmanager.cpp.

References addControllerGuid(), FIFE::ControllerMappingLoader::load(), m_activeJoysticks, and m_mappingLoader.

Referenced by FIFE::EventManager::loadGamepadMapping().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::removeControllerGuid ( Joystick joystick)
private

Removes / decal controller GUID.

Definition at line 364 of file joystickmanager.cpp.

References FIFE::Joystick::getGuid(), FIFE::Joystick::isController(), and m_gamepadGuids.

Referenced by removeJoystick().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::removeJoystick ( Joystick joystick)

Removes the given joystick, can be reused.

Definition at line 105 of file joystickmanager.cpp.

References m_activeJoysticks, m_joystickIndices, and removeControllerGuid().

Referenced by processJoystickEvent().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::removeJoystickListener ( IJoystickListener listener)
virtual

Removes an added listener from the controller.

Listener will not be notified anymore via the corresponding events

Parameters
listenerlistener to remove

Implements FIFE::IJoystickController.

Definition at line 188 of file joystickmanager.cpp.

References m_pendingJoystickListenersFront.

Referenced by FIFE::EventManager::removeJoystickListener().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::saveMapping ( const std::string  guid,
const std::string &  file 
)

Saves controller mapping for given GUID in the specified file.

Definition at line 130 of file joystickmanager.cpp.

References getStringMapping(), m_mappingSaver, and FIFE::ControllerMappingSaver::save().

Referenced by FIFE::EventManager::saveGamepadMapping().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::saveMappings ( const std::string &  file)

Saves all controller mappings that were used during the season.

Definition at line 135 of file joystickmanager.cpp.

References getStringMapping(), m_gamepadGuids, m_mappingSaver, and FIFE::ControllerMappingSaver::save().

Referenced by FIFE::EventManager::saveGamepadMappings().

+ Here is the caller graph for this function:

void FIFE::JoystickManager::setStringMapping ( const std::string &  mapping)

Sets controller mapping from string and adds or updates the related controllers.

Definition at line 165 of file joystickmanager.cpp.

References addControllerGuid(), and m_activeJoysticks.

Referenced by FIFE::EventManager::setGamepadStringMapping().

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<Joystick*> FIFE::JoystickManager::m_activeJoysticks
private

All active / connected Joysticks.

Definition at line 146 of file joystickmanager.h.

Referenced by addJoystick(), getJoystickCount(), loadMapping(), removeJoystick(), and setStringMapping().

std::map<std::string, uint8_t> FIFE::JoystickManager::m_gamepadGuids
private

Each sort of gamepad have a GUID from SDL. Indicates the number of gamepads with given GUID are connected.

Definition at line 154 of file joystickmanager.h.

Referenced by addControllerGuid(), removeControllerGuid(), and saveMappings().

std::map<int32_t, uint32_t> FIFE::JoystickManager::m_joystickIndices
private

Definition at line 151 of file joystickmanager.h.

Referenced by addJoystick(), getJoystick(), and removeJoystick().

std::deque<IJoystickListener*> FIFE::JoystickManager::m_joystickListeners
private

Definition at line 156 of file joystickmanager.h.

Referenced by dispatchJoystickEvent().

std::vector<Joystick*> FIFE::JoystickManager::m_joysticks
private

All "known" Joysticks. Useful if a user reconnect a Joystick.

Definition at line 149 of file joystickmanager.h.

Referenced by addJoystick(), getJoystick(), and ~JoystickManager().

ControllerMappingLoader FIFE::JoystickManager::m_mappingLoader
private

Loader for gamecontroller mapping.

Definition at line 140 of file joystickmanager.h.

Referenced by JoystickManager(), and loadMapping().

ControllerMappingSaver FIFE::JoystickManager::m_mappingSaver
private

Saver for gamecontroller mapping.

Definition at line 143 of file joystickmanager.h.

Referenced by JoystickManager(), saveMapping(), and saveMappings().

std::deque<IJoystickListener*> FIFE::JoystickManager::m_pendingJoystickDeletions
private

Definition at line 159 of file joystickmanager.h.

Referenced by dispatchJoystickEvent().

std::deque<IJoystickListener*> FIFE::JoystickManager::m_pendingJoystickListeners
private

Definition at line 157 of file joystickmanager.h.

Referenced by addJoystickListener(), and dispatchJoystickEvent().

std::deque<IJoystickListener*> FIFE::JoystickManager::m_pendingJoystickListenersFront
private

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