diff src/haptic/linux/SDL_syshaptic.c @ 2539:b4c41a7eea04 gsoc2008_force_feedback

Properly support INFINITY length haptic effects on linux.
author Edgar Simo <bobbens@gmail.com>
date Sun, 20 Jul 2008 16:21:15 +0000
parents 22ce87690b41
children fe346eddd3fb
line wrap: on
line diff
--- a/src/haptic/linux/SDL_syshaptic.c	Sun Jul 20 14:12:52 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Sun Jul 20 16:21:15 2008 +0000
@@ -515,7 +515,8 @@
          if (dest->direction < 0) return -1;
 
          /* Replay */
-         dest->replay.length = CLAMP(constant->length);
+         dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
+               0 : CLAMP(constant->length);
          dest->replay.delay = CLAMP(constant->delay);
 
          /* Trigger */
@@ -546,7 +547,8 @@
          if (dest->direction < 0) return -1;
          
          /* Replay */
-         dest->replay.length = CLAMP(periodic->length);
+         dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ? 
+               0 : CLAMP(periodic->length);
          dest->replay.delay = CLAMP(periodic->delay);
          
          /* Trigger */
@@ -597,7 +599,8 @@
          dest->direction = 0; /* Handled by the condition-specifics. */
 
          /* Replay */
-         dest->replay.length = CLAMP(condition->length);
+         dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 
+               0 : CLAMP(condition->length);
          dest->replay.delay = CLAMP(condition->delay);
 
          /* Trigger */
@@ -631,7 +634,8 @@
          if (dest->direction < 0) return -1;
 
          /* Replay */
-         dest->replay.length = CLAMP(ramp->length);
+         dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ? 
+               0 : CLAMP(ramp->length);
          dest->replay.delay = CLAMP(ramp->delay);
 
          /* Trigger */
@@ -741,6 +745,7 @@
    /* Prepare to run the effect */
    run.type = EV_FF;
    run.code = effect->hweffect->effect.id;
+   /* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
    run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
 
    if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {