Fixed GameCube rumble
authorSam Lantinga <slouken@libsdl.org>
Thu, 19 Dec 2019 18:00:08 -0800
changeset 13363eb09f372f3ac
parent 13362 2d73c614e067
child 13364 e0633ed9c498
Fixed GameCube rumble
src/joystick/hidapi/SDL_hidapi_gamecube.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c	Thu Dec 19 16:14:22 2019 -0800
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c	Thu Dec 19 18:00:08 2019 -0800
     1.3 @@ -147,7 +147,6 @@
     1.4      SDL_Joystick *joystick;
     1.5      Uint8 packet[37];
     1.6      Uint8 *curSlot;
     1.7 -    Uint32 now;
     1.8      Uint8 i;
     1.9      int size;
    1.10  
    1.11 @@ -225,9 +224,9 @@
    1.12      }
    1.13  
    1.14      /* Write rumble packet */
    1.15 -    now = SDL_GetTicks();
    1.16      for (i = 0; i < 4; i += 1) {
    1.17 -        if (ctx->rumbleExpiration[i] > 0) {
    1.18 +        if (ctx->rumbleExpiration[i] || (ctx->rumble[1 + i] && !ctx->rumbleAllowed[i])) {
    1.19 +            Uint32 now = SDL_GetTicks();
    1.20              if (SDL_TICKS_PASSED(now, ctx->rumbleExpiration[i]) || !ctx->rumbleAllowed[i]) {
    1.21                  ctx->rumble[1 + i] = 0;
    1.22                  ctx->rumbleExpiration[i] = 0;
    1.23 @@ -279,8 +278,8 @@
    1.24                  ctx->rumble[i + 1] = val;
    1.25                  ctx->rumbleUpdate = SDL_TRUE;
    1.26              }
    1.27 -            if (val && duration_ms < SDL_HAPTIC_INFINITY) {
    1.28 -                ctx->rumbleExpiration[i] = SDL_GetTicks() + duration_ms;
    1.29 +            if (val && duration_ms) {
    1.30 +                ctx->rumbleExpiration[i] = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
    1.31              } else {
    1.32                  ctx->rumbleExpiration[i] = 0;
    1.33              }