Skip to content
Permalink
Browse files

Emscripten: Simplified implementation of joystick update function.

The function was implemented using four loops but only needed two.
  • Loading branch information
philippwiesemann committed Apr 15, 2015
1 parent 86fb92a commit e6b7b38c6cedbfca5392642c75b5e84a5a8d945d
Showing with 6 additions and 7 deletions.
  1. +6 −7 src/joystick/emscripten/SDL_sysjoystick.c
@@ -350,6 +350,10 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
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_SYS_JoystickUpdate(SDL_Joystick * joystick)
SDL_PrivateJoystickAxis(item->joystick, i,
(Sint16) (32767.*gamepadState.axis[i]));
}
}

item->timestamp = gamepadState.timestamp;
for( i = 0; i < item->naxes; i++) {
/* store to compare in next update */
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];
}
item->timestamp = gamepadState.timestamp;
}
}
}

0 comments on commit e6b7b38

Please sign in to comment.