SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DeviceManager Class Reference

This class holds the list of all known devices (ands their configurations), as well as the list of currently plugged (used) devices. More...

#include <device_manager.hpp>

Inheritance diagram for DeviceManager:
Inheritance graph
[legend]

Public Member Functions

PlayerAssignMode getAssignMode () const
 
void setAssignMode (const PlayerAssignMode assignMode)
 
void addGamepad (GamePadDevice *d)
 
int getGamePadAmount () const
 
int getGamePadConfigAmount () const
 
GamePadDevicegetGamePad (const int i)
 
GamepadConfiggetGamepadConfig (const int i)
 
GamePadDevicegetGamePadFromIrrID (const int i)
 
void clearGamepads ()
 
bool getConfigForGamepad (const int sdl_id, const std::string &name, GamepadConfig **config)
 Returns the keyboard that has a binding for this button, or NULL if none.
 
void addEmptyKeyboard ()
 
void addKeyboard (KeyboardDevice *d)
 
void clearKeyboard ()
 
int getKeyboardAmount ()
 
int getActiveKeyboardAmount ()
 
int getKeyboardConfigAmount () const
 
KeyboardDevicegetKeyboard (const int i)
 
KeyboardConfiggetKeyboardConfig (const int i)
 
KeyboardDevicegetKeyboardFromBtnID (const int btnID)
 
MultitouchDevicegetMultitouchDevice ()
 
void clearMultitouchDevices ()
 
void updateMultitouchDevice ()
 
bool deleteConfig (DeviceConfig *config)
 Delete the given config and removes DeviceManager references to it.
 
bool translateInput (Input::InputType type, int deviceID, int btnID, int axisDir, int *value, InputManager::InputDriverMode mode, StateManager::ActivePlayer **player, PlayerAction *action)
 Given some input, finds to which device it belongs and, using the corresponding device object, maps this input to the corresponding player and game action.
 
void clearLatestUsedDevice ()
 
InputDevicegetLatestUsedDevice ()
 
bool initialize ()
 
void save ()
 
StateManager::ActivePlayergetSinglePlayer ()
 Returns the active player if there is only a single local player.
 
void setSinglePlayer (StateManager::ActivePlayer *p)
 Sets the ActivePlayer if there is only a single local player.
 
void mapFireToSelect (bool v)
 Sets or reset the 'map fire to select' option.
 

Private Member Functions

InputDevicemapGamepadInput (Input::InputType type, int deviceID, int btnID, int axisDir, int *value, InputManager::InputDriverMode mode, StateManager::ActivePlayer **player, PlayerAction *action)
 Helper method, only used internally.
 
InputDevicemapKeyboardInput (int button_id, InputManager::InputDriverMode mode, StateManager::ActivePlayer **player, PlayerAction *action)
 Helper method, only used internally.
 
bool load ()
 Loads the configuration from the user's input.xml file.
 
void shutdown ()
 

Private Attributes

PtrVector< KeyboardDevice, HOLD > m_keyboards
 
PtrVector< GamePadDevice, HOLD > m_gamepads
 
PtrVector< KeyboardConfig, HOLD > m_keyboard_configs
 
PtrVector< GamepadConfig, HOLD > m_gamepad_configs
 
MultitouchDevicem_multitouch_device
 
InputDevicem_latest_used_device
 
PlayerAssignMode m_assign_mode
 
StateManager::ActivePlayerm_single_player
 Will be non-null in single-player mode.
 
bool m_map_fire_to_select
 If this is flag is set the next fire event (if the fire key is not mapped to anything else) will be mapped to 'select'.
 

Detailed Description

This class holds the list of all known devices (ands their configurations), as well as the list of currently plugged (used) devices.

It thus takes care of finding to which device any given input belongs, and what action each keypress is bound to, if any (and, since each device is associated to a player, it also finds which player triggered this action) These input mapping capabilities should only be used through the InputManager, not directly.

The device manager starts in "no-assign" mode, which means no input configuration is associated to any player. So all devices will react. This is used in menus before player set-up is done. Switching back to no-assign mode will also clear anything in devices that was associated with players in assign mode.

Member Function Documentation

◆ getConfigForGamepad()

bool DeviceManager::getConfigForGamepad ( const int  irr_id,
const std::string &  name,
GamepadConfig **  config 
)

Returns the keyboard that has a binding for this button, or NULL if none.

Check if we already have a config object for gamepad 'irr_id' as reported by irrLicht, If no, create one.

Returns true if new configuration was created, otherwise false.

◆ getSinglePlayer()

StateManager::ActivePlayer * DeviceManager::getSinglePlayer ( )
inline

Returns the active player if there is only a single local player.

It returns NULL if multiplayer is active.

◆ mapGamepadInput()

InputDevice * DeviceManager::mapGamepadInput ( Input::InputType  type,
int  device_id,
int  button_id,
int  axis_dir,
int *  value,
InputManager::InputDriverMode  mode,
StateManager::ActivePlayer **  player,
PlayerAction action 
)
private

Helper method, only used internally.

Takes care of analyzing gamepad input.

Parameters
[in]typeType of gamepad event (IT_STICKMOTION etc).
[out]playerWhich player this input belongs to (only set in ASSIGN mode)
[out]actionWhich action is related to this input trigger
modeUsed to determine whether to determine menu actions or game actions
Returns
The device to which this input belongs

◆ mapKeyboardInput()

InputDevice * DeviceManager::mapKeyboardInput ( int  button_id,
InputManager::InputDriverMode  mode,
StateManager::ActivePlayer **  player,
PlayerAction action 
)
private

Helper method, only used internally.

Takes care of analyzing keyboard input.

Parameters
[in]button_idId of the key pressed.
[in]modeUsed to determine whether to determine menu actions or game actions
[out]playerWhich player this input belongs to (only set in ASSIGN mode).
[out]actionWhich action is related to this input trigger.
Returns
The device to which this input belongs

◆ setSinglePlayer()

void DeviceManager::setSinglePlayer ( StateManager::ActivePlayer p)
inline

Sets the ActivePlayer if there is only a single local player.

p must be NULL in case of splitscreen. A single player will receive events from all connected devices. This allows for example a single player to select a kart with the keyboard, but then use a gamepad for the actual racing. In splitscreen each player will only receive events from the device used to connect in the kart selection screen.

◆ translateInput()

bool DeviceManager::translateInput ( Input::InputType  type,
int  deviceID,
int  btnID,
int  axisDir,
int *  value,
InputManager::InputDriverMode  mode,
StateManager::ActivePlayer **  player,
PlayerAction action 
)

Given some input, finds to which device it belongs and, using the corresponding device object, maps this input to the corresponding player and game action.

Returns
false if player/action could not be set.
Note
Special case : can return 'true' but set action to PA_BEFORE_FIRST if the input was used but is not associated to an action and a player
Parameters
modeused to determine whether to map game actions or menu actions

Member Data Documentation

◆ m_map_fire_to_select

bool DeviceManager::m_map_fire_to_select
private

If this is flag is set the next fire event (if the fire key is not mapped to anything else) will be mapped to 'select'.

This is used in the kart select GUI to support the old way of adding players by pressing fire.


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