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 7847038da46576e6
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
     1.1 --- a/src/haptic/windows/SDL_syshaptic.c	Sun Oct 20 15:49:52 2013 -0400
     1.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Sun Oct 20 15:55:47 2013 -0400
     1.3 @@ -1327,7 +1327,11 @@
     1.4          XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
     1.5          SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT);  /* should catch this at higher level */
     1.6          SDL_LockMutex(haptic->hwdata->mutex);
     1.7 -        haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
     1.8 +        if(effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) {
     1.9 +            haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY;
    1.10 +        } else {
    1.11 +            haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
    1.12 +        }
    1.13          SDL_UnlockMutex(haptic->hwdata->mutex);
    1.14          return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
    1.15      }
    1.16 @@ -1560,10 +1564,13 @@
    1.17          SDL_Delay(50);
    1.18          SDL_LockMutex(hwdata->mutex);
    1.19          /* If we're currently running and need to stop... */
    1.20 -        if ((hwdata->stopTicks) && (hwdata->stopTicks < SDL_GetTicks())) {
    1.21 -            XINPUT_VIBRATION vibration = { 0, 0 };
    1.22 -            hwdata->stopTicks = 0;
    1.23 -            XINPUTSETSTATE(hwdata->userid, &vibration);
    1.24 +        const Uint32 stopTicks = hwdata->stopTicks;
    1.25 +        if (stopTicks) {
    1.26 +            if ((stopTicks != SDL_HAPTIC_INFINITY) && (stopTicks < SDL_GetTicks())) {
    1.27 +                XINPUT_VIBRATION vibration = { 0, 0 };
    1.28 +                hwdata->stopTicks = 0;
    1.29 +                XINPUTSETSTATE(hwdata->userid, &vibration);
    1.30 +            }
    1.31          }
    1.32          SDL_UnlockMutex(hwdata->mutex);
    1.33      }