FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
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
 Map to hold the relation between Joystick InstanceId and JoystickId. More...
 
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
 The Joystick listeners. More...
 

Detailed Description

Joystick Manager manages all events related to Joysticks and Gamecontrollers.

Definition at line 54 of file joystickmanager.h.

Constructor & Destructor Documentation

◆ JoystickManager()

FIFE::JoystickManager::JoystickManager ( )

Constructor.

Definition at line 43 of file joystickmanager.cpp.

References addJoystick(), m_mappingLoader, and m_mappingSaver.

◆ ~JoystickManager()

FIFE::JoystickManager::~JoystickManager ( )
virtual

Destructor.

Definition at line 61 of file joystickmanager.cpp.

References m_joysticks.

Member Function Documentation

◆ addControllerGuid()

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

Adds GUID from controller.

Needed for saving.

Definition at line 331 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:

◆ addJoystick()

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:

◆ addJoystickListener()

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_joystickListeners.

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

+ Here is the caller graph for this function:

◆ addJoystickListenerFront()

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_joystickListeners.

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

+ Here is the caller graph for this function:

◆ convertRange()

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

Converts the int16 in -1.0 to 1.0 range.

Definition at line 318 of file joystickmanager.cpp.

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

Referenced by processControllerEvent(), and processJoystickEvent().

+ Here is the caller graph for this function:

◆ dispatchJoystickEvent()

◆ getEventSourceType()

EventSourceType FIFE::JoystickManager::getEventSourceType ( )
virtual

Gets the source type of this event.

Returns
source type of this event

Implements FIFE::IEventSource.

Definition at line 306 of file joystickmanager.cpp.

References FIFE::ES_ENGINE.

◆ getGuidString()

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

Return GUID for given device index as string.

Definition at line 310 of file joystickmanager.cpp.

Referenced by addJoystick().

+ Here is the caller graph for this function:

◆ getJoystick()

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:

◆ getJoystickCount()

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:

◆ getStringMapping()

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:

◆ loadMapping()

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:

◆ processControllerEvent()

◆ processJoystickEvent()

◆ removeControllerGuid()

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

Removes / decal controller GUID.

Definition at line 342 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:

◆ removeJoystick()

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:

◆ removeJoystickListener()

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 FIFE::IListener::isActive(), m_joystickListeners, and FIFE::IListener::setActive().

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

+ Here is the caller graph for this function:

◆ saveMapping()

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:

◆ saveMappings()

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:

◆ setStringMapping()

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

◆ m_activeJoysticks

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

◆ m_gamepadGuids

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 155 of file joystickmanager.h.

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

◆ m_joystickIndices

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

Map to hold the relation between Joystick InstanceId and JoystickId.

Definition at line 152 of file joystickmanager.h.

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

◆ m_joystickListeners

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

◆ m_joysticks

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

◆ m_mappingLoader

ControllerMappingLoader FIFE::JoystickManager::m_mappingLoader
private

Loader for gamecontroller mapping.

Definition at line 140 of file joystickmanager.h.

Referenced by JoystickManager(), and loadMapping().

◆ m_mappingSaver

ControllerMappingSaver FIFE::JoystickManager::m_mappingSaver
private

Saver for gamecontroller mapping.

Definition at line 143 of file joystickmanager.h.

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


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