tree 8cbca1e6b293
parent 7ddddb71cec9 author Edward Rudd <urkle@outoforder.cc> 1358030045 18000 committer Edward Rudd <urkle@outoforder.cc> 1358030045 18000 revision 6820 branch default Consolidate iterating the SupportedControllers array also fix memory leak when controller mapping not found
This commit is contained in:
parent
831e12e08b
commit
65399f4c26
1 changed files with 22 additions and 57 deletions
|
@ -242,11 +242,24 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
|
||||||
{
|
{
|
||||||
return s_pXInputMapping;
|
return s_pXInputMapping;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
|
||||||
|
ControllerMapping_t *pSupportedController = s_pSupportedControllers;
|
||||||
|
while ( pSupportedController )
|
||||||
|
{
|
||||||
|
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) )
|
||||||
|
{
|
||||||
|
return pSupportedController;
|
||||||
|
}
|
||||||
|
pSupportedController = pSupportedController->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* convert a string to its enum equivalent
|
* convert a string to its enum equivalent
|
||||||
*/
|
*/
|
||||||
|
@ -681,19 +694,6 @@ SDL_GameControllerNameForIndex(int device_index)
|
||||||
{
|
{
|
||||||
return pSupportedController->name;
|
return pSupportedController->name;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
|
|
||||||
pSupportedController = s_pSupportedControllers;
|
|
||||||
while ( pSupportedController )
|
|
||||||
{
|
|
||||||
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) )
|
|
||||||
{
|
|
||||||
return pSupportedController->name;
|
|
||||||
}
|
|
||||||
pSupportedController = pSupportedController->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,24 +708,6 @@ int SDL_IsGameController(int device_index)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
|
|
||||||
pSupportedController = s_pSupportedControllers;
|
|
||||||
// debug code to help get the guid string for a new joystick
|
|
||||||
/* char szGUID[33];
|
|
||||||
SDL_JoystickGetGUIDString( jGUID, szGUID, sizeof(szGUID) );
|
|
||||||
printf( "%s\n", pchGUID );
|
|
||||||
SDL_free( pchGUID );*/
|
|
||||||
while ( pSupportedController )
|
|
||||||
{
|
|
||||||
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) )
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
pSupportedController = pSupportedController->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,37 +742,21 @@ SDL_GameControllerOpen(int device_index)
|
||||||
gamecontrollerlist = gamecontrollerlist->next;
|
gamecontrollerlist = gamecontrollerlist->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and initialize the joystick
|
// Find a Controller Mapping
|
||||||
gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller));
|
|
||||||
if (gamecontroller == NULL) {
|
|
||||||
SDL_OutOfMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSupportedController = SDL_PrivateGetControllerMapping(device_index);
|
pSupportedController = SDL_PrivateGetControllerMapping(device_index);
|
||||||
if ( !pSupportedController )
|
|
||||||
{
|
|
||||||
SDL_JoystickGUID jGUID;
|
|
||||||
|
|
||||||
jGUID = SDL_JoystickGetDeviceGUID( device_index );
|
|
||||||
pSupportedController = s_pSupportedControllers;
|
|
||||||
while ( pSupportedController )
|
|
||||||
{
|
|
||||||
if ( !SDL_memcmp( &jGUID, &pSupportedController->guid, sizeof(jGUID) ) )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSupportedController = pSupportedController->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !pSupportedController )
|
if ( !pSupportedController )
|
||||||
{
|
{
|
||||||
SDL_SetError("Couldn't find mapping for device (%d)", device_index );
|
SDL_SetError("Couldn't find mapping for device (%d)", device_index );
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create and initialize the joystick
|
||||||
|
gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller));
|
||||||
|
if (gamecontroller == NULL) {
|
||||||
|
SDL_OutOfMemory();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
|
SDL_memset(gamecontroller, 0, (sizeof *gamecontroller));
|
||||||
gamecontroller->joystick = SDL_JoystickOpen(device_index);
|
gamecontroller->joystick = SDL_JoystickOpen(device_index);
|
||||||
if ( !gamecontroller->joystick ) {
|
if ( !gamecontroller->joystick ) {
|
||||||
|
@ -1024,7 +990,6 @@ SDL_GameControllerQuit(void)
|
||||||
SDL_GameControllerClose(SDL_gamecontrollers);
|
SDL_GameControllerClose(SDL_gamecontrollers);
|
||||||
}
|
}
|
||||||
|
|
||||||
pControllerMap = s_pSupportedControllers;
|
|
||||||
while ( s_pSupportedControllers )
|
while ( s_pSupportedControllers )
|
||||||
{
|
{
|
||||||
pControllerMap = s_pSupportedControllers;
|
pControllerMap = s_pSupportedControllers;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue