Fix Linux haptic scaling, add 2.1 FIXME
authorEthan Lee <flibitijibibo@flibitijibibo.com>
Fri, 04 May 2018 21:58:39 -0400
changeset 1227144a639b5f1af
parent 12270 52dddda6fba7
child 12272 c68b05ca0761
Fix Linux haptic scaling, add 2.1 FIXME
include/SDL_haptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Mon Aug 13 12:52:52 2018 -0400
     1.2 +++ b/include/SDL_haptic.h	Fri May 04 21:58:39 2018 -0400
     1.3 @@ -117,6 +117,17 @@
     1.4  extern "C" {
     1.5  #endif /* __cplusplus */
     1.6  
     1.7 +/* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF).
     1.8 + *
     1.9 + * At the moment the magnitude variables are mixed between signed/unsigned, and
    1.10 + * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
    1.11 + *
    1.12 + * Some platforms may have higher precision than that (Linux FF, Windows XInput)
    1.13 + * so we should fix the inconsistency in favor of higher possible precision,
    1.14 + * adjusting for platforms that use different scales.
    1.15 + * -flibit
    1.16 + */
    1.17 +
    1.18  /**
    1.19   *  \typedef SDL_Haptic
    1.20   *
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Mon Aug 13 12:52:52 2018 -0400
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Fri May 04 21:58:39 2018 -0400
     2.3 @@ -801,7 +801,8 @@
     2.4          else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
     2.5              dest->u.periodic.waveform = FF_SAW_DOWN;
     2.6          dest->u.periodic.period = CLAMP(periodic->period);
     2.7 -        dest->u.periodic.magnitude = periodic->magnitude;
     2.8 +        /* Linux expects 0-65535, so multiply by 2 */
     2.9 +        dest->u.periodic.magnitude = CLAMP(periodic->magnitude) * 2;
    2.10          dest->u.periodic.offset = periodic->offset;
    2.11          /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
    2.12          dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
    2.13 @@ -908,9 +909,9 @@
    2.14          dest->trigger.button = 0;
    2.15          dest->trigger.interval = 0;
    2.16  
    2.17 -        /* Rumble */
    2.18 -        dest->u.rumble.strong_magnitude = leftright->large_magnitude;
    2.19 -        dest->u.rumble.weak_magnitude = leftright->small_magnitude;
    2.20 +        /* Rumble (Linux expects 0-65535, so multiply by 2) */
    2.21 +        dest->u.rumble.strong_magnitude = CLAMP(leftright->large_magnitude) * 2;
    2.22 +        dest->u.rumble.weak_magnitude = CLAMP(leftright->small_magnitude) * 2;
    2.23  
    2.24          break;
    2.25