Emscripten: Simplified implementation of joystick update function.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 15 Apr 2015 21:27:10 +0200
changeset 9560 d1d80a69110b
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
--- a/src/joystick/emscripten/SDL_sysjoystick.c	Wed Apr 15 21:25:15 2015 +0200
+++ b/src/joystick/emscripten/SDL_sysjoystick.c	Wed Apr 15 21:27:10 2015 +0200
@@ -350,6 +350,10 @@
                         buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
                         SDL_PrivateJoystickButton(item->joystick, i, buttonState);
                     }
+
+                    /* store values to compare them in the next update */
+                    item->analogButton[i] = gamepadState.analogButton[i];
+                    item->digitalButton[i] = gamepadState.digitalButton[i];
                 }
 
                 for(i = 0; i < item->naxes; i++) {
@@ -358,17 +362,12 @@
                         SDL_PrivateJoystickAxis(item->joystick, i,
                                                   (Sint16) (32767.*gamepadState.axis[i]));
                     }
+
+                    /* store to compare in next update */
+                    item->axis[i] = gamepadState.axis[i];
                 }
 
                 item->timestamp = gamepadState.timestamp;
-                for( i = 0; i < item->naxes; i++) {
-                    item->axis[i] = gamepadState.axis[i];
-                }
-
-                for( i = 0; i < item->nbuttons; i++) {
-                    item->analogButton[i] = gamepadState.analogButton[i];
-                    item->digitalButton[i] = gamepadState.digitalButton[i];
-                }
             }
         }
     }