Haptic: Don't interpret a direction of polar 35999 as "unsupported type".
authorRyan C. Gordon <icculus@icculus.org>
Sat, 16 Aug 2014 16:40:01 -0400
changeset 90672412ba127e23
parent 9066 c2af3ff967cc
child 9068 a57a1d70ae07
Haptic: Don't interpret a direction of polar 35999 as "unsupported type".

(or linux-direction 0xFFFF)

Thanks, Elias!

Partially fixes Bugzilla #2686.
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/src/haptic/linux/SDL_syshaptic.c	Fri Aug 15 23:39:14 2014 +0200
     1.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sat Aug 16 16:40:01 2014 -0400
     1.3 @@ -652,15 +652,15 @@
     1.4  
     1.5  
     1.6  /*
     1.7 - * Returns the ff_effect usable direction from a SDL_HapticDirection.
     1.8 + * Initializes the ff_effect usable direction from a SDL_HapticDirection.
     1.9   */
    1.10 -static Uint16
    1.11 -SDL_SYS_ToDirection(SDL_HapticDirection * dir)
    1.12 +static int
    1.13 +SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
    1.14  {
    1.15      Uint32 tmp;
    1.16      float f;                    /* Ideally we'd use fixed point math instead of floats... */
    1.17  
    1.18 -    switch (dir->type) {
    1.19 +    switch (src->type) {
    1.20      case SDL_HAPTIC_POLAR:
    1.21          /* Linux directions start from south.
    1.22                  (and range from 0 to 0xFFFF)
    1.23 @@ -671,10 +671,11 @@
    1.24                          180 deg -> 0x8000 (up)
    1.25                          270 deg -> 0xC000 (right)
    1.26                      */
    1.27 -        tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
    1.28 -        return (Uint16) tmp;
    1.29 +        tmp = (((18000 + src->dir[0]) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
    1.30 +        *dest = (Uint16) tmp;
    1.31 +        break;
    1.32  
    1.33 -       case SDL_HAPTIC_SPHERICAL:
    1.34 +    case SDL_HAPTIC_SPHERICAL:
    1.35              /*
    1.36                  We convert to polar, because that's the only supported direction on Linux.
    1.37                  The first value of a spherical direction is practically the same as a
    1.38 @@ -683,12 +684,13 @@
    1.39                  --> add 9000
    1.40                  --> finally add 18000 and convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
    1.41              */
    1.42 -            tmp = ((dir->dir[0]) + 9000) % 36000;    /* Convert to polars */
    1.43 +            tmp = ((src->dir[0]) + 9000) % 36000;    /* Convert to polars */
    1.44          tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
    1.45 -        return (Uint16) tmp;
    1.46 +        *dest = (Uint16) tmp;
    1.47 +        break;
    1.48  
    1.49      case SDL_HAPTIC_CARTESIAN:
    1.50 -        f = atan2(dir->dir[1], dir->dir[0]);
    1.51 +        f = atan2(src->dir[1], src->dir[0]);
    1.52                      /*
    1.53                        atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
    1.54                         - Y-axis-value is the second coordinate (from center to SOUTH)
    1.55 @@ -701,10 +703,11 @@
    1.56                      */
    1.57                  tmp = (((int) (f * 18000. / M_PI)) + 45000) % 36000;
    1.58          tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
    1.59 -        return (Uint16) tmp;
    1.60 +        *dest = (Uint16) tmp;
    1.61 +        break;
    1.62  
    1.63      default:
    1.64 -        return (Uint16) SDL_SetError("Haptic: Unsupported direction type.");
    1.65 +        return SDL_SetError("Haptic: Unsupported direction type.");
    1.66      }
    1.67  
    1.68      return 0;
    1.69 @@ -735,8 +738,7 @@
    1.70  
    1.71          /* Header */
    1.72          dest->type = FF_CONSTANT;
    1.73 -        dest->direction = SDL_SYS_ToDirection(&constant->direction);
    1.74 -        if (dest->direction == (Uint16) - 1)
    1.75 +        if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1)
    1.76              return -1;
    1.77  
    1.78          /* Replay */
    1.79 @@ -771,8 +773,7 @@
    1.80  
    1.81          /* Header */
    1.82          dest->type = FF_PERIODIC;
    1.83 -        dest->direction = SDL_SYS_ToDirection(&periodic->direction);
    1.84 -        if (dest->direction == (Uint16) - 1)
    1.85 +        if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1)
    1.86              return -1;
    1.87  
    1.88          /* Replay */
    1.89 @@ -868,8 +869,7 @@
    1.90  
    1.91          /* Header */
    1.92          dest->type = FF_RAMP;
    1.93 -        dest->direction = SDL_SYS_ToDirection(&ramp->direction);
    1.94 -        if (dest->direction == (Uint16) - 1)
    1.95 +        if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1)
    1.96              return -1;
    1.97  
    1.98          /* Replay */