diff --git a/src/input/gamepad_device.cpp b/src/input/gamepad_device.cpp index da1b546b7..423c1894f 100644 --- a/src/input/gamepad_device.cpp +++ b/src/input/gamepad_device.cpp @@ -33,20 +33,27 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name, GamepadConfig *configuration) { m_type = DT_GAMEPAD; - m_prev_axis_directions = NULL; m_configuration = configuration; GamepadConfig *config = static_cast(m_configuration); if(m_configuration->getNumberOfButtons()setNumberOfButtons(button_count); } - if(m_configuration->getNumberOfAxes() 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()setNumberOfAxis(axis_count); + config->setNumberOfAxis(adj_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_prev_axis_directions.resize(adj_axis_count); + m_prev_axis_value.resize(adj_axis_count); + m_axis_ok.resize(adj_axis_count); m_irr_index = irr_index; m_name = name; @@ -57,9 +64,9 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name, m_axis_ok[i] = false; } - m_buttonPressed = new bool[button_count]; + m_button_pressed.resize(button_count); for(int n=0; n class GamepadConfig; /** @@ -31,9 +32,9 @@ class GamepadConfig; class GamePadDevice : public InputDevice { void resetAxisDirection(const int axis, Input::AxisDirection direction); - bool* m_buttonPressed; + std::vector m_button_pressed; - Input::AxisDirection *m_prev_axis_directions; + std::vector m_prev_axis_directions; /** 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 @@ -43,10 +44,10 @@ class GamePadDevice : public InputDevice * on linux some hard disks may be reported as gamepads with * uninteresting axis values) */ - int *m_prev_axis_value; + std::vector m_prev_axis_value; /** \see m_prev_axis_value */ - bool *m_axis_ok; + std::vector m_axis_ok; /** Irrlicht index of this gamepad. */ int m_irr_index;