Merge commit 'e6a134c3479ccdbaf91bb36d46ffb64b6a3b52b9' into improve-xbox-gamepad-support
This commit is contained in:
commit
4c55ca4da9
@ -33,20 +33,27 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
|
|||||||
GamepadConfig *configuration)
|
GamepadConfig *configuration)
|
||||||
{
|
{
|
||||||
m_type = DT_GAMEPAD;
|
m_type = DT_GAMEPAD;
|
||||||
m_prev_axis_directions = NULL;
|
|
||||||
m_configuration = configuration;
|
m_configuration = configuration;
|
||||||
GamepadConfig *config = static_cast<GamepadConfig*>(m_configuration);
|
GamepadConfig *config = static_cast<GamepadConfig*>(m_configuration);
|
||||||
if(m_configuration->getNumberOfButtons()<button_count)
|
if(m_configuration->getNumberOfButtons()<button_count)
|
||||||
{
|
{
|
||||||
config->setNumberOfButtons(button_count);
|
config->setNumberOfButtons(button_count);
|
||||||
}
|
}
|
||||||
if(m_configuration->getNumberOfAxes()<axis_count)
|
|
||||||
|
// HAT/POV buttons will be reported as additional axis with the values
|
||||||
|
// HAT_V_ID > HAT_H_ID. So increase the number of axis to be large
|
||||||
|
// enough to handle HAT_V/H_ID as axis number.
|
||||||
|
assert(Input::HAT_V_ID > Input::HAT_H_ID);
|
||||||
|
int adj_axis_count = axis_count > Input::HAT_V_ID ? axis_count
|
||||||
|
: Input::HAT_V_ID+1;
|
||||||
|
|
||||||
|
if(m_configuration->getNumberOfAxes()<adj_axis_count)
|
||||||
{
|
{
|
||||||
config->setNumberOfAxis(axis_count);
|
config->setNumberOfAxis(adj_axis_count);
|
||||||
}
|
}
|
||||||
m_prev_axis_directions = new Input::AxisDirection[axis_count];
|
m_prev_axis_directions.resize(adj_axis_count);
|
||||||
m_prev_axis_value = new int[axis_count];
|
m_prev_axis_value.resize(adj_axis_count);
|
||||||
m_axis_ok = new bool[axis_count];
|
m_axis_ok.resize(adj_axis_count);
|
||||||
m_irr_index = irr_index;
|
m_irr_index = irr_index;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
|
||||||
@ -57,9 +64,9 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
|
|||||||
m_axis_ok[i] = false;
|
m_axis_ok[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_buttonPressed = new bool[button_count];
|
m_button_pressed.resize(button_count);
|
||||||
for(int n=0; n<button_count; n++)
|
for(int n=0; n<button_count; n++)
|
||||||
m_buttonPressed[n] = false;
|
m_button_pressed[n] = false;
|
||||||
} // GamePadDevice
|
} // GamePadDevice
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -67,12 +74,6 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
|
|||||||
*/
|
*/
|
||||||
GamePadDevice::~GamePadDevice()
|
GamePadDevice::~GamePadDevice()
|
||||||
{
|
{
|
||||||
delete[] m_buttonPressed;
|
|
||||||
delete[] m_prev_axis_directions;
|
|
||||||
delete[] m_prev_axis_value;
|
|
||||||
delete[] m_axis_ok;
|
|
||||||
|
|
||||||
// FIXME - any need to close devices?
|
|
||||||
} // ~GamePadDevice
|
} // ~GamePadDevice
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -93,14 +94,14 @@ int GamePadDevice::getNumberOfButtons() const
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool GamePadDevice::isButtonPressed(const int i)
|
bool GamePadDevice::isButtonPressed(const int i)
|
||||||
{
|
{
|
||||||
return m_buttonPressed[i];
|
return m_button_pressed[i];
|
||||||
} // isButtonPressed
|
} // isButtonPressed
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||||
{
|
{
|
||||||
m_buttonPressed[i] = isButtonPressed;
|
m_button_pressed[i] = isButtonPressed;
|
||||||
} // setButtonPressed
|
} // setButtonPressed
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -182,7 +183,7 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if(m_prev_axis_directions == NULL) return false; // device not open
|
if(m_prev_axis_directions.size() == 0) return false; // device not open
|
||||||
|
|
||||||
if (type == Input::IT_STICKMOTION)
|
if (type == Input::IT_STICKMOTION)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "input/input_device.hpp"
|
#include "input/input_device.hpp"
|
||||||
#include "utils/cpp2011.hpp"
|
#include "utils/cpp2011.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
class GamepadConfig;
|
class GamepadConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,9 +32,9 @@ class GamepadConfig;
|
|||||||
class GamePadDevice : public InputDevice
|
class GamePadDevice : public InputDevice
|
||||||
{
|
{
|
||||||
void resetAxisDirection(const int axis, Input::AxisDirection direction);
|
void resetAxisDirection(const int axis, Input::AxisDirection direction);
|
||||||
bool* m_buttonPressed;
|
std::vector<bool> m_button_pressed;
|
||||||
|
|
||||||
Input::AxisDirection *m_prev_axis_directions;
|
std::vector<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
|
||||||
* when at least 2 different values are read from this axis (if an axis
|
* when at least 2 different values are read from this axis (if an axis
|
||||||
@ -43,10 +44,10 @@ class GamePadDevice : public InputDevice
|
|||||||
* on linux some hard disks may be reported as gamepads with
|
* on linux some hard disks may be reported as gamepads with
|
||||||
* uninteresting axis values)
|
* uninteresting axis values)
|
||||||
*/
|
*/
|
||||||
int *m_prev_axis_value;
|
std::vector<int> m_prev_axis_value;
|
||||||
|
|
||||||
/** \see m_prev_axis_value */
|
/** \see m_prev_axis_value */
|
||||||
bool *m_axis_ok;
|
std::vector<bool> m_axis_ok;
|
||||||
|
|
||||||
/** Irrlicht index of this gamepad. */
|
/** Irrlicht index of this gamepad. */
|
||||||
int m_irr_index;
|
int m_irr_index;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user