From 64a9c0945f870d150d194865e8b9d342b2630b6f Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Mon, 1 Apr 2019 09:38:51 -0700 Subject: [PATCH] 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: Rafael Kitover --- src/wx/widgets/sdljoy.cpp | 21 ++++++++++++--------- src/wx/widgets/wx/sdljoy.h | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/wx/widgets/sdljoy.cpp b/src/wx/widgets/sdljoy.cpp index aafc2696..a7e60b00 100644 --- a/src/wx/widgets/sdljoy.cpp +++ b/src/wx/widgets/sdljoy.cpp @@ -36,7 +36,7 @@ wxSDLJoy::wxSDLJoy(bool analog) if (!njoy) return; - joystate = new wxSDLJoyState_t[njoy]; + joystate = new wxSDLJoyState[njoy]; memset(joystate, 0, njoy * sizeof(*joystate)); for (int i = 0; i < njoy; i++) { @@ -45,7 +45,17 @@ wxSDLJoy::wxSDLJoy(bool analog) nctrl += joystate[i].nax = SDL_JoystickNumAxes(dev); nctrl += joystate[i].nhat = SDL_JoystickNumHats(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); } } @@ -134,13 +144,6 @@ void wxSDLJoy::Notify() for (int j = 0; j < nax; 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 (val > 0x3fff) val = 0x7fff; diff --git a/src/wx/widgets/wx/sdljoy.h b/src/wx/widgets/wx/sdljoy.h index bdc7b194..9fcd3cef 100644 --- a/src/wx/widgets/wx/sdljoy.h +++ b/src/wx/widgets/wx/sdljoy.h @@ -13,7 +13,7 @@ #include #include -typedef struct wxSDLJoyState wxSDLJoyState_t; +struct wxSDLJoyState; class wxSDLJoy : public wxTimer { public: @@ -61,7 +61,7 @@ public: protected: bool digital; int njoy; - wxSDLJoyState_t* joystate; + wxSDLJoyState* joystate; wxEvtHandler* evthandler; bool nosticks; void Notify();