Poll for the initial controller state when using DirectInput

This fixes getting a deflected axis as the first buffered input reading on a generic USB controller (G-Shark GS-GP702)
main
Sam Lantinga 2024-03-20 10:45:11 -07:00
parent 4a7e3beeb9
commit 70b0d33106
2 changed files with 10 additions and 1 deletions

View File

@ -849,6 +849,7 @@ int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic
} else if (FAILED(result)) { } else if (FAILED(result)) {
return SetDIerror("IDirectInputDevice8::SetProperty", result); return SetDIerror("IDirectInputDevice8::SetProperty", result);
} }
joystick->hwdata->first_update = SDL_TRUE;
/* Poll and wait for initial device state to be populated */ /* Poll and wait for initial device state to be populated */
result = IDirectInputDevice8_Poll(joystick->hwdata->InputDevice); result = IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
@ -1115,7 +1116,14 @@ void SDL_DINPUT_JoystickUpdate(SDL_Joystick *joystick)
IDirectInputDevice8_Poll(joystick->hwdata->InputDevice); IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
} }
if (joystick->hwdata->buffered) { if (joystick->hwdata->first_update) {
/* Poll to get the initial state of the joystick */
UpdateDINPUTJoystickState_Polled(joystick);
joystick->hwdata->first_update = SDL_FALSE;
return;
}
if (joystick->hwdata->buffered ) {
UpdateDINPUTJoystickState_Buffered(joystick); UpdateDINPUTJoystickState_Buffered(joystick);
} else { } else {
UpdateDINPUTJoystickState_Polled(joystick); UpdateDINPUTJoystickState_Polled(joystick);

View File

@ -76,6 +76,7 @@ struct joystick_hwdata
LPDIRECTINPUTDEVICE8 InputDevice; LPDIRECTINPUTDEVICE8 InputDevice;
DIDEVCAPS Capabilities; DIDEVCAPS Capabilities;
SDL_bool buffered; SDL_bool buffered;
SDL_bool first_update;
input_t Inputs[MAX_INPUTS]; input_t Inputs[MAX_INPUTS];
int NumInputs; int NumInputs;
int NumSliders; int NumSliders;