diff --git a/CHANGES b/CHANGES index 890b57f2b..657a4cfce 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,7 @@ Other fixes: - Qt: Fix corrupted savestate and fatal error text - Qt: Fix sprite compositing when sprite tiles go out of bounds (fixes mgba.io/i/2348) Misc: + - SDL: Use SDL_JoystickRumble where available - Wii: Add adjustable gyroscope settings (closes mgba.io/i/2245) 0.9.2: (2021-07-10) diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index c7291ff32..682620fc4 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -47,9 +47,11 @@ bool mSDLInitEvents(struct mSDLEvents* context) { #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); +#if !SDL_VERSION_ATLEAST(2, 0, 9) if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) { mLOG(SDL_EVENTS, ERROR, "SDL haptic initialization failed: %s", SDL_GetError()); } +#endif if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { mLOG(SDL_EVENTS, ERROR, "SDL video initialization failed: %s", SDL_GetError()); } @@ -73,7 +75,9 @@ bool mSDLInitEvents(struct mSDLEvents* context) { joystick->index = SDL_JoystickListSize(&context->joysticks) - 1; #if SDL_VERSION_ATLEAST(2, 0, 0) joystick->id = SDL_JoystickInstanceID(joystick->joystick); +#if !SDL_VERSION_ATLEAST(2, 0, 9) joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick); +#endif #else joystick->id = SDL_JoystickIndex(joystick->joystick); #endif @@ -100,7 +104,7 @@ void mSDLDeinitEvents(struct mSDLEvents* context) { size_t i; for (i = 0; i < SDL_JoystickListSize(&context->joysticks); ++i) { struct SDL_JoystickCombo* joystick = SDL_JoystickListGetPointer(&context->joysticks, i); -#if SDL_VERSION_ATLEAST(2, 0, 0) +#if SDL_VERSION_ATLEAST(2, 0, 0) && !SDL_VERSION_ATLEAST(2, 0, 9) SDL_HapticClose(joystick->haptic); #endif SDL_JoystickClose(joystick->joystick); @@ -223,7 +227,7 @@ bool mSDLAttachPlayer(struct mSDLEvents* events, struct mSDLPlayer* player) { if (index != SIZE_MAX) { player->joystick = SDL_JoystickListGetPointer(&events->joysticks, index); -#if SDL_VERSION_ATLEAST(2, 0, 0) +#if SDL_VERSION_ATLEAST(2, 0, 0) && !SDL_VERSION_ATLEAST(2, 0, 9) if (player->joystick->haptic) { SDL_HapticRumbleInit(player->joystick->haptic); } @@ -365,7 +369,7 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration* joystick->joystick = sdlJoystick; joystick->id = SDL_JoystickInstanceID(joystick->joystick); joystick->index = SDL_JoystickListSize(&events->joysticks) - 1; -#if SDL_VERSION_ATLEAST(2, 0, 0) +#if SDL_VERSION_ATLEAST(2, 0, 0) && !SDL_VERSION_ATLEAST(2, 0, 9) joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick); #endif for (i = 0; i < events->playersAttached && i < MAX_PLAYERS; ++i) { @@ -649,7 +653,11 @@ void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext, #if SDL_VERSION_ATLEAST(2, 0, 0) static void _mSDLSetRumble(struct mRumble* rumble, int enable) { struct mSDLRumble* sdlRumble = (struct mSDLRumble*) rumble; - if (!sdlRumble->p->joystick || !sdlRumble->p->joystick->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->joystick->haptic)) { + if (!sdlRumble->p->joystick +#if !SDL_VERSION_ATLEAST(2, 0, 9) + || !sdlRumble->p->joystick->haptic || !SDL_HapticRumbleSupported(sdlRumble->p->joystick->haptic) +#endif + ) { return; } int8_t originalLevel = sdlRumble->level; @@ -668,12 +676,16 @@ static void _mSDLSetRumble(struct mRumble* rumble, int enable) { return; } sdlRumble->activeLevel = activeLevel; +#if SDL_VERSION_ATLEAST(2, 0, 9) + SDL_JoystickRumble(sdlRumble->p->joystick->joystick, activeLevel * 0xFFFF, activeLevel * 0xFFFF, 500); +#else if (sdlRumble->activeLevel > 0.5 / RUMBLE_STEPS) { SDL_HapticRumbleStop(sdlRumble->p->joystick->haptic); SDL_HapticRumblePlay(sdlRumble->p->joystick->haptic, activeLevel, 500); } else { SDL_HapticRumbleStop(sdlRumble->p->joystick->haptic); } +#endif } #endif