Made processAndMapInput a pure virtual function of InputDevice, which
is implemented in Keyboard- and GamepadDevice.
This commit is contained in:
parent
9d5fd13ae9
commit
92196c7534
@ -184,7 +184,7 @@ GamePadDevice* DeviceManager::getGamePadFromIrrID(const int id)
|
|||||||
const int count = m_gamepads.size();
|
const int count = m_gamepads.size();
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if (m_gamepads[i].m_index == id)
|
if (m_gamepads[i].getIrrIndex()== id)
|
||||||
{
|
{
|
||||||
|
|
||||||
return m_gamepads.get(i);
|
return m_gamepads.get(i);
|
||||||
@ -317,7 +317,7 @@ InputDevice* DeviceManager::mapKeyboardInput(int button_id,
|
|||||||
{
|
{
|
||||||
KeyboardDevice *keyboard = m_keyboards.get(n);
|
KeyboardDevice *keyboard = m_keyboards.get(n);
|
||||||
|
|
||||||
if (keyboard->processAndMapInput(action, Input::IT_KEYBOARD, button_id, mode))
|
if (keyboard->processAndMapInput(Input::IT_KEYBOARD, button_id, mode, action))
|
||||||
{
|
{
|
||||||
if (m_single_player != NULL)
|
if (m_single_player != NULL)
|
||||||
{
|
{
|
||||||
@ -363,7 +363,7 @@ InputDevice *DeviceManager::mapGamepadInput(Input::InputType type,
|
|||||||
|
|
||||||
if (gPad != NULL)
|
if (gPad != NULL)
|
||||||
{
|
{
|
||||||
if (gPad->processAndMapInput(action, type, button_id, mode, value))
|
if (gPad->processAndMapInput(type, button_id, mode, action, value))
|
||||||
{
|
{
|
||||||
if (m_single_player != NULL)
|
if (m_single_player != NULL)
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,12 @@
|
|||||||
#include "karts/abstract_kart.hpp"
|
#include "karts/abstract_kart.hpp"
|
||||||
#include "karts/controller/player_controller.hpp"
|
#include "karts/controller/player_controller.hpp"
|
||||||
|
|
||||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name,
|
/** Constructor for GamePadDevice from a connected gamepad for which no
|
||||||
|
* configuration existed (defaults will be used)
|
||||||
|
* \param irrIndex Index of stick as given by irrLicht.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
|
||||||
const int axis_count, const int button_count,
|
const int axis_count, const int button_count,
|
||||||
GamepadConfig *configuration)
|
GamepadConfig *configuration)
|
||||||
{
|
{
|
||||||
@ -35,7 +40,7 @@ GamePadDevice::GamePadDevice(const int irrIndex, const std::string name,
|
|||||||
m_prev_axis_value = new int[axis_count];
|
m_prev_axis_value = new int[axis_count];
|
||||||
m_axis_ok = new bool[axis_count];
|
m_axis_ok = new bool[axis_count];
|
||||||
m_button_count = button_count;
|
m_button_count = button_count;
|
||||||
m_index = irrIndex;
|
m_irr_index = irr_index;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
for (int i = 0; i < axis_count; i++)
|
for (int i = 0; i < axis_count; i++)
|
||||||
@ -107,11 +112,26 @@ void GamePadDevice::resetAxisDirection(const int axis,
|
|||||||
} // resetAxisDirection
|
} // resetAxisDirection
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Invoked when this device it used. Verifies if the key/button that was
|
||||||
|
* pressed is associated with a binding. If yes, sets action and returns
|
||||||
|
* true; otherwise returns false. It can also modify the value used.
|
||||||
|
* \param type Type of input (e.g. IT_STICKMOTION, ...).
|
||||||
|
* \param id ID of the key that was pressed or of the axis that was
|
||||||
|
* triggered (depending on the value of the 'type' parameter).
|
||||||
|
* \param mode Used to determine whether to map menu actions or
|
||||||
|
* game actions
|
||||||
|
* \param[out] action The action associated to this input (only check
|
||||||
|
* this value if method returned true)
|
||||||
|
* \param[in,out] value The value associated with this type (typically
|
||||||
|
* how far a gamepad axis is moved).
|
||||||
|
*
|
||||||
|
* \return Whether the pressed key/button is bound with an action
|
||||||
|
*/
|
||||||
|
|
||||||
bool GamePadDevice::processAndMapInput(PlayerAction* action /* out */,
|
bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
||||||
Input::InputType type, const int id,
|
|
||||||
InputManager::InputDriverMode mode,
|
InputManager::InputDriverMode mode,
|
||||||
int* value/* inout */)
|
PlayerAction* action /* out */,
|
||||||
|
int* value /* inout */ )
|
||||||
{
|
{
|
||||||
if (!m_configuration->isEnabled()) return false;
|
if (!m_configuration->isEnabled()) return false;
|
||||||
|
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
#define HEADER_GAMEPAD_DEVICE_HPP
|
#define HEADER_GAMEPAD_DEVICE_HPP
|
||||||
|
|
||||||
#include "input/input_device.hpp"
|
#include "input/input_device.hpp"
|
||||||
|
#include "utils/cpp2011.hpp"
|
||||||
|
|
||||||
class GamepadConfig;
|
class GamepadConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief specialisation of Inputdevice for gamepad type devices
|
* \brief specialisation of Inputdevice for gamepad type devices
|
||||||
* \ingroup input
|
* \ingroup input
|
||||||
@ -31,7 +33,6 @@ class GamePadDevice : public InputDevice
|
|||||||
void resetAxisDirection(const int axis, Input::AxisDirection direction);
|
void resetAxisDirection(const int axis, Input::AxisDirection direction);
|
||||||
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
||||||
|
|
||||||
public:
|
|
||||||
Input::AxisDirection *m_prev_axis_directions;
|
Input::AxisDirection *m_prev_axis_directions;
|
||||||
|
|
||||||
/** used to determine if an axis is valid; an axis is considered valid
|
/** used to determine if an axis is valid; an axis is considered valid
|
||||||
@ -43,46 +44,45 @@ public:
|
|||||||
* uninteresting axis values)
|
* uninteresting axis values)
|
||||||
*/
|
*/
|
||||||
int *m_prev_axis_value;
|
int *m_prev_axis_value;
|
||||||
|
|
||||||
/** \see m_prev_axis_value */
|
/** \see m_prev_axis_value */
|
||||||
bool *m_axis_ok;
|
bool *m_axis_ok;
|
||||||
|
|
||||||
|
/** Deadzone for this gamepad. */
|
||||||
int m_deadzone;
|
int m_deadzone;
|
||||||
int m_index;
|
|
||||||
|
/** Irrlicht index of this gamepad. */
|
||||||
|
int m_irr_index;
|
||||||
|
|
||||||
|
/** Number of axis for this gamepad. */
|
||||||
int m_axis_count;
|
int m_axis_count;
|
||||||
|
|
||||||
|
/** Number of buttons of this gamepad. */
|
||||||
int m_button_count;
|
int m_button_count;
|
||||||
|
|
||||||
/** Constructor for GamePadDevice from a connected gamepad for which no
|
public:
|
||||||
* configuration existed (defaults will be used)
|
GamePadDevice(const int irrIndex, const std::string &name,
|
||||||
* \param irrIndex Index of stick as given by irrLicht.
|
const int axis_number,
|
||||||
*/
|
const int button_count,
|
||||||
GamePadDevice(const int irrIndex, const std::string name,
|
GamepadConfig *configuration);
|
||||||
const int axis_number,
|
|
||||||
const int btnAmount, GamepadConfig *configuration);
|
|
||||||
virtual ~GamePadDevice();
|
virtual ~GamePadDevice();
|
||||||
|
bool isButtonPressed(const int i);
|
||||||
|
void setButtonPressed(const int i, bool isButtonPressed);
|
||||||
|
|
||||||
bool isButtonPressed(const int i);
|
virtual bool processAndMapInput(Input::InputType type, const int id,
|
||||||
void setButtonPressed(const int i, bool isButtonPressed);
|
InputManager::InputDriverMode mode,
|
||||||
|
PlayerAction *action, int* value = NULL
|
||||||
/**
|
) OVERRIDE;
|
||||||
* Invoked when this device it used. Verifies if the key/button that
|
|
||||||
* was pressed is associated with a binding. If yes, sets action and
|
|
||||||
* returns true; otherwise returns false.
|
|
||||||
*
|
|
||||||
* \param id ID of the key that was pressed or of the axis
|
|
||||||
* that was triggered (depending on
|
|
||||||
* the value of the 'type' parameter)
|
|
||||||
* \param mode Used to determine whether to map menu actions or
|
|
||||||
* game actions
|
|
||||||
* \param[out] action The action associated to this input (only check
|
|
||||||
* this value if method returned true)
|
|
||||||
*
|
|
||||||
* \return Whether the pressed key/button is bound with an action
|
|
||||||
*/
|
|
||||||
bool processAndMapInput(PlayerAction* action, Input::InputType type,
|
|
||||||
const int id,
|
|
||||||
InputManager::InputDriverMode mode, int* value);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the irrlicht index of this gamepad. */
|
||||||
|
int getIrrIndex() const { return m_irr_index; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the deadzone of this gamepad. */
|
||||||
|
int getDeadzone() const { return m_deadzone; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the number of buttons of this gamepad. */
|
||||||
|
int getNumberOfButtons() const { return m_button_count; }
|
||||||
|
}; // class GamepadDevice
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -62,20 +62,25 @@ public:
|
|||||||
|
|
||||||
InputDevice();
|
InputDevice();
|
||||||
virtual ~InputDevice();
|
virtual ~InputDevice();
|
||||||
bool processAndMapInput(PlayerAction* action, Input::InputType type, int id, InputManager::InputDriverMode mode);
|
/** Invoked when this device it used. Verifies if the key/button that was
|
||||||
|
* pressed is associated with a binding. If yes, sets action and returns
|
||||||
bool processAndMapInput(PlayerAction* action, Input::InputType type, const int id,
|
* true; otherwise returns false. It can also modify the value used.
|
||||||
int* value, InputManager::InputDriverMode mode);
|
* \param type Type of input (e.g. IT_STICKMOTION, ...).
|
||||||
|
* \param id ID of the key that was pressed or of the axis that was
|
||||||
#ifdef NOTYET
|
* triggered (depending on the value of the 'type' parameter).
|
||||||
virtual bool processAndMapInput(PlayerAction *action,
|
* \param mode Used to determine whether to map menu actions or
|
||||||
Input::InputType type,
|
* game actions
|
||||||
|
* \param[out] action The action associated to this input (only check
|
||||||
const int id,
|
* this value if method returned true)
|
||||||
int* value,
|
* \param[in,out] value The value associated with this type (typically
|
||||||
|
* how far a gamepad axis is moved).
|
||||||
|
*
|
||||||
|
* \return Whether the pressed key/button is bound with an action
|
||||||
|
*/
|
||||||
|
virtual bool processAndMapInput(Input::InputType type, const int id,
|
||||||
InputManager::InputDriverMode mode,
|
InputManager::InputDriverMode mode,
|
||||||
PlayerAction* action) = 0;
|
PlayerAction *action, int* value = NULL
|
||||||
#endif
|
) = 0;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Sets which players uses this device; or pass NULL to say no player
|
/** Sets which players uses this device; or pass NULL to say no player
|
||||||
|
@ -640,7 +640,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
|
|||||||
getDeviceManager()->getGamePadFromIrrID(deviceID);
|
getDeviceManager()->getGamePadFromIrrID(deviceID);
|
||||||
|
|
||||||
if (gp != NULL &&
|
if (gp != NULL &&
|
||||||
abs(value)>gp->m_deadzone)
|
abs(value)>gp->getDeadzone())
|
||||||
{
|
{
|
||||||
//I18N: message shown when an input device is used but
|
//I18N: message shown when an input device is used but
|
||||||
// is not associated to any player
|
// is not associated to any player
|
||||||
@ -778,7 +778,7 @@ EventPropagation InputManager::input(const SEvent& event)
|
|||||||
return EVENT_BLOCK;
|
return EVENT_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<gp->m_button_count; i++)
|
for(int i=0; i<gp->getNumberOfButtons(); i++)
|
||||||
{
|
{
|
||||||
const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i);
|
const bool isButtonPressed = event.JoystickEvent.IsButtonPressed(i);
|
||||||
|
|
||||||
|
@ -38,11 +38,24 @@ KeyboardDevice::KeyboardDevice()
|
|||||||
} // KeyboardDevice
|
} // KeyboardDevice
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Invoked when this device it used. Verifies if the key/button that was
|
||||||
bool KeyboardDevice::processAndMapInput(PlayerAction* action /* out */,
|
* pressed is associated with a binding. If yes, sets action and returns
|
||||||
Input::InputType type,
|
* true; otherwise returns false. It can also modify the value used.
|
||||||
const int id,
|
* \param type Type of input (e.g. IT_STICKMOTION, ...).
|
||||||
InputManager::InputDriverMode mode)
|
* \param id ID of the key that was pressed or of the axis that was
|
||||||
|
* triggered (depending on the value of the 'type' parameter).
|
||||||
|
* \param mode Used to determine whether to map menu actions or
|
||||||
|
* game actions
|
||||||
|
* \param[out] action The action associated to this input (only check
|
||||||
|
* this value if method returned true)
|
||||||
|
* \param[in,out] value The value associated with this type (typically
|
||||||
|
* how far a gamepad axis is moved).
|
||||||
|
*
|
||||||
|
* \return Whether the pressed key/button is bound with an action
|
||||||
|
*/
|
||||||
|
bool KeyboardDevice::processAndMapInput(Input::InputType type, const int id,
|
||||||
|
InputManager::InputDriverMode mode,
|
||||||
|
PlayerAction *action, int* value)
|
||||||
{
|
{
|
||||||
assert(type==Input::IT_KEYBOARD);
|
assert(type==Input::IT_KEYBOARD);
|
||||||
if (mode == InputManager::INGAME)
|
if (mode == InputManager::INGAME)
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "input/input_device.hpp"
|
#include "input/input_device.hpp"
|
||||||
|
|
||||||
#include "input/input.hpp"
|
#include "utils/cpp2011.hpp"
|
||||||
|
|
||||||
class KeyboardConfig;
|
class KeyboardConfig;
|
||||||
|
|
||||||
@ -37,20 +37,10 @@ public:
|
|||||||
KeyboardDevice(KeyboardConfig *configuration);
|
KeyboardDevice(KeyboardConfig *configuration);
|
||||||
|
|
||||||
virtual ~KeyboardDevice() {}
|
virtual ~KeyboardDevice() {}
|
||||||
|
virtual bool processAndMapInput(Input::InputType type, const int id,
|
||||||
/**
|
InputManager::InputDriverMode mode,
|
||||||
* Checks if this key belongs to this device. if yes, sets action and
|
PlayerAction *action, int* value = NULL
|
||||||
* returns true; otherwise returns false
|
) OVERRIDE;
|
||||||
*
|
|
||||||
* \param id ID of the key that was pressed
|
|
||||||
* \param mode Used to determine whether to bind menu actions or
|
|
||||||
* game actions
|
|
||||||
* \param[out] action The action associated to this input (only check
|
|
||||||
* this value if method returned true)
|
|
||||||
*/
|
|
||||||
bool processAndMapInput(PlayerAction* action, Input::InputType type,
|
|
||||||
const int id,
|
|
||||||
InputManager::InputDriverMode mode);
|
|
||||||
|
|
||||||
}; // KeyboardDevice
|
}; // KeyboardDevice
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user