diff src/haptic/SDL_haptic.c @ 2560:2274406ba792 gsoc2008_force_feedback

Made ValidHaptic cleaner.
author Edgar Simo <bobbens@gmail.com>
date Thu, 31 Jul 2008 09:02:43 +0000
parents 2d88b82ce781
children 3696b9ce8a37
line wrap: on
line diff
--- a/src/haptic/SDL_haptic.c	Wed Jul 30 18:29:55 2008 +0000
+++ b/src/haptic/SDL_haptic.c	Thu Jul 31 09:02:43 2008 +0000
@@ -61,16 +61,19 @@
  * Checks to see if the haptic device is valid
  */
 static int
-ValidHaptic(SDL_Haptic ** haptic)
+ValidHaptic(SDL_Haptic * haptic)
 {
+   int i;
    int valid;
+
+   valid = 0;
+   for (i=0; i<SDL_numhaptics; i++) {
+      if (SDL_haptics[i] == haptic) {
+         valid = 1;
+         break;
+      }
+   }
    
-   if (*haptic == NULL) {
-      SDL_SetError("Haptic: Device hasn't been opened yet");
-      valid = 0;
-   } else {
-      valid = 1;
-   }
    return valid;
 }
 
@@ -178,7 +181,7 @@
 int
 SDL_HapticIndex(SDL_Haptic * haptic)
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -299,7 +302,7 @@
    int i;
 
    /* Must be valid */
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return;
    }
 
@@ -349,7 +352,7 @@
 int
 SDL_HapticNumEffects(SDL_Haptic * haptic)
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -363,7 +366,7 @@
 int
 SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -377,7 +380,7 @@
 unsigned int
 SDL_HapticQuery(SDL_Haptic * haptic)
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -391,7 +394,7 @@
 int
 SDL_HapticNumAxes(SDL_Haptic * haptic)
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -404,7 +407,7 @@
 int
 SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -422,7 +425,7 @@
    int i;
 
    /* Check for device validity. */
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -469,7 +472,7 @@
 int
 SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data)
 {
-   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
+   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
       return -1;
    }
 
@@ -495,7 +498,7 @@
 int
 SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
 {
-   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
+   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
       return -1;
    }
 
@@ -513,7 +516,7 @@
 int
 SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
 {
-   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
+   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
       return -1;
    }
 
@@ -531,7 +534,7 @@
 void
 SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
 {
-   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
+   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
       return;
    }
 
@@ -549,7 +552,7 @@
 int
 SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect)
 {
-   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
+   if (!ValidHaptic(haptic) || !ValidEffect(haptic,effect)) {
       return -1;
    }
 
@@ -570,7 +573,7 @@
    const char *env;
    int real_gain, max_gain;
 
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }
 
@@ -613,7 +616,7 @@
 int
 SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter )
 {
-   if (!ValidHaptic(&haptic)) {
+   if (!ValidHaptic(haptic)) {
       return -1;
    }