joysticks: hack to better support 360 triggers
Map initial state of axis to 0. This is sufficient for the time being for the 360 triggers to work better. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
352eb149ae
commit
2fcad3f813
|
@ -9,6 +9,7 @@ struct wxSDLJoyState {
|
||||||
SDL_Joystick* dev;
|
SDL_Joystick* dev;
|
||||||
int nax, nhat, nbut;
|
int nax, nhat, nbut;
|
||||||
short* curval;
|
short* curval;
|
||||||
|
short* initial_val;
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
~wxSDLJoyState()
|
~wxSDLJoyState()
|
||||||
{
|
{
|
||||||
|
@ -16,12 +17,15 @@ struct wxSDLJoyState {
|
||||||
SDL_JoystickClose(dev);
|
SDL_JoystickClose(dev);
|
||||||
if (curval)
|
if (curval)
|
||||||
delete[] curval;
|
delete[] curval;
|
||||||
|
if (initial_val)
|
||||||
|
delete[] initial_val;
|
||||||
}
|
}
|
||||||
wxSDLJoyState()
|
wxSDLJoyState()
|
||||||
{
|
{
|
||||||
dev = NULL;
|
dev = NULL;
|
||||||
nax = nhat = nbut = 0;
|
nax = nhat = nbut = 0;
|
||||||
curval = NULL;
|
curval = NULL;
|
||||||
|
initial_val = NULL;
|
||||||
is_valid = true;
|
is_valid = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -70,17 +74,19 @@ wxSDLJoy::wxSDLJoy(bool analog)
|
||||||
nctrl += joystate[i].nhat = hats < 0 ? 0 : hats;
|
nctrl += joystate[i].nhat = hats < 0 ? 0 : hats;
|
||||||
nctrl += joystate[i].nbut = buttons < 0 ? 0 : buttons;
|
nctrl += joystate[i].nbut = buttons < 0 ? 0 : buttons;
|
||||||
|
|
||||||
joystate[i].curval = new short[nctrl]{0};
|
joystate[i].curval = new short[nctrl]{};
|
||||||
|
|
||||||
// clear controls
|
// set initial values array
|
||||||
memset(joystate[i].curval, 0, sizeof(short) * nctrl);
|
// see below for 360 trigger handling
|
||||||
|
|
||||||
// initialize axis previous value to initial state
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 6)
|
#if SDL_VERSION_ATLEAST(2, 0, 6)
|
||||||
|
joystate[i].initial_val = new short[nctrl]{};
|
||||||
|
|
||||||
for (int j = 0; j < joystate[i].nax; j++) {
|
for (int j = 0; j < joystate[i].nax; j++) {
|
||||||
int16_t initial_state = 0;
|
int16_t initial_state = 0;
|
||||||
SDL_JoystickGetAxisInitialState(dev, j, &initial_state);
|
SDL_JoystickGetAxisInitialState(dev, j, &initial_state);
|
||||||
joystate[i].curval[j] = initial_state;
|
joystate[i].initial_val[j] = initial_state;
|
||||||
|
|
||||||
|
// curval is 0 which is what initial state maps to ATM
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -181,6 +187,13 @@ void wxSDLJoy::Notify()
|
||||||
val = 0;
|
val = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is for the 360 and similar triggers which return a
|
||||||
|
// value on initial state of the trigger axis. This hack may be
|
||||||
|
// insufficient, we may need to expand the joy event API to
|
||||||
|
// support initial values.
|
||||||
|
if (joystate[i].initial_val && val == joystate[i].initial_val[j])
|
||||||
|
val = 0;
|
||||||
|
|
||||||
if (handler && val != joystate[i].curval[j]) {
|
if (handler && val != joystate[i].curval[j]) {
|
||||||
wxSDLJoyEvent ev(wxEVT_SDLJOY, GetId());
|
wxSDLJoyEvent ev(wxEVT_SDLJOY, GetId());
|
||||||
ev.joy = i;
|
ev.joy = i;
|
||||||
|
|
Loading…
Reference in New Issue