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();
|
||||
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);
|
||||
@ -317,7 +317,7 @@ InputDevice* DeviceManager::mapKeyboardInput(int button_id,
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -363,7 +363,7 @@ InputDevice *DeviceManager::mapGamepadInput(Input::InputType type,
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -23,7 +23,12 @@
|
||||
#include "karts/abstract_kart.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,
|
||||
GamepadConfig *configuration)
|
||||
{
|
||||
@ -35,7 +40,7 @@ GamePadDevice::GamePadDevice(const int irrIndex, const std::string name,
|
||||
m_prev_axis_value = new int[axis_count];
|
||||
m_axis_ok = new bool[axis_count];
|
||||
m_button_count = button_count;
|
||||
m_index = irrIndex;
|
||||
m_irr_index = irr_index;
|
||||
m_name = name;
|
||||
|
||||
for (int i = 0; i < axis_count; i++)
|
||||
@ -107,11 +112,26 @@ void GamePadDevice::resetAxisDirection(const int axis,
|
||||
} // 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 */,
|
||||
Input::InputType type, const int id,
|
||||
bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
||||
InputManager::InputDriverMode mode,
|
||||
int* value/* inout */)
|
||||
PlayerAction* action /* out */,
|
||||
int* value /* inout */ )
|
||||
{
|
||||
if (!m_configuration->isEnabled()) return false;
|
||||
|
||||
|
@ -20,8 +20,10 @@
|
||||
#define HEADER_GAMEPAD_DEVICE_HPP
|
||||
|
||||
#include "input/input_device.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
class GamepadConfig;
|
||||
|
||||
/**
|
||||
* \brief specialisation of Inputdevice for gamepad type devices
|
||||
* \ingroup input
|
||||
@ -31,7 +33,6 @@ class GamePadDevice : public InputDevice
|
||||
void resetAxisDirection(const int axis, Input::AxisDirection direction);
|
||||
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
||||
|
||||
public:
|
||||
Input::AxisDirection *m_prev_axis_directions;
|
||||
|
||||
/** used to determine if an axis is valid; an axis is considered valid
|
||||
@ -43,46 +44,45 @@ public:
|
||||
* uninteresting axis values)
|
||||
*/
|
||||
int *m_prev_axis_value;
|
||||
|
||||
/** \see m_prev_axis_value */
|
||||
bool *m_axis_ok;
|
||||
|
||||
/** Deadzone for this gamepad. */
|
||||
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;
|
||||
|
||||
/** Number of buttons of this gamepad. */
|
||||
int m_button_count;
|
||||
|
||||
/** 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(const int irrIndex, const std::string name,
|
||||
const int axis_number,
|
||||
const int btnAmount, GamepadConfig *configuration);
|
||||
public:
|
||||
GamePadDevice(const int irrIndex, const std::string &name,
|
||||
const int axis_number,
|
||||
const int button_count,
|
||||
GamepadConfig *configuration);
|
||||
virtual ~GamePadDevice();
|
||||
bool isButtonPressed(const int i);
|
||||
void setButtonPressed(const int i, bool isButtonPressed);
|
||||
|
||||
bool isButtonPressed(const int i);
|
||||
void setButtonPressed(const int i, bool isButtonPressed);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
};
|
||||
virtual bool processAndMapInput(Input::InputType type, const int id,
|
||||
InputManager::InputDriverMode mode,
|
||||
PlayerAction *action, int* value = NULL
|
||||
) OVERRIDE;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** 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
|
||||
|
@ -62,20 +62,25 @@ public:
|
||||
|
||||
InputDevice();
|
||||
virtual ~InputDevice();
|
||||
bool processAndMapInput(PlayerAction* action, Input::InputType type, int id, InputManager::InputDriverMode mode);
|
||||
|
||||
bool processAndMapInput(PlayerAction* action, Input::InputType type, const int id,
|
||||
int* value, InputManager::InputDriverMode mode);
|
||||
|
||||
#ifdef NOTYET
|
||||
virtual bool processAndMapInput(PlayerAction *action,
|
||||
Input::InputType type,
|
||||
|
||||
const int id,
|
||||
int* value,
|
||||
/** 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
|
||||
*/
|
||||
virtual bool processAndMapInput(Input::InputType type, const int id,
|
||||
InputManager::InputDriverMode mode,
|
||||
PlayerAction* action) = 0;
|
||||
#endif
|
||||
PlayerAction *action, int* value = NULL
|
||||
) = 0;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** 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);
|
||||
|
||||
if (gp != NULL &&
|
||||
abs(value)>gp->m_deadzone)
|
||||
abs(value)>gp->getDeadzone())
|
||||
{
|
||||
//I18N: message shown when an input device is used but
|
||||
// is not associated to any player
|
||||
@ -778,7 +778,7 @@ EventPropagation InputManager::input(const SEvent& event)
|
||||
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);
|
||||
|
||||
|
@ -38,11 +38,24 @@ KeyboardDevice::KeyboardDevice()
|
||||
} // KeyboardDevice
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool KeyboardDevice::processAndMapInput(PlayerAction* action /* out */,
|
||||
Input::InputType type,
|
||||
const 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
|
||||
* 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 KeyboardDevice::processAndMapInput(Input::InputType type, const int id,
|
||||
InputManager::InputDriverMode mode,
|
||||
PlayerAction *action, int* value)
|
||||
{
|
||||
assert(type==Input::IT_KEYBOARD);
|
||||
if (mode == InputManager::INGAME)
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "input/input_device.hpp"
|
||||
|
||||
#include "input/input.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
class KeyboardConfig;
|
||||
|
||||
@ -37,20 +37,10 @@ public:
|
||||
KeyboardDevice(KeyboardConfig *configuration);
|
||||
|
||||
virtual ~KeyboardDevice() {}
|
||||
|
||||
/**
|
||||
* Checks if this key belongs to this device. if yes, sets action and
|
||||
* returns true; otherwise returns false
|
||||
*
|
||||
* \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);
|
||||
virtual bool processAndMapInput(Input::InputType type, const int id,
|
||||
InputManager::InputDriverMode mode,
|
||||
PlayerAction *action, int* value = NULL
|
||||
) OVERRIDE;
|
||||
|
||||
}; // KeyboardDevice
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user