# HG changeset patch # User Ethan Lee # Date 1525485519 14400 # Fri May 04 21:58:39 2018 -0400 # Node ID 0316b40b604eace7a844b6e1b67ea0c119d2865b # Parent bc2aba33ae1f87a0ba8256bec8ee3829010c7893 Fix Linux haptic scaling, add 2.1 FIXME diff -r bc2aba33ae1f -r 0316b40b604e include/SDL_haptic.h --- a/include/SDL_haptic.h Mon Apr 23 22:29:14 2018 -0700 +++ b/include/SDL_haptic.h Fri May 04 21:58:39 2018 -0400 @@ -117,6 +117,17 @@ extern "C" { #endif /* __cplusplus */ +/* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF). + * + * At the moment the magnitude variables are mixed between signed/unsigned, and + * it is also not made clear that ALL of those variables expect a max of 0x7FFF. + * + * Some platforms may have higher precision than that (Linux FF, Windows XInput) + * so we should fix the inconsistency in favor of higher possible precision, + * adjusting for platforms that use different scales. + * -flibit + */ + /** * \typedef SDL_Haptic * diff -r bc2aba33ae1f -r 0316b40b604e src/haptic/linux/SDL_syshaptic.c --- a/src/haptic/linux/SDL_syshaptic.c Mon Apr 23 22:29:14 2018 -0700 +++ b/src/haptic/linux/SDL_syshaptic.c Fri May 04 21:58:39 2018 -0400 @@ -798,7 +798,8 @@ else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN) dest->u.periodic.waveform = FF_SAW_DOWN; dest->u.periodic.period = CLAMP(periodic->period); - dest->u.periodic.magnitude = periodic->magnitude; + /* Linux expects 0-65535, so multiply by 2 */ + dest->u.periodic.magnitude = CLAMP(periodic->magnitude) * 2; dest->u.periodic.offset = periodic->offset; /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */ dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000; @@ -905,9 +906,9 @@ dest->trigger.button = 0; dest->trigger.interval = 0; - /* Rumble */ - dest->u.rumble.strong_magnitude = leftright->large_magnitude; - dest->u.rumble.weak_magnitude = leftright->small_magnitude; + /* Rumble (Linux expects 0-65535, so multiply by 2) */ + dest->u.rumble.strong_magnitude = CLAMP(leftright->large_magnitude) * 2; + dest->u.rumble.weak_magnitude = CLAMP(leftright->small_magnitude) * 2; break;