Unverified Commit 64a9c094 authored by Rafael Kitover's avatar Rafael Kitover
Browse files

fix analog stick regression from e57beed8 #400



Instead of ignoring the initial state of axes, which I did to make
triggers work on the 360 controller, set the initial previous value to
the initial state instead.

This fixes the original problem without breaking analog stick movement.
Signed-off-by: default avatarRafael Kitover <rkitover@gmail.com>
parent 0f0d2400
...@@ -36,7 +36,7 @@ wxSDLJoy::wxSDLJoy(bool analog) ...@@ -36,7 +36,7 @@ wxSDLJoy::wxSDLJoy(bool analog)
if (!njoy) if (!njoy)
return; return;
joystate = new wxSDLJoyState_t[njoy]; joystate = new wxSDLJoyState[njoy];
memset(joystate, 0, njoy * sizeof(*joystate)); memset(joystate, 0, njoy * sizeof(*joystate));
for (int i = 0; i < njoy; i++) { for (int i = 0; i < njoy; i++) {
...@@ -45,7 +45,17 @@ wxSDLJoy::wxSDLJoy(bool analog) ...@@ -45,7 +45,17 @@ wxSDLJoy::wxSDLJoy(bool analog)
nctrl += joystate[i].nax = SDL_JoystickNumAxes(dev); nctrl += joystate[i].nax = SDL_JoystickNumAxes(dev);
nctrl += joystate[i].nhat = SDL_JoystickNumHats(dev); nctrl += joystate[i].nhat = SDL_JoystickNumHats(dev);
nctrl += joystate[i].nbut = SDL_JoystickNumButtons(dev); nctrl += joystate[i].nbut = SDL_JoystickNumButtons(dev);
joystate[i].curval = new short[nctrl]; joystate[i].curval = new short[nctrl]{0};
// initialize axis previous value to initial state
#if SDL_VERSION_ATLEAST(2, 0, 6)
for (int j = 0; j < joystate[i].nax; j++) {
int16_t initial_state = 0;
SDL_JoystickGetAxisInitialState(dev, j, &initial_state);
joystate[i].curval[j] = initial_state;
}
#endif
memset(joystate[i].curval, 0, sizeof(short) * nctrl); memset(joystate[i].curval, 0, sizeof(short) * nctrl);
} }
} }
...@@ -134,13 +144,6 @@ void wxSDLJoy::Notify() ...@@ -134,13 +144,6 @@ void wxSDLJoy::Notify()
for (int j = 0; j < nax; j++) { for (int j = 0; j < nax; j++) {
val = SDL_JoystickGetAxis(dev, j); val = SDL_JoystickGetAxis(dev, j);
// trigger axes always return max negative value, we ignore these
#if SDL_VERSION_ATLEAST(2, 0, 6)
int16_t initial_state;
if (SDL_JoystickGetAxisInitialState(dev, j, &initial_state) && val == initial_state)
continue;
#endif
if (digital) { if (digital) {
if (val > 0x3fff) if (val > 0x3fff)
val = 0x7fff; val = 0x7fff;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <wx/event.h> #include <wx/event.h>
#include <wx/timer.h> #include <wx/timer.h>
typedef struct wxSDLJoyState wxSDLJoyState_t; struct wxSDLJoyState;
class wxSDLJoy : public wxTimer { class wxSDLJoy : public wxTimer {
public: public:
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
protected: protected:
bool digital; bool digital;
int njoy; int njoy;
wxSDLJoyState_t* joystate; wxSDLJoyState* joystate;
wxEvtHandler* evthandler; wxEvtHandler* evthandler;
bool nosticks; bool nosticks;
void Notify(); void Notify();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment