Haptic: Add some missing haptic types to test, and fix wrong array-sizes.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 16 Aug 2014 16:50:10 -0400
changeset 90720c1a46c018aa
parent 9071 8e04e17c7af3
child 9073 98d13a381299
Haptic: Add some missing haptic types to test, and fix wrong array-sizes.

Thanks, Elias!

Fixes Bugzilla #2686.
(along with the last several commits.)
test/testhaptic.c
     1.1 --- a/test/testhaptic.c	Sat Aug 16 16:49:00 2014 -0400
     1.2 +++ b/test/testhaptic.c	Sat Aug 16 16:50:10 2014 -0400
     1.3 @@ -45,8 +45,8 @@
     1.4      int i;
     1.5      char *name;
     1.6      int index;
     1.7 -    SDL_HapticEffect efx[5];
     1.8 -    int id[5];
     1.9 +    SDL_HapticEffect efx[9];
    1.10 +    int id[9];
    1.11      int nefx;
    1.12      unsigned int supported;
    1.13  
    1.14 @@ -149,6 +149,7 @@
    1.15          }
    1.16          nefx++;
    1.17      }
    1.18 +    
    1.19      /* Now the classical constant effect. */
    1.20      if (supported & SDL_HAPTIC_CONSTANT) {
    1.21          SDL_Log("   effect %d: Constant Force\n", nefx);
    1.22 @@ -166,6 +167,7 @@
    1.23          }
    1.24          nefx++;
    1.25      }
    1.26 +    
    1.27      /* The cute spring effect. */
    1.28      if (supported & SDL_HAPTIC_SPRING) {
    1.29          SDL_Log("   effect %d: Condition Spring\n", nefx);
    1.30 @@ -185,6 +187,24 @@
    1.31          }
    1.32          nefx++;
    1.33      }
    1.34 +    /* The interesting damper effect. */
    1.35 +    if (supported & SDL_HAPTIC_DAMPER) {
    1.36 +        SDL_Log("   effect %d: Condition Damper\n", nefx);
    1.37 +        efx[nefx].type = SDL_HAPTIC_DAMPER;
    1.38 +        efx[nefx].condition.length = 5000;
    1.39 +        for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
    1.40 +            efx[nefx].condition.right_sat[i] = 0xFFFF;
    1.41 +            efx[nefx].condition.left_sat[i] = 0xFFFF;
    1.42 +            efx[nefx].condition.right_coeff[i] = 0x2000;
    1.43 +            efx[nefx].condition.left_coeff[i] = 0x2000;
    1.44 +        }
    1.45 +        id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
    1.46 +        if (id[nefx] < 0) {
    1.47 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
    1.48 +            abort_execution();
    1.49 +        }
    1.50 +        nefx++;
    1.51 +    }
    1.52      /* The pretty awesome inertia effect. */
    1.53      if (supported & SDL_HAPTIC_INERTIA) {
    1.54          SDL_Log("   effect %d: Condition Inertia\n", nefx);
    1.55 @@ -204,6 +224,44 @@
    1.56          }
    1.57          nefx++;
    1.58      }
    1.59 +    /* The hot friction effect. */
    1.60 +    if (supported & SDL_HAPTIC_FRICTION) {
    1.61 +        SDL_Log("   effect %d: Condition Friction\n", nefx);
    1.62 +        efx[nefx].type = SDL_HAPTIC_FRICTION;
    1.63 +        efx[nefx].condition.length = 5000;
    1.64 +        for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
    1.65 +            efx[nefx].condition.right_sat[i] = 0xFFFF;
    1.66 +            efx[nefx].condition.left_sat[i] = 0xFFFF;
    1.67 +            efx[nefx].condition.right_coeff[i] = 0x2000;
    1.68 +            efx[nefx].condition.left_coeff[i] = 0x2000;
    1.69 +        }
    1.70 +        id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
    1.71 +        if (id[nefx] < 0) {
    1.72 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
    1.73 +            abort_execution();
    1.74 +        }
    1.75 +        nefx++;
    1.76 +    }
    1.77 +    
    1.78 +    /* Now we'll try a ramp effect */
    1.79 +    if (supported & SDL_HAPTIC_RAMP) {
    1.80 +        SDL_Log("   effect %d: Ramp\n", nefx);
    1.81 +        efx[nefx].type = SDL_HAPTIC_RAMP;
    1.82 +        efx[nefx].ramp.direction.type = SDL_HAPTIC_CARTESIAN;
    1.83 +        efx[nefx].ramp.direction.dir[0] = 1;     /* Force comes from                 */
    1.84 +        efx[nefx].ramp.direction.dir[1] = -1;    /*                  the north-east. */
    1.85 +        efx[nefx].ramp.length = 5000;
    1.86 +        efx[nefx].ramp.start = 0x4000;
    1.87 +        efx[nefx].ramp.end = -0x4000;
    1.88 +        efx[nefx].ramp.attack_length = 1000;
    1.89 +        efx[nefx].ramp.fade_length = 1000;
    1.90 +        id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
    1.91 +        if (id[nefx] < 0) {
    1.92 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
    1.93 +            abort_execution();
    1.94 +        }
    1.95 +        nefx++;
    1.96 +    }
    1.97  
    1.98      /* Finally we'll try a left/right effect. */
    1.99      if (supported & SDL_HAPTIC_LEFTRIGHT) {