Removed number of axes and buttons from GamepadDevice, and use the
values from GamepadConfig instead.
This commit is contained in:
parent
e9980fcb2f
commit
4986deebd6
@ -23,6 +23,7 @@
|
||||
#include "input/input.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <iosfwd>
|
||||
#include <irrString.h>
|
||||
#include <string>
|
||||
@ -93,11 +94,29 @@ public:
|
||||
irr::core::stringw getBindingAsString(const PlayerAction action) const;
|
||||
virtual bool isGamePad() const = 0;
|
||||
virtual bool isKeyboard() const = 0;
|
||||
|
||||
virtual void save(std::ofstream& stream);
|
||||
virtual bool load(const XMLNode *config);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Should only be called for gamepads, which has its own implementation.
|
||||
* of this function. */
|
||||
virtual int getNumberOfButtons() const
|
||||
{
|
||||
assert(false); return 0;
|
||||
} // getNumberOfButtons
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Should only be called for gamepads, which has its own implementation.
|
||||
* of this function. */
|
||||
virtual int getNumberOfAxes() const
|
||||
{
|
||||
assert(false); return 0;
|
||||
} // getNumberOfAxes
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the name of this device. */
|
||||
void setName(const std::string &name) { m_name = name; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the name for this device configuration. */
|
||||
const std::string& getName() const { return m_name; };
|
||||
|
@ -57,10 +57,18 @@ public:
|
||||
const int axis_count=0,
|
||||
const int button_ount=0);
|
||||
virtual bool load(const XMLNode *config) OVERRIDE;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of buttons in this configuration. */
|
||||
virtual int getNumberOfButtons() const OVERRIDE { return m_button_count; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the number of buttons this device has. */
|
||||
void setNumberOfButtons(int count) { m_button_count = count; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of axis of this configufation. */
|
||||
virtual int getNumberOfAxes() const OVERRIDE { return m_axis_count; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the number of axis this device has. */
|
||||
void setNumberOfAxis(int count) { m_axis_count = count; }
|
||||
|
@ -35,11 +35,23 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
|
||||
m_type = DT_GAMEPAD;
|
||||
m_prev_axis_directions = NULL;
|
||||
m_configuration = configuration;
|
||||
m_axis_count = axis_count;
|
||||
GamepadConfig *config = static_cast<GamepadConfig*>(m_configuration);
|
||||
if(m_configuration->getNumberOfButtons()!=button_count)
|
||||
{
|
||||
Log::warn("GamePadDevice",
|
||||
"Different number of buttons for '%s': was %d now %d.",
|
||||
getName().c_str(), config->getNumberOfButtons(),
|
||||
button_count);
|
||||
}
|
||||
if(m_configuration->getNumberOfAxes()!=axis_count)
|
||||
{
|
||||
Log::warn("GamePadDevice",
|
||||
"Different number of axis for '%s': was %d now %d.",
|
||||
getName().c_str(), config->getNumberOfAxes(), axis_count);
|
||||
}
|
||||
m_prev_axis_directions = new Input::AxisDirection[axis_count];
|
||||
m_prev_axis_value = new int[axis_count];
|
||||
m_axis_ok = new bool[axis_count];
|
||||
m_button_count = button_count;
|
||||
m_irr_index = irr_index;
|
||||
m_name = name;
|
||||
|
||||
@ -74,6 +86,13 @@ bool GamePadDevice::moved(int value) const
|
||||
return abs(value) > dz;
|
||||
} // moved
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns the number of buttons of this gamepad. */
|
||||
int GamePadDevice::getNumberOfButtons() const
|
||||
{
|
||||
return m_configuration->getNumberOfButtons();
|
||||
} // getNumberOfButtons
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GamePadDevice::isButtonPressed(const int i)
|
||||
{
|
||||
@ -148,7 +167,7 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
|
||||
if (type == Input::IT_STICKMOTION)
|
||||
{
|
||||
// this gamepad doesn't even have that many axes
|
||||
if (id >= m_axis_count) return false;
|
||||
if (id >= m_configuration->getNumberOfAxes()) return false;
|
||||
|
||||
if (getPlayer())
|
||||
{
|
||||
|
@ -51,12 +51,6 @@ class GamePadDevice : public InputDevice
|
||||
/** 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;
|
||||
|
||||
public:
|
||||
GamePadDevice(const int irrIndex, const std::string &name,
|
||||
const int axis_number,
|
||||
@ -70,6 +64,7 @@ public:
|
||||
InputManager::InputDriverMode mode,
|
||||
PlayerAction *action, int* value = NULL
|
||||
) OVERRIDE;
|
||||
int getNumberOfButtons() const;
|
||||
bool moved(int value) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -77,9 +72,6 @@ public:
|
||||
int getIrrIndex() const { return m_irr_index; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of buttons of this gamepad. */
|
||||
int getNumberOfButtons() const { return m_button_count; }
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}; // class GamepadDevice
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user