Allow XInput haptics to run for SDL_HAPTIC_INFINITY time (thanks, Mitchell!).
authorRyan C. Gordon <icculus@icculus.org>
Sun, 20 Oct 2013 15:55:47 -0400
changeset 7847 038da46576e6
parent 7846 70f1d63482d0
child 7848 4f77ff668405
Allow XInput haptics to run for SDL_HAPTIC_INFINITY time (thanks, Mitchell!). Partially fixes Bugzilla #2126.
src/haptic/windows/SDL_syshaptic.c
--- a/src/haptic/windows/SDL_syshaptic.c	Sun Oct 20 15:49:52 2013 -0400
+++ b/src/haptic/windows/SDL_syshaptic.c	Sun Oct 20 15:55:47 2013 -0400
@@ -1327,7 +1327,11 @@
         XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
         SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT);  /* should catch this at higher level */
         SDL_LockMutex(haptic->hwdata->mutex);
-        haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
+        if(effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) {
+            haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY;
+        } else {
+            haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
+        }
         SDL_UnlockMutex(haptic->hwdata->mutex);
         return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
     }
@@ -1560,10 +1564,13 @@
         SDL_Delay(50);
         SDL_LockMutex(hwdata->mutex);
         /* If we're currently running and need to stop... */
-        if ((hwdata->stopTicks) && (hwdata->stopTicks < SDL_GetTicks())) {
-            XINPUT_VIBRATION vibration = { 0, 0 };
-            hwdata->stopTicks = 0;
-            XINPUTSETSTATE(hwdata->userid, &vibration);
+        const Uint32 stopTicks = hwdata->stopTicks;
+        if (stopTicks) {
+            if ((stopTicks != SDL_HAPTIC_INFINITY) && (stopTicks < SDL_GetTicks())) {
+                XINPUT_VIBRATION vibration = { 0, 0 };
+                hwdata->stopTicks = 0;
+                XINPUTSETSTATE(hwdata->userid, &vibration);
+            }
         }
         SDL_UnlockMutex(hwdata->mutex);
     }