Fully-initialise the JOYSTICK_STATUS struct

This matches the vanilla behaviour.
This commit is contained in:
Clownacy 2020-01-04 19:41:04 +00:00
parent b00e65b90b
commit 0218402222

View file

@ -60,11 +60,14 @@ BOOL GetJoystickStatus(JOYSTICK_STATUS *status)
if (joystick == NULL)
return FALSE;
// The original Input.cpp assumed there were 32 buttons (because of DirectInput's 'DIJOYSTATE' struct)
int numButtons = SDL_JoystickNumButtons(joystick);
if (numButtons > 32)
numButtons = 32;
for (int i = 0; i < numButtons; ++i)
// Read whatever buttons actually exist
int i;
for (i = 0; i < numButtons; ++i)
{
if (SDL_JoystickGetButton(joystick, i) != 0)
status->bButton[i] = TRUE;
@ -72,6 +75,10 @@ BOOL GetJoystickStatus(JOYSTICK_STATUS *status)
status->bButton[i] = FALSE;
}
// Blank the buttons that do not
for (; i < 32; ++i)
status->bButton[i] = FALSE;
status->bDown = FALSE;
status->bRight = FALSE;
status->bUp = FALSE;