Start rumbling once a raw input controller has been correlated

Fixes https://github.com/libsdl-org/SDL/issues/5351
This commit is contained in:
Sam Lantinga 2022-03-17 18:25:50 -07:00
parent 3167ba342d
commit 1868c5b521
2 changed files with 27 additions and 18 deletions

View file

@ -886,7 +886,7 @@ SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 h
result = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble); result = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble);
} }
/* Save the rumble value regardless of success, so we don't spam the driver */ if (result == 0) {
joystick->low_frequency_rumble = low_frequency_rumble; joystick->low_frequency_rumble = low_frequency_rumble;
joystick->high_frequency_rumble = high_frequency_rumble; joystick->high_frequency_rumble = high_frequency_rumble;
@ -898,6 +898,7 @@ SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 h
} else { } else {
joystick->rumble_expiration = 0; joystick->rumble_expiration = 0;
} }
}
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return result; return result;
@ -920,7 +921,7 @@ SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
result = joystick->driver->RumbleTriggers(joystick, left_rumble, right_rumble); result = joystick->driver->RumbleTriggers(joystick, left_rumble, right_rumble);
} }
/* Save the rumble value regardless of success, so we don't spam the driver */ if (result == 0) {
joystick->left_trigger_rumble = left_rumble; joystick->left_trigger_rumble = left_rumble;
joystick->right_trigger_rumble = right_rumble; joystick->right_trigger_rumble = right_rumble;
@ -932,6 +933,7 @@ SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
} else { } else {
joystick->trigger_rumble_expiration = 0; joystick->trigger_rumble_expiration = 0;
} }
}
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return result; return result;

View file

@ -1295,6 +1295,13 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin
} }
#endif /* SDL_JOYSTICK_RAWINPUT_XINPUT */ #endif /* SDL_JOYSTICK_RAWINPUT_XINPUT */
if (!rumbled) {
#if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT)
return SDL_SetError("Controller isn't correlated yet, try hitting a button first");
#else
return SDL_Unsupported();
#endif
}
return 0; return 0;
} }