Emscripten: Simplified implementation of joystick update function.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 15 Apr 2015 21:27:10 +0200
changeset 9560d1d80a69110b
parent 9559 3ca4f4ef7506
child 9561 d8ad01792399
Emscripten: Simplified implementation of joystick update function.

The function was implemented using four loops but only needed two.
src/joystick/emscripten/SDL_sysjoystick.c
     1.1 --- a/src/joystick/emscripten/SDL_sysjoystick.c	Wed Apr 15 21:25:15 2015 +0200
     1.2 +++ b/src/joystick/emscripten/SDL_sysjoystick.c	Wed Apr 15 21:27:10 2015 +0200
     1.3 @@ -350,6 +350,10 @@
     1.4                          buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
     1.5                          SDL_PrivateJoystickButton(item->joystick, i, buttonState);
     1.6                      }
     1.7 +
     1.8 +                    /* store values to compare them in the next update */
     1.9 +                    item->analogButton[i] = gamepadState.analogButton[i];
    1.10 +                    item->digitalButton[i] = gamepadState.digitalButton[i];
    1.11                  }
    1.12  
    1.13                  for(i = 0; i < item->naxes; i++) {
    1.14 @@ -358,17 +362,12 @@
    1.15                          SDL_PrivateJoystickAxis(item->joystick, i,
    1.16                                                    (Sint16) (32767.*gamepadState.axis[i]));
    1.17                      }
    1.18 +
    1.19 +                    /* store to compare in next update */
    1.20 +                    item->axis[i] = gamepadState.axis[i];
    1.21                  }
    1.22  
    1.23                  item->timestamp = gamepadState.timestamp;
    1.24 -                for( i = 0; i < item->naxes; i++) {
    1.25 -                    item->axis[i] = gamepadState.axis[i];
    1.26 -                }
    1.27 -
    1.28 -                for( i = 0; i < item->nbuttons; i++) {
    1.29 -                    item->analogButton[i] = gamepadState.analogButton[i];
    1.30 -                    item->digitalButton[i] = gamepadState.digitalButton[i];
    1.31 -                }
    1.32              }
    1.33          }
    1.34      }