Engine/lib/sdl/src/joystick/emscripten/SDL_sysjoystick.c
/* Function to update the state of a joystick - called as a device poll.
 * This function shouldn't update the joystick structure directly,
 * but instead should call SDL_PrivateJoystick*() to deliver events
 * and update joystick device state.
 */
Function to update the state of a joystick - called as a device poll.
This function shouldn't update the joystick structure directly,
but instead should call SDL_PrivateJoystick*() to deliver events
and update joystick device state.
Function to update the state of a joystick - called as a device poll . This function shouldn ' t update the joystick structure directly but instead should call SDL_PrivateJoystick * () to deliver events and update joystick device state .
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
    EmscriptenGamepadEvent gamepadState;
    SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
    int i, result, buttonState;
    if (item) {
        result = emscripten_get_gamepad_status(item->index, &gamepadState);
        if( result == EMSCRIPTEN_RESULT_SUCCESS) {
            if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
                for(i = 0; i < item->nbuttons; i++) {
                    if(item->digitalButton[i] != gamepadState.digitalButton[i]) {
                        buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
                        SDL_PrivateJoystickButton(item->joystick, i, buttonState);
                    }
                    item->analogButton[i] = gamepadState.analogButton[i];
                    item->digitalButton[i] = gamepadState.digitalButton[i];
                }
                for(i = 0; i < item->naxes; i++) {
                    if(item->axis[i] != gamepadState.axis[i]) {
                        SDL_PrivateJoystickAxis(item->joystick, i,
                                                  (Sint16) (32767.*gamepadState.axis[i]));
                    }
                    item->axis[i] = gamepadState.axis[i];
                }
                item->timestamp = gamepadState.timestamp;
            }
        }
    }
}
void SDL_SYS_JoystickUpdate ( SDL_Joystick * joystick ) { EmscriptenGamepadEvent gamepadState ; SDL_joylist_item * item = ( SDL_joylist_item * ) joystick -> hwdata ; int i , result , buttonState ; if ( item ) { result = emscripten_get_gamepad_status ( item -> index , & gamepadState ) ; if ( result == EMSCRIPTEN_RESULT_SUCCESS ) { if ( gamepadState . timestamp == 0 || gamepadState . timestamp != item -> timestamp ) { for ( i = 0 ; i < item -> nbuttons ; i ++ ) { if ( item -> digitalButton [ i ] != gamepadState . digitalButton [ i ] ) { buttonState = gamepadState . digitalButton [ i ] ? SDL_PRESSED : SDL_RELEASED ; SDL_PrivateJoystickButton ( item -> joystick , i , buttonState ) ; } item -> analogButton [ i ] = gamepadState . analogButton [ i ] ; item -> digitalButton [ i ] = gamepadState . digitalButton [ i ] ; } for ( i = 0 ; i < item -> naxes ; i ++ ) { if ( item -> axis [ i ] != gamepadState . axis [ i ] ) { SDL_PrivateJoystickAxis ( item -> joystick , i , ( Sint16 ) ( 32767. * gamepadState . axis [ i ] ) ) ; } item -> axis [ i ] = gamepadState . axis [ i ] ; } item -> timestamp = gamepadState . timestamp ; } } } }
Function to update the state of a joystick - called as a device poll.
Function to update the state of a joystick - called as a device poll .
/* store values to compare them in the next update */ // do we need to do conversion? /* store to compare in next update */