FIFE
be64c707dea6b3250bd4355bf5c825d25920087d
|
Joystick Manager manages all events related to Joysticks and Gamecontrollers. More...
#include <joystickmanager.h>
Public Member Functions | |
JoystickManager () | |
Constructor. More... | |
virtual | ~JoystickManager () |
Destructor. More... | |
Joystick * | addJoystick (int32_t deviceIndex) |
Adds a joystick with the given device index. More... | |
Joystick * | getJoystick (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... | |
Joystick Manager manages all events related to Joysticks and Gamecontrollers.
Definition at line 54 of file joystickmanager.h.
FIFE::JoystickManager::JoystickManager | ( | ) |
Constructor.
Definition at line 43 of file joystickmanager.cpp.
References addJoystick(), m_mappingLoader, and m_mappingSaver.
|
virtual |
|
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().
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().
|
virtual |
Adds a listener to the back of the listener deque Listener will be notified via the corresponding events.
listener | listener to add |
Implements FIFE::IJoystickController.
Definition at line 180 of file joystickmanager.cpp.
References m_joystickListeners.
Referenced by FIFE::EventManager::addJoystickListener().
|
virtual |
Adds a listener to the front of the listener deque Listener will be notified via the corresponding events.
listener | listener to add |
Implements FIFE::IJoystickController.
Definition at line 184 of file joystickmanager.cpp.
References m_joystickListeners.
Referenced by FIFE::EventManager::addJoystickListenerFront().
|
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().
void FIFE::JoystickManager::dispatchJoystickEvent | ( | JoystickEvent & | evt | ) |
Dispatches joystick / controller events.
Definition at line 273 of file joystickmanager.cpp.
References FIFE::JoystickEvent::AXIS_MOTION, FIFE::JoystickEvent::BUTTON_PRESSED, FIFE::JoystickEvent::BUTTON_RELEASED, FIFE::JoystickEvent::DEVICE_ADDED, FIFE::JoystickEvent::DEVICE_REMOVED, FIFE::JoystickEvent::getType(), FIFE::JoystickEvent::HAT_MOTION, FIFE::JoystickEvent::isConsumed(), and m_joystickListeners.
Referenced by processControllerEvent(), and processJoystickEvent().
|
virtual |
Gets the source type of this event.
Implements FIFE::IEventSource.
Definition at line 306 of file joystickmanager.cpp.
References FIFE::ES_ENGINE.
|
private |
Return GUID for given device index as string.
Definition at line 310 of file joystickmanager.cpp.
Referenced by addJoystick().
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().
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().
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().
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().
void FIFE::JoystickManager::processControllerEvent | ( | SDL_Event | event | ) |
Creates and process gamecontroller events.
Definition at line 248 of file joystickmanager.cpp.
References FIFE::JoystickEvent::AXIS_MOTION, FIFE::JoystickEvent::BUTTON_PRESSED, FIFE::JoystickEvent::BUTTON_RELEASED, convertRange(), dispatchJoystickEvent(), FIFE::JoystickEvent::setAxis(), FIFE::JoystickEvent::setAxisValue(), FIFE::JoystickEvent::setButton(), FIFE::JoystickEvent::setController(), FIFE::JoystickEvent::setInstanceId(), FIFE::JoystickEvent::setSource(), and FIFE::JoystickEvent::setType().
Referenced by FIFE::EventManager::processEvents().
void FIFE::JoystickManager::processJoystickEvent | ( | SDL_Event | event | ) |
Creates and process joystick events.
Definition at line 200 of file joystickmanager.cpp.
References addJoystick(), FIFE::JoystickEvent::AXIS_MOTION, FIFE::JoystickEvent::BUTTON_PRESSED, FIFE::JoystickEvent::BUTTON_RELEASED, convertRange(), FIFE::JoystickEvent::DEVICE_ADDED, FIFE::JoystickEvent::DEVICE_REMOVED, dispatchJoystickEvent(), FIFE::JoystickEvent::getInstanceId(), FIFE::Joystick::getInstanceId(), getJoystick(), FIFE::JoystickEvent::HAT_MOTION, FIFE::Joystick::isController(), removeJoystick(), FIFE::JoystickEvent::setAxis(), FIFE::JoystickEvent::setAxisValue(), FIFE::JoystickEvent::setButton(), FIFE::JoystickEvent::setController(), FIFE::JoystickEvent::setHat(), FIFE::JoystickEvent::setHatValue(), FIFE::JoystickEvent::setInstanceId(), FIFE::JoystickEvent::setSource(), and FIFE::JoystickEvent::setType().
Referenced by FIFE::EventManager::processEvents().
|
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().
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().
|
virtual |
Removes an added listener from the controller.
Listener will not be notified anymore via the corresponding events
listener | listener 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().
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().
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().
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().
|
private |
All active / connected Joysticks.
Definition at line 146 of file joystickmanager.h.
Referenced by addJoystick(), getJoystickCount(), loadMapping(), removeJoystick(), and setStringMapping().
|
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().
|
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().
|
private |
The Joystick listeners.
Definition at line 158 of file joystickmanager.h.
Referenced by addJoystickListener(), addJoystickListenerFront(), dispatchJoystickEvent(), and removeJoystickListener().
|
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().
|
private |
Loader for gamecontroller mapping.
Definition at line 140 of file joystickmanager.h.
Referenced by JoystickManager(), and loadMapping().
|
private |
Saver for gamecontroller mapping.
Definition at line 143 of file joystickmanager.h.
Referenced by JoystickManager(), saveMapping(), and saveMappings().