Engine/lib/sdl/src/joystick/emscripten/SDL_sysjoystick.c
/* Function to scan the system for joysticks.
 * It should return 0, or -1 on an unrecoverable fatal error.
 */
Function to scan the system for joysticks.
It should return 0, or -1 on an unrecoverable fatal error.
Function to scan the system for joysticks . It should return 0 or - 1 on an unrecoverable fatal error .
int
SDL_SYS_JoystickInit(void)
{
    int retval, i, numjs;
    EmscriptenGamepadEvent gamepadState;
    numjoysticks = 0;
    numjs = emscripten_get_num_gamepads();
    if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
        return SDL_SetError("Gamepads not supported");
    }
    if (numjs > 0) {
        for(i = 0; i < numjs; i++) {
            retval = emscripten_get_gamepad_status(i, &gamepadState);
            if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
                Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
                                             &gamepadState,
                                             NULL);
            }
        }
    }
    retval = emscripten_set_gamepadconnected_callback(NULL,
                                                      0,
                                                      Emscripten_JoyStickConnected);
    if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
        SDL_SYS_JoystickQuit();
        return SDL_SetError("Could not set gamepad connect callback");
    }
    retval = emscripten_set_gamepaddisconnected_callback(NULL,
                                                         0,
                                                         Emscripten_JoyStickDisconnected);
    if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
        SDL_SYS_JoystickQuit();
        return SDL_SetError("Could not set gamepad disconnect callback");
    }
    return 0;
}
int SDL_SYS_JoystickInit ( void ) { int retval , i , numjs ; EmscriptenGamepadEvent gamepadState ; numjoysticks = 0 ; numjs = emscripten_get_num_gamepads ( ) ; if ( numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED ) { return SDL_SetError ( " " ) ; } if ( numjs > 0 ) { for ( i = 0 ; i < numjs ; i ++ ) { retval = emscripten_get_gamepad_status ( i , & gamepadState ) ; if ( retval == EMSCRIPTEN_RESULT_SUCCESS ) { Emscripten_JoyStickConnected ( EMSCRIPTEN_EVENT_GAMEPADCONNECTED , & gamepadState , NULL ) ; } } } retval = emscripten_set_gamepadconnected_callback ( NULL , 0 , Emscripten_JoyStickConnected ) ; if ( retval != EMSCRIPTEN_RESULT_SUCCESS ) { SDL_SYS_JoystickQuit ( ) ; return SDL_SetError ( " " ) ; } retval = emscripten_set_gamepaddisconnected_callback ( NULL , 0 , Emscripten_JoyStickDisconnected ) ; if ( retval != EMSCRIPTEN_RESULT_SUCCESS ) { SDL_SYS_JoystickQuit ( ) ; return SDL_SetError ( " " ) ; } return 0 ; }
Function to scan the system for joysticks.
Function to scan the system for joysticks .
/* Check if gamepad is supported by browser */ /* handle already connected gamepads */