Updated Haptic API for SDL 3.0 conventions

Also removed the XInput haptic support since using the haptic API for rumble is no longer supported.
This commit is contained in:
Sam Lantinga
2024-01-17 15:22:35 -08:00
parent 8ca9134115
commit f224af5ac5
35 changed files with 943 additions and 1320 deletions

View File

@@ -81,7 +81,10 @@ int main(int argc, char *argv[])
SDL_free(SDL_GetJoysticks(&num_joysticks));
SDL_Log("There are %d joysticks at startup\n", num_joysticks);
if (enable_haptic) {
SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
int num_haptics;
SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics);
SDL_free(haptics);
SDL_Log("There are %d haptic devices at startup\n", num_haptics);
}
while (keepGoing) {
@@ -99,13 +102,13 @@ int main(int argc, char *argv[])
instance = event.jdevice.which;
SDL_Log("Joy Added : %" SDL_PRIu32 " : %s\n", event.jdevice.which, SDL_GetJoystickName(joystick));
if (enable_haptic) {
if (SDL_JoystickIsHaptic(joystick)) {
haptic = SDL_HapticOpenFromJoystick(joystick);
if (SDL_IsJoystickHaptic(joystick)) {
haptic = SDL_OpenHapticFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_HapticRumbleInit(haptic) != 0) {
if (SDL_InitHapticRumble(haptic) != 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_HapticClose(haptic);
SDL_CloseHaptic(haptic);
haptic = NULL;
}
} else {
@@ -122,7 +125,7 @@ int main(int argc, char *argv[])
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
instance = 0;
if (enable_haptic && haptic) {
SDL_HapticClose(haptic);
SDL_CloseHaptic(haptic);
haptic = NULL;
}
SDL_CloseJoystick(joystick);
@@ -136,13 +139,13 @@ int main(int argc, char *argv[])
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
*/
if (enable_haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
SDL_PlayHapticRumble(haptic, 0.25, 250);
}
break;
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
SDL_Log("Button Press: %d\n", event.jbutton.button);
if (enable_haptic && haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
SDL_PlayHapticRumble(haptic, 0.25, 250);
}
if (event.jbutton.button == 0) {
SDL_Log("Exiting due to button press of button 0\n");