Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: added preliminary joystick / game controller support (minus ho…
Browse files Browse the repository at this point in the history
…tplugging)
  • Loading branch information
DavidLudwig committed May 20, 2013
1 parent ccc96c8 commit f3ad223
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 15 deletions.
6 changes: 3 additions & 3 deletions VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
Expand Up @@ -75,9 +75,9 @@
<ClCompile Include="..\..\src\file\SDL_rwops.c" />
<ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
<ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\SDL_gamecontroller.c" />
<ClCompile Include="..\..\src\joystick\SDL_joystick.c" />
<ClCompile Include="..\..\src\joystick\windowsrt\SDL_xinputjoystick.c" />
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\render\direct3d11\SDL_render_d3d11.cpp">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
Expand Down Expand Up @@ -426,7 +426,7 @@
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>xinput.lib;xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -440,7 +440,7 @@
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies>xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>xinput.lib;xaudio2.lib;d2d1.lib;d3d11.lib;dxgi.lib;ole32.lib;windowscodecs.lib;dwrite.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'">
Expand Down
6 changes: 3 additions & 3 deletions VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
Expand Up @@ -192,9 +192,6 @@
<ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -267,6 +264,9 @@
<ClCompile Include="..\..\src\joystick\SDL_gamecontroller.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\joystick\windowsrt\SDL_xinputjoystick.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\begin_code.h">
Expand Down
8 changes: 6 additions & 2 deletions include/SDL_config_windowsrt.h
Expand Up @@ -144,8 +144,12 @@ typedef unsigned int uintptr_t;
/* Enable various input drivers */
// TODO, WinRT: Get haptic support working
#define SDL_HAPTIC_DISABLED 1
// TODO, WinRT: Get joystick support working
#define SDL_JOYSTICK_DISABLED 1

#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#define SDL_JOYSTICK_DISABLED 1
#else
#define SDL_JOYSTICK_XINPUT 1
#endif

/* Enable various shared object loading systems */
#define SDL_LOADSO_WINDOWS 1
Expand Down
14 changes: 8 additions & 6 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -89,8 +89,10 @@ typedef struct _ControllerMapping_t
/* default mappings we support */
const char *s_ControllerMappings [] =
{
#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
"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",
#endif
#ifdef SDL_JOYSTICK_DINPUT
"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 Controller,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",
"4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,",
Expand Down Expand Up @@ -119,7 +121,7 @@ const char *s_ControllerMappings [] =
};

static ControllerMapping_t *s_pSupportedControllers = NULL;
#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
static ControllerMapping_t *s_pXInputMapping = NULL;
#endif

Expand Down Expand Up @@ -310,7 +312,7 @@ ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *gu
*/
ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
{
#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping )
{
return s_pXInputMapping;
Expand Down Expand Up @@ -699,15 +701,15 @@ SDL_GameControllerAddMapping( const char *mappingString )
char *pchMapping;
SDL_JoystickGUID jGUID;
ControllerMapping_t *pControllerMapping;
#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
SDL_bool is_xinput_mapping = SDL_FALSE;
#endif

pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString );
if (!pchGUID) {
return -1;
}
#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) {
is_xinput_mapping = SDL_TRUE;
}
Expand Down Expand Up @@ -742,7 +744,7 @@ SDL_GameControllerAddMapping( const char *mappingString )
SDL_free( pchMapping );
return SDL_OutOfMemory();
}
#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
if ( is_xinput_mapping )
{
s_pXInputMapping = pControllerMapping;
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/SDL_sysjoystick.h
Expand Up @@ -108,7 +108,7 @@ extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
/* Function to return the stable GUID for a opened joystick */
extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);

#ifdef SDL_JOYSTICK_DINPUT
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
/* Function to get the current instance id of the joystick located at device_index */
extern SDL_bool SDL_SYS_IsXInputDeviceIndex( int device_index );
#endif
Expand Down

0 comments on commit f3ad223

Please sign in to comment.