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 <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-04-01 09:38:51 -07:00
parent 0f0d2400bc
commit 64a9c0945f
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
2 changed files with 14 additions and 11 deletions

View File

@ -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;

View File

@ -13,7 +13,7 @@
#include <wx/event.h>
#include <wx/timer.h>
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();