Made ValidHaptic cleaner. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Thu, 31 Jul 2008 09:02:43 +0000
branchgsoc2008_force_feedback
changeset 25602274406ba792
parent 2559 42b682e85546
child 2561 3696b9ce8a37
Made ValidHaptic cleaner.
src/haptic/SDL_haptic.c
     1.1 --- a/src/haptic/SDL_haptic.c	Wed Jul 30 18:29:55 2008 +0000
     1.2 +++ b/src/haptic/SDL_haptic.c	Thu Jul 31 09:02:43 2008 +0000
     1.3 @@ -61,16 +61,19 @@
     1.4   * Checks to see if the haptic device is valid
     1.5   */
     1.6  static int
     1.7 -ValidHaptic(SDL_Haptic ** haptic)
     1.8 +ValidHaptic(SDL_Haptic * haptic)
     1.9  {
    1.10 +   int i;
    1.11     int valid;
    1.12 +
    1.13 +   valid = 0;
    1.14 +   for (i=0; i<SDL_numhaptics; i++) {
    1.15 +      if (SDL_haptics[i] == haptic) {
    1.16 +         valid = 1;
    1.17 +         break;
    1.18 +      }
    1.19 +   }
    1.20     
    1.21 -   if (*haptic == NULL) {
    1.22 -      SDL_SetError("Haptic: Device hasn't been opened yet");
    1.23 -      valid = 0;
    1.24 -   } else {
    1.25 -      valid = 1;
    1.26 -   }
    1.27     return valid;
    1.28  }
    1.29  
    1.30 @@ -178,7 +181,7 @@
    1.31  int
    1.32  SDL_HapticIndex(SDL_Haptic * haptic)
    1.33  {
    1.34 -   if (!ValidHaptic(&haptic)) {
    1.35 +   if (!ValidHaptic(haptic)) {
    1.36        return -1;
    1.37     }
    1.38  
    1.39 @@ -299,7 +302,7 @@
    1.40     int i;
    1.41  
    1.42     /* Must be valid */
    1.43 -   if (!ValidHaptic(&haptic)) {
    1.44 +   if (!ValidHaptic(haptic)) {
    1.45        return;
    1.46     }
    1.47  
    1.48 @@ -349,7 +352,7 @@
    1.49  int
    1.50  SDL_HapticNumEffects(SDL_Haptic * haptic)
    1.51  {
    1.52 -   if (!ValidHaptic(&haptic)) {
    1.53 +   if (!ValidHaptic(haptic)) {
    1.54        return -1;
    1.55     }
    1.56  
    1.57 @@ -363,7 +366,7 @@
    1.58  int
    1.59  SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
    1.60  {
    1.61 -   if (!ValidHaptic(&haptic)) {
    1.62 +   if (!ValidHaptic(haptic)) {
    1.63        return -1;
    1.64     }
    1.65  
    1.66 @@ -377,7 +380,7 @@
    1.67  unsigned int
    1.68  SDL_HapticQuery(SDL_Haptic * haptic)
    1.69  {
    1.70 -   if (!ValidHaptic(&haptic)) {
    1.71 +   if (!ValidHaptic(haptic)) {
    1.72        return -1;
    1.73     }
    1.74  
    1.75 @@ -391,7 +394,7 @@
    1.76  int
    1.77  SDL_HapticNumAxes(SDL_Haptic * haptic)
    1.78  {
    1.79 -   if (!ValidHaptic(&haptic)) {
    1.80 +   if (!ValidHaptic(haptic)) {
    1.81        return -1;
    1.82     }
    1.83  
    1.84 @@ -404,7 +407,7 @@
    1.85  int
    1.86  SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
    1.87  {
    1.88 -   if (!ValidHaptic(&haptic)) {
    1.89 +   if (!ValidHaptic(haptic)) {
    1.90        return -1;
    1.91     }
    1.92  
    1.93 @@ -422,7 +425,7 @@
    1.94     int i;
    1.95  
    1.96     /* Check for device validity. */
    1.97 -   if (!ValidHaptic(&haptic)) {
    1.98 +   if (!ValidHaptic(haptic)) {
    1.99        return -1;
   1.100     }
   1.101  
   1.102 @@ -469,7 +472,7 @@
   1.103  int
   1.104  SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
   1.105  {
   1.106 -   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
   1.107 +   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
   1.108        return -1;
   1.109     }
   1.110  
   1.111 @@ -495,7 +498,7 @@
   1.112  int
   1.113  SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
   1.114  {
   1.115 -   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
   1.116 +   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
   1.117        return -1;
   1.118     }
   1.119  
   1.120 @@ -513,7 +516,7 @@
   1.121  int
   1.122  SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
   1.123  {
   1.124 -   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
   1.125 +   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
   1.126        return -1;
   1.127     }
   1.128  
   1.129 @@ -531,7 +534,7 @@
   1.130  void
   1.131  SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
   1.132  {
   1.133 -   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
   1.134 +   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
   1.135        return;
   1.136     }
   1.137  
   1.138 @@ -549,7 +552,7 @@
   1.139  int
   1.140  SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
   1.141  {
   1.142 -   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
   1.143 +   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
   1.144        return -1;
   1.145     }
   1.146  
   1.147 @@ -570,7 +573,7 @@
   1.148     const char *env;
   1.149     int real_gain, max_gain;
   1.150  
   1.151 -   if (!ValidHaptic(&haptic)) {
   1.152 +   if (!ValidHaptic(haptic)) {
   1.153        return -1;
   1.154     }
   1.155  
   1.156 @@ -613,7 +616,7 @@
   1.157  int
   1.158  SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter )
   1.159  {
   1.160 -   if (!ValidHaptic(&haptic)) {
   1.161 +   if (!ValidHaptic(haptic)) {
   1.162        return -1;
   1.163     }
   1.164