Updated coding style to match the rest of SDL

This commit is contained in:
Sam Lantinga 2014-05-13 11:32:36 -07:00
parent 81c574b8cb
commit 6735097332

View File

@ -111,8 +111,7 @@ int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_Gam
*/ */
int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
{ {
switch( event->type ) switch(event->type) {
{
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
{ {
SDL_GameController *controllerlist; SDL_GameController *controllerlist;
@ -120,16 +119,12 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
if (event->jaxis.axis >= k_nMaxReverseEntries) break; if (event->jaxis.axis >= k_nMaxReverseEntries) break;
controllerlist = SDL_gamecontrollers; controllerlist = SDL_gamecontrollers;
while ( controllerlist ) while (controllerlist) {
{ if (controllerlist->joystick->instance_id == event->jaxis.which) {
if ( controllerlist->joystick->instance_id == event->jaxis.which ) if (controllerlist->mapping.raxes[event->jaxis.axis] >= 0) /* simple axis to axis, send it through */ {
{
if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) /* simple axis to axis, send it through */
{
SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis]; SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis];
Sint16 value = event->jaxis.value; Sint16 value = event->jaxis.value;
switch (axis) switch (axis) {
{
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
/* Shift it to be 0 - 32767. */ /* Shift it to be 0 - 32767. */
@ -138,9 +133,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
break; break;
} }
SDL_PrivateGameControllerAxis(controllerlist, axis, value); SDL_PrivateGameControllerAxis(controllerlist, axis, value);
} } else if (controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0) { /* simulate an axis as a button */
else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) /* simulate an axis as a button */
{
SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED); SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED);
} }
break; break;
@ -157,16 +150,11 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
if (event->jbutton.button >= k_nMaxReverseEntries) break; if (event->jbutton.button >= k_nMaxReverseEntries) break;
controllerlist = SDL_gamecontrollers; controllerlist = SDL_gamecontrollers;
while ( controllerlist ) while (controllerlist) {
{ if (controllerlist->joystick->instance_id == event->jbutton.which) {
if ( controllerlist->joystick->instance_id == event->jbutton.which ) if (controllerlist->mapping.rbuttons[event->jbutton.button] >= 0) { /* simple button as button */
{
if ( controllerlist->mapping.rbuttons[event->jbutton.button] >= 0 ) /* simple button as button */
{
SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state); SDL_PrivateGameControllerButton(controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state);
} } else if (controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0) { /* an button pretending to be an axis */
else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) /* an button pretending to be an axis */
{
SDL_PrivateGameControllerAxis(controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0); SDL_PrivateGameControllerAxis(controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0);
} }
break; break;
@ -182,10 +170,8 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
if (event->jhat.hat >= 4) break; if (event->jhat.hat >= 4) break;
controllerlist = SDL_gamecontrollers; controllerlist = SDL_gamecontrollers;
while ( controllerlist ) while (controllerlist) {
{ if (controllerlist->joystick->instance_id == event->jhat.which) {
if ( controllerlist->joystick->instance_id == event->jhat.which )
{
Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value; Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value;
/* Get list of removed bits (button release) */ /* Get list of removed bits (button release) */
Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame; Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame;
@ -224,8 +210,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
break; break;
case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEADDED:
{ {
if ( SDL_IsGameController(event->jdevice.which ) ) if (SDL_IsGameController(event->jdevice.which)) {
{
SDL_Event deviceevent; SDL_Event deviceevent;
deviceevent.type = SDL_CONTROLLERDEVICEADDED; deviceevent.type = SDL_CONTROLLERDEVICEADDED;
deviceevent.cdevice.which = event->jdevice.which; deviceevent.cdevice.which = event->jdevice.which;
@ -236,10 +221,8 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
case SDL_JOYDEVICEREMOVED: case SDL_JOYDEVICEREMOVED:
{ {
SDL_GameController *controllerlist = SDL_gamecontrollers; SDL_GameController *controllerlist = SDL_gamecontrollers;
while ( controllerlist ) while (controllerlist) {
{ if (controllerlist->joystick->instance_id == event->jdevice.which) {
if ( controllerlist->joystick->instance_id == event->jdevice.which )
{
SDL_Event deviceevent; SDL_Event deviceevent;
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED; deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
deviceevent.cdevice.which = event->jdevice.which; deviceevent.cdevice.which = event->jdevice.which;
@ -263,10 +246,8 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid) ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
{ {
ControllerMapping_t *pSupportedController = s_pSupportedControllers; ControllerMapping_t *pSupportedController = s_pSupportedControllers;
while ( pSupportedController ) while (pSupportedController) {
{ if (SDL_memcmp(guid, &pSupportedController->guid, sizeof(*guid)) == 0) {
if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) )
{
return pSupportedController; return pSupportedController;
} }
pSupportedController = pSupportedController->next; pSupportedController = pSupportedController->next;
@ -280,8 +261,7 @@ ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *gu
ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
{ {
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT) #if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping ) if (SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping) {
{
return s_pXInputMapping; return s_pXInputMapping;
} }
else else
@ -311,8 +291,7 @@ SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchStrin
if (!pchString || !pchString[0]) if (!pchString || !pchString[0])
return SDL_CONTROLLER_AXIS_INVALID; return SDL_CONTROLLER_AXIS_INVALID;
for ( entry = 0; map_StringForControllerAxis[entry]; ++entry) for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
{
if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry])) if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
return entry; return entry;
} }
@ -324,8 +303,7 @@ SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchStrin
*/ */
const char* SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis) const char* SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis)
{ {
if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) {
{
return map_StringForControllerAxis[axis]; return map_StringForControllerAxis[axis];
} }
return NULL; return NULL;
@ -359,9 +337,8 @@ SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchS
if (!pchString || !pchString[0]) if (!pchString || !pchString[0])
return SDL_CONTROLLER_BUTTON_INVALID; return SDL_CONTROLLER_BUTTON_INVALID;
for ( entry = 0; map_StringForControllerButton[entry]; ++entry) for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
{ if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) )
return entry; return entry;
} }
return SDL_CONTROLLER_BUTTON_INVALID; return SDL_CONTROLLER_BUTTON_INVALID;
@ -372,8 +349,7 @@ SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchS
*/ */
const char* SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis) const char* SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis)
{ {
if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) {
{
return map_StringForControllerButton[axis]; return map_StringForControllerButton[axis];
} }
return NULL; return NULL;
@ -391,73 +367,51 @@ void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char
axis = SDL_GameControllerGetAxisFromString(szGameButton); axis = SDL_GameControllerGetAxisFromString(szGameButton);
iSDLButton = SDL_atoi(&szJoystickButton[1]); iSDLButton = SDL_atoi(&szJoystickButton[1]);
if ( szJoystickButton[0] == 'a' ) if (szJoystickButton[0] == 'a') {
{ if (iSDLButton >= k_nMaxReverseEntries) {
if ( iSDLButton >= k_nMaxReverseEntries )
{
SDL_SetError("Axis index too large: %d", iSDLButton); SDL_SetError("Axis index too large: %d", iSDLButton);
return; return;
} }
if ( axis != SDL_CONTROLLER_AXIS_INVALID ) if (axis != SDL_CONTROLLER_AXIS_INVALID) {
{
pMapping->axes[ axis ] = iSDLButton; pMapping->axes[ axis ] = iSDLButton;
pMapping->raxes[ iSDLButton ] = axis; pMapping->raxes[ iSDLButton ] = axis;
} } else if (button != SDL_CONTROLLER_BUTTON_INVALID) {
else if ( button != SDL_CONTROLLER_BUTTON_INVALID )
{
pMapping->axesasbutton[ button ] = iSDLButton; pMapping->axesasbutton[ button ] = iSDLButton;
pMapping->raxesasbutton[ iSDLButton ] = button; pMapping->raxesasbutton[ iSDLButton ] = button;
} } else {
else
{
SDL_assert(!"How did we get here?"); SDL_assert(!"How did we get here?");
} }
} } else if (szJoystickButton[0] == 'b') {
else if ( szJoystickButton[0] == 'b' ) if (iSDLButton >= k_nMaxReverseEntries) {
{
if ( iSDLButton >= k_nMaxReverseEntries )
{
SDL_SetError("Button index too large: %d", iSDLButton); SDL_SetError("Button index too large: %d", iSDLButton);
return; return;
} }
if ( button != SDL_CONTROLLER_BUTTON_INVALID ) if (button != SDL_CONTROLLER_BUTTON_INVALID) {
{
pMapping->buttons[ button ] = iSDLButton; pMapping->buttons[ button ] = iSDLButton;
pMapping->rbuttons[ iSDLButton ] = button; pMapping->rbuttons[ iSDLButton ] = button;
} } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
{
pMapping->buttonasaxis[ axis ] = iSDLButton; pMapping->buttonasaxis[ axis ] = iSDLButton;
pMapping->rbuttonasaxis[ iSDLButton ] = axis; pMapping->rbuttonasaxis[ iSDLButton ] = axis;
} } else {
else
{
SDL_assert(!"How did we get here?"); SDL_assert(!"How did we get here?");
} }
} } else if (szJoystickButton[0] == 'h') {
else if ( szJoystickButton[0] == 'h' )
{
int hat = SDL_atoi(&szJoystickButton[1]); int hat = SDL_atoi(&szJoystickButton[1]);
int mask = SDL_atoi(&szJoystickButton[3]); int mask = SDL_atoi(&szJoystickButton[3]);
if (hat >= 4) { if (hat >= 4) {
SDL_SetError("Hat index too large: %d", iSDLButton); SDL_SetError("Hat index too large: %d", iSDLButton);
} }
if ( button != SDL_CONTROLLER_BUTTON_INVALID ) if (button != SDL_CONTROLLER_BUTTON_INVALID) {
{
int ridx; int ridx;
pMapping->hatasbutton[ button ].hat = hat; pMapping->hatasbutton[ button ].hat = hat;
pMapping->hatasbutton[ button ].mask = mask; pMapping->hatasbutton[ button ].mask = mask;
ridx = (hat << 4) | mask; ridx = (hat << 4) | mask;
pMapping->rhatasbutton[ ridx ] = button; pMapping->rhatasbutton[ ridx ] = button;
} } else if (axis != SDL_CONTROLLER_AXIS_INVALID) {
else if ( axis != SDL_CONTROLLER_AXIS_INVALID )
{
SDL_assert(!"Support hat as axis"); SDL_assert(!"Support hat as axis");
} } else {
else
{
SDL_assert(!"How did we get here?"); SDL_assert(!"How did we get here?");
} }
} }
@ -479,40 +433,28 @@ SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapp
SDL_memset(szGameButton, 0x0, sizeof(szGameButton)); SDL_memset(szGameButton, 0x0, sizeof(szGameButton));
SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton)); SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton));
while ( pchPos && *pchPos ) while (pchPos && *pchPos) {
{ if (*pchPos == ':') {
if ( *pchPos == ':' )
{
i = 0; i = 0;
bGameButton = SDL_FALSE; bGameButton = SDL_FALSE;
} } else if (*pchPos == ' ') {
else if ( *pchPos == ' ' )
{
} } else if (*pchPos == ',') {
else if ( *pchPos == ',' )
{
i = 0; i = 0;
bGameButton = SDL_TRUE; bGameButton = SDL_TRUE;
SDL_PrivateGameControllerParseButton(szGameButton, szJoystickButton, pMapping); SDL_PrivateGameControllerParseButton(szGameButton, szJoystickButton, pMapping);
SDL_memset(szGameButton, 0x0, sizeof(szGameButton)); SDL_memset(szGameButton, 0x0, sizeof(szGameButton));
SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton)); SDL_memset(szJoystickButton, 0x0, sizeof(szJoystickButton));
} } else if (bGameButton) {
else if ( bGameButton ) if (i >= sizeof(szGameButton)) {
{
if ( i >= sizeof(szGameButton))
{
SDL_SetError("Button name too large: %s", szGameButton); SDL_SetError("Button name too large: %s", szGameButton);
return; return;
} }
szGameButton[i] = *pchPos; szGameButton[i] = *pchPos;
i++; i++;
} } else {
else if (i >= sizeof(szJoystickButton)) {
{
if ( i >= sizeof(szJoystickButton))
{
SDL_SetError("Joystick button name too large: %s", szJoystickButton); SDL_SetError("Joystick button name too large: %s", szJoystickButton);
return; return;
} }
@ -537,28 +479,24 @@ void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_
pMapping->name = pchName; pMapping->name = pchName;
/* set all the button mappings to non defaults */ /* set all the button mappings to non defaults */
for ( j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++ ) for (j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++) {
{
pMapping->axes[j] = -1; pMapping->axes[j] = -1;
pMapping->buttonasaxis[j] = -1; pMapping->buttonasaxis[j] = -1;
} }
for ( j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++ ) for (j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++) {
{
pMapping->buttons[j] = -1; pMapping->buttons[j] = -1;
pMapping->axesasbutton[j] = -1; pMapping->axesasbutton[j] = -1;
pMapping->hatasbutton[j].hat = -1; pMapping->hatasbutton[j].hat = -1;
} }
for ( j = 0; j < k_nMaxReverseEntries; j++ ) for (j = 0; j < k_nMaxReverseEntries; j++) {
{
pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID; pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID;
pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID; pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID;
pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID; pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID;
pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID; pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
} }
for (j = 0; j < k_nMaxHatEntries; j++) for (j = 0; j < k_nMaxHatEntries; j++) {
{
pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID; pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID;
} }
@ -572,11 +510,9 @@ void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_
char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping) char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
{ {
const char *pFirstComma = SDL_strchr(pMapping, ','); const char *pFirstComma = SDL_strchr(pMapping, ',');
if ( pFirstComma ) if (pFirstComma) {
{
char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1); char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
if ( !pchGUID ) if (!pchGUID) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -605,8 +541,7 @@ char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping )
return NULL; return NULL;
pchName = SDL_malloc(pSecondComma - pFirstComma); pchName = SDL_malloc(pSecondComma - pFirstComma);
if ( !pchName ) if (!pchName) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
@ -637,10 +572,8 @@ char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping )
void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pControllerMapping) void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pControllerMapping)
{ {
SDL_GameController *gamecontrollerlist = SDL_gamecontrollers; SDL_GameController *gamecontrollerlist = SDL_gamecontrollers;
while ( gamecontrollerlist ) while (gamecontrollerlist) {
{ if (!SDL_memcmp(&gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) {
if ( !SDL_memcmp( &gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid) ) )
{
SDL_Event event; SDL_Event event;
event.type = SDL_CONTROLLERDEVICEREMAPPED; event.type = SDL_CONTROLLERDEVICEREMAPPED;
event.cdevice.which = gamecontrollerlist->joystick->instance_id; event.cdevice.which = gamecontrollerlist->joystick->instance_id;
@ -697,8 +630,7 @@ SDL_GameControllerAddMappingsFromRW( SDL_RWops * rw, int freerw )
line_end = SDL_strchr(line, '\n'); line_end = SDL_strchr(line, '\n');
if (line_end != NULL) { if (line_end != NULL) {
*line_end = '\0'; *line_end = '\0';
} } else {
else {
line_end = buf + db_size; line_end = buf + db_size;
} }
@ -711,8 +643,8 @@ SDL_GameControllerAddMappingsFromRW( SDL_RWops * rw, int freerw )
platform_len = comma - tmp + 1; platform_len = comma - tmp + 1;
if (platform_len + 1 < SDL_arraysize(line_platform)) { if (platform_len + 1 < SDL_arraysize(line_platform)) {
SDL_strlcpy(line_platform, tmp, platform_len); SDL_strlcpy(line_platform, tmp, platform_len);
if(SDL_strncasecmp(line_platform, platform, platform_len) == 0 if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
&& SDL_GameControllerAddMapping(line) > 0) { SDL_GameControllerAddMapping(line) > 0) {
controllers++; controllers++;
} }
} }
@ -783,8 +715,7 @@ SDL_GameControllerAddMapping( const char *mappingString )
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT) #if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
if ( is_xinput_mapping ) if (is_xinput_mapping) {
{
s_pXInputMapping = pControllerMapping; s_pXInputMapping = pControllerMapping;
} }
#endif #endif
@ -845,11 +776,12 @@ SDL_GameControllerLoadHints()
SDL_GameControllerAddMapping(pUserMappings); SDL_GameControllerAddMapping(pUserMappings);
if ( pchNewLine ) if (pchNewLine) {
pUserMappings = pchNewLine + 1; pUserMappings = pchNewLine + 1;
else } else {
pUserMappings = NULL; pUserMappings = NULL;
} }
}
SDL_free(pTempMappings); SDL_free(pTempMappings);
} }
} }
@ -898,8 +830,7 @@ const char *
SDL_GameControllerNameForIndex(int device_index) SDL_GameControllerNameForIndex(int device_index)
{ {
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index); ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
if ( pSupportedController ) if (pSupportedController) {
{
return pSupportedController->name; return pSupportedController->name;
} }
return NULL; return NULL;
@ -913,8 +844,7 @@ SDL_bool
SDL_IsGameController(int device_index) SDL_IsGameController(int device_index)
{ {
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index); ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
if ( pSupportedController ) if (pSupportedController) {
{
return SDL_TRUE; return SDL_TRUE;
} }
@ -942,8 +872,7 @@ SDL_GameControllerOpen(int device_index)
gamecontrollerlist = SDL_gamecontrollers; gamecontrollerlist = SDL_gamecontrollers;
/* If the controller is already open, return it */ /* If the controller is already open, return it */
while ( gamecontrollerlist ) while (gamecontrollerlist) {
{
if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) { if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
gamecontroller = gamecontrollerlist; gamecontroller = gamecontrollerlist;
++gamecontroller->ref_count; ++gamecontroller->ref_count;
@ -1006,11 +935,9 @@ SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControlle
if (!gamecontroller) if (!gamecontroller)
return 0; return 0;
if (gamecontroller->mapping.axes[axis] >= 0 ) if (gamecontroller->mapping.axes[axis] >= 0) {
{
Sint16 value = (SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axes[axis])); Sint16 value = (SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axes[axis]));
switch (axis) switch (axis) {
{
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
/* Shift it to be 0 - 32767. */ /* Shift it to be 0 - 32767. */
@ -1019,9 +946,7 @@ SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControlle
break; break;
} }
return value; return value;
} } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0) {
else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
{
Uint8 value; Uint8 value;
value = SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis]); value = SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis]);
if (value > 0) if (value > 0)
@ -1041,20 +966,15 @@ SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControl
if (!gamecontroller) if (!gamecontroller)
return 0; return 0;
if ( gamecontroller->mapping.buttons[button] >= 0 ) if (gamecontroller->mapping.buttons[button] >= 0) {
{
return (SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttons[button])); return (SDL_JoystickGetButton(gamecontroller->joystick, gamecontroller->mapping.buttons[button]));
} } else if (gamecontroller->mapping.axesasbutton[button] >= 0) {
else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
{
Sint16 value; Sint16 value;
value = SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button]); value = SDL_JoystickGetAxis(gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button]);
if (ABS(value) > 32768/2) if (ABS(value) > 32768/2)
return 1; return 1;
return 0; return 0;
} } else if (gamecontroller->mapping.hatasbutton[button].hat >= 0) {
else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
{
Uint8 value; Uint8 value;
value = SDL_JoystickGetHat(gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat); value = SDL_JoystickGetHat(gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat);
@ -1115,13 +1035,10 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController
if (!gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID) if (!gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID)
return bind; return bind;
if (gamecontroller->mapping.axes[axis] >= 0 ) if (gamecontroller->mapping.axes[axis] >= 0) {
{
bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS; bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
bind.value.button = gamecontroller->mapping.axes[axis]; bind.value.button = gamecontroller->mapping.axes[axis];
} } else if (gamecontroller->mapping.buttonasaxis[axis] >= 0) {
else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 )
{
bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON; bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
bind.value.button = gamecontroller->mapping.buttonasaxis[axis]; bind.value.button = gamecontroller->mapping.buttonasaxis[axis];
} }
@ -1141,18 +1058,13 @@ SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameControll
if (!gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID) if (!gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID)
return bind; return bind;
if ( gamecontroller->mapping.buttons[button] >= 0 ) if (gamecontroller->mapping.buttons[button] >= 0) {
{
bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON; bind.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
bind.value.button = gamecontroller->mapping.buttons[button]; bind.value.button = gamecontroller->mapping.buttons[button];
} } else if (gamecontroller->mapping.axesasbutton[button] >= 0) {
else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
{
bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS; bind.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
bind.value.axis = gamecontroller->mapping.axesasbutton[button]; bind.value.axis = gamecontroller->mapping.axesasbutton[button];
} } else if (gamecontroller->mapping.hatasbutton[button].hat >= 0) {
else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
{
bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT; bind.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat; bind.value.hat.hat = gamecontroller->mapping.hatasbutton[button].hat;
bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask; bind.value.hat.hat_mask = gamecontroller->mapping.hatasbutton[button].mask;
@ -1182,17 +1094,12 @@ SDL_GameControllerClose(SDL_GameController * gamecontroller)
gamecontrollerlist = SDL_gamecontrollers; gamecontrollerlist = SDL_gamecontrollers;
gamecontrollerlistprev = NULL; gamecontrollerlistprev = NULL;
while ( gamecontrollerlist ) while (gamecontrollerlist) {
{ if (gamecontroller == gamecontrollerlist) {
if (gamecontroller == gamecontrollerlist) if (gamecontrollerlistprev) {
{
if ( gamecontrollerlistprev )
{
/* unlink this entry */ /* unlink this entry */
gamecontrollerlistprev->next = gamecontrollerlist->next; gamecontrollerlistprev->next = gamecontrollerlist->next;
} } else {
else
{
SDL_gamecontrollers = gamecontroller->next; SDL_gamecontrollers = gamecontroller->next;
} }
@ -1213,14 +1120,12 @@ void
SDL_GameControllerQuit(void) SDL_GameControllerQuit(void)
{ {
ControllerMapping_t *pControllerMap; ControllerMapping_t *pControllerMap;
while ( SDL_gamecontrollers ) while (SDL_gamecontrollers) {
{
SDL_gamecontrollers->ref_count = 1; SDL_gamecontrollers->ref_count = 1;
SDL_GameControllerClose(SDL_gamecontrollers); SDL_GameControllerClose(SDL_gamecontrollers);
} }
while ( s_pSupportedControllers ) while (s_pSupportedControllers) {
{
pControllerMap = s_pSupportedControllers; pControllerMap = s_pSupportedControllers;
s_pSupportedControllers = s_pSupportedControllers->next; s_pSupportedControllers = s_pSupportedControllers->next;
SDL_free(pControllerMap->name); SDL_free(pControllerMap->name);