From dc6e31d270f6ffd8c28abfe80fd2e241bccd2160 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 26 Nov 2012 23:41:50 -0800 Subject: [PATCH 1/4] Hopefully fixed BSD joystick code --- src/joystick/bsd/SDL_sysjoystick.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c index 17dcc9686..18be0f3e1 100644 --- a/src/joystick/bsd/SDL_sysjoystick.c +++ b/src/joystick/bsd/SDL_sysjoystick.c @@ -175,15 +175,14 @@ SDL_SYS_JoystickInit(void) SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i); - nj.index = SDL_SYS_numjoysticks; - joynames[nj.index] = strdup(s); + joynames[SDL_SYS_numjoysticks] = strdup(s); - if (SDL_SYS_JoystickOpen(&nj, nj.index) == 0) { + if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) { SDL_SYS_JoystickClose(&nj); SDL_SYS_numjoysticks++; } else { - SDL_free(joynames[nj.index]); - joynames[nj.index] = NULL; + SDL_free(joynames[SDL_SYS_numjoysticks]); + joynames[SDL_SYS_numjoysticks] = NULL; } } for (i = 0; i < MAX_JOY_JOYS; i++) { @@ -295,7 +294,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index) joy->nbuttons = 2; joy->nhats = 0; joy->nballs = 0; - joydevnames[joy->index] = strdup("Gameport joystick"); + joydevnames[device_index] = strdup("Gameport joystick"); goto usbend; } else { hw->type = BSDJOY_UHID; @@ -359,8 +358,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index) s = hid_usage_in_page(hitem.usage); sp = SDL_malloc(SDL_strlen(s) + 5); SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)", - s, joy->index); - joydevnames[joy->index] = sp; + s, device_index); + joydevnames[device_index] = sp; } } break; From 9deff82aa9a51fa2b18351229322eb2d976e10d1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 26 Nov 2012 23:50:12 -0800 Subject: [PATCH 2/4] The XInput code is only available in the DirectInput joystick driver. --- src/joystick/SDL_gamecontroller.c | 8 ++++---- src/joystick/SDL_sysjoystick.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 10445c198..440fea0c5 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -81,7 +81,7 @@ typedef struct _ControllerMapping_t /* default mappings we support */ const char *s_ControllerMappings [] = { -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_DINPUT "xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5", "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", "88880803000000000000504944564944,PS3,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", @@ -235,7 +235,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) */ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) { -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_DINPUT if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping ) { return s_pXInputMapping; @@ -576,7 +576,7 @@ SDL_GameControllerInit(void) pchMapping = SDL_PrivateGetControllerMappingFromMappingString( pMappingString ); if ( pchGUID && pchName ) { -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_DINPUT if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) { s_pXInputMapping = pControllerMapping; @@ -628,7 +628,7 @@ SDL_GameControllerInit(void) if ( pchGUID && pchName ) { -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_DINPUT if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) { s_pXInputMapping = pControllerMapping; diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index d67f916cb..028855b8b 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -113,7 +113,7 @@ extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index ); */ extern JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick); -#ifdef __WIN32__ +#ifdef SDL_JOYSTICK_DINPUT /* Function to get the current instance id of the joystick located at device_index */ extern int SDL_SYS_IsXInputDeviceIndex( int device_index ); #endif From d0d72a403cd0799670d92ebaeda22b66fb2bcd77 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 26 Nov 2012 23:53:18 -0800 Subject: [PATCH 3/4] Fixed unused variable warning --- src/joystick/SDL_gamecontroller.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 440fea0c5..03bd7fb9b 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -730,8 +730,6 @@ SDL_GameControllerOpen(int device_index) SDL_GameController *gamecontrollerlist; ControllerMapping_t *pSupportedController = NULL; - int deviceMappingIndex = -1; - if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); return (NULL); From 94866bcf0db390e9a5584abbfa1e89df2724f4fe Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 26 Nov 2012 23:56:24 -0800 Subject: [PATCH 4/4] Fixed Visual Studio 2008 build --- VisualC/SDL/SDL_VS2008.vcproj | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/VisualC/SDL/SDL_VS2008.vcproj b/VisualC/SDL/SDL_VS2008.vcproj index 3c06ac90b..802f7f36c 100644 --- a/VisualC/SDL/SDL_VS2008.vcproj +++ b/VisualC/SDL/SDL_VS2008.vcproj @@ -411,6 +411,10 @@ RelativePath="..\..\include\SDL_events.h" > + + @@ -451,6 +455,10 @@ RelativePath="..\..\include\SDL_main.h" > + + @@ -856,6 +864,10 @@ RelativePath="..\..\src\video\SDL_fillrect.c" > + +