Engine/lib/sdl/src/joystick/SDL_gamecontroller.c
/*
 * Open a controller for use - the index passed as an argument refers to
 * the N'th controller on the system.  This index is the value which will
 * identify this controller in future controller events.
 *
 * This function returns a controller identifier, or NULL if an error occurred.
 */
Open a controller for use - the index passed as an argument refers to
the N'th controller on the system.  This index is the value which will
identify this controller in future controller events.

This function returns a controller identifier, or NULL if an error occurred.
Open a controller for use - the index passed as an argument refers to the N ' th controller on the system . This index is the value which will identify this controller in future controller events . This function returns a controller identifier or NULL if an error occurred .
SDL_GameController *
SDL_GameControllerOpen(int device_index)
{
    SDL_GameController *gamecontroller;
    SDL_GameController *gamecontrollerlist;
    ControllerMapping_t *pSupportedController = NULL;
    if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
        SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
        return (NULL);
    }
    gamecontrollerlist = SDL_gamecontrollers;
    while (gamecontrollerlist) {
        if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
                gamecontroller = gamecontrollerlist;
                ++gamecontroller->ref_count;
                return (gamecontroller);
        }
        gamecontrollerlist = gamecontrollerlist->next;
    }
    pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
    if (!pSupportedController) {
        SDL_SetError("Couldn't find mapping for device (%d)", device_index);
        return (NULL);
    }
    gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller));
    if (gamecontroller == NULL) {
        SDL_OutOfMemory();
        return NULL;
    }
    SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
    gamecontroller->joystick = SDL_JoystickOpen(device_index);
    if (!gamecontroller->joystick) {
        SDL_free(gamecontroller);
        return NULL;
    }
    SDL_PrivateLoadButtonMapping(&gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping);
    ++gamecontroller->ref_count;
    gamecontroller->next = SDL_gamecontrollers;
    SDL_gamecontrollers = gamecontroller;
    SDL_SYS_JoystickUpdate(gamecontroller->joystick);
    return (gamecontroller);
}
SDL_GameController * SDL_GameControllerOpen ( int device_index ) { SDL_GameController * gamecontroller ; SDL_GameController * gamecontrollerlist ; ControllerMapping_t * pSupportedController = NULL ; if ( ( device_index < 0 ) || ( device_index >= SDL_NumJoysticks ( ) ) ) { SDL_SetError ( " " , SDL_NumJoysticks ( ) ) ; return ( NULL ) ; } gamecontrollerlist = SDL_gamecontrollers ; while ( gamecontrollerlist ) { if ( SDL_SYS_GetInstanceIdOfDeviceIndex ( device_index ) == gamecontrollerlist -> joystick -> instance_id ) { gamecontroller = gamecontrollerlist ; ++ gamecontroller -> ref_count ; return ( gamecontroller ) ; } gamecontrollerlist = gamecontrollerlist -> next ; } pSupportedController = SDL_PrivateGetControllerMapping ( device_index ) ; if ( ! pSupportedController ) { SDL_SetError ( " " , device_index ) ; return ( NULL ) ; } gamecontroller = ( SDL_GameController * ) SDL_malloc ( ( sizeof * gamecontroller ) ) ; if ( gamecontroller == NULL ) { SDL_OutOfMemory ( ) ; return NULL ; } SDL_memset ( gamecontroller , 0 , ( sizeof * gamecontroller ) ) ; gamecontroller -> joystick = SDL_JoystickOpen ( device_index ) ; if ( ! gamecontroller -> joystick ) { SDL_free ( gamecontroller ) ; return NULL ; } SDL_PrivateLoadButtonMapping ( & gamecontroller -> mapping , pSupportedController -> guid , pSupportedController -> name , pSupportedController -> mapping ) ; ++ gamecontroller -> ref_count ; gamecontroller -> next = SDL_gamecontrollers ; SDL_gamecontrollers = gamecontroller ; SDL_SYS_JoystickUpdate ( gamecontroller -> joystick ) ; return ( gamecontroller ) ; }
Open a controller for use - the index passed as an argument refers to
 the N'th controller on the system.
Open a controller for use - the index passed as an argument refers to the N ' th controller on the system .
/* If the controller is already open, return it */ /* Find a controller mapping */ /* Create and initialize the joystick */ /* Add joystick to list */ /* Link the joystick in the list */