Made the latest XInput + Haptic changes compile and run on WinRT
authorDavid Ludwig <dludwig@pobox.com>
Fri, 04 Jul 2014 18:20:23 -0400
changeset 8973 47fb6a7e7f68
parent 8972 dfc759d7486f
child 8974 f813b8b10b55
Made the latest XInput + Haptic changes compile and run on WinRT Notes: - Support for the 'Guide' button does not seem to be possible, as XInputGetStateEx is not available on WinRT. - Haptic support appears to be working on WinRT now! - SDL/WinRT does not allow calls to LoadLibrary or LoadLibraryEx. The calls to those were removed by this change, but only when compiling for WinRT. Non-WinRT Windows will continue to detect and load XInput via LoadLibrary and GetProcAddress calls.
VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj
VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters
VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj
VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters
include/SDL_config_winrt.h
src/core/windows/SDL_xinput.c
--- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj	Thu Jul 03 15:39:55 2014 -0700
+++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj	Fri Jul 04 18:20:23 2014 -0400
@@ -234,6 +234,7 @@
     <ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
+    <ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
     <ClInclude Include="..\..\src\render\direct3d11\SDL_render_winrt.h" />
     <ClInclude Include="..\..\src\render\mmx.h" />
     <ClInclude Include="..\..\src\render\SDL_d3dmath.h" />
@@ -333,6 +334,7 @@
     <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\windows\SDL_xinputjoystick.c" />
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     <ClCompile Include="..\..\src\power\SDL_power.c" />
     <ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
--- a/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters	Thu Jul 03 15:39:55 2014 -0700
+++ b/VisualC-WinRT/WinPhone80_VS2012/SDL-WinPhone80.vcxproj.filters	Fri Jul 04 18:20:23 2014 -0400
@@ -357,6 +357,9 @@
     <ClInclude Include="..\..\src\video\winrt\SDL_winrtmessagebox.h">
       <Filter>Source Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -644,5 +647,8 @@
     <ClCompile Include="..\..\src\video\winrt\SDL_winrtmessagebox.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
--- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj	Thu Jul 03 15:39:55 2014 -0700
+++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj	Fri Jul 04 18:20:23 2014 -0400
@@ -100,6 +100,7 @@
     <ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
     <ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
     <ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
+    <ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
     <ClInclude Include="..\..\src\render\direct3d11\SDL_render_winrt.h" />
     <ClInclude Include="..\..\src\render\mmx.h" />
     <ClInclude Include="..\..\src\render\opengles2\SDL_gles2funcs.h" />
@@ -204,7 +205,7 @@
     <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\winrt\SDL_xinputjoystick.c" />
+    <ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c" />
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
     <ClCompile Include="..\..\src\power\SDL_power.c" />
     <ClCompile Include="..\..\src\power\winrt\SDL_syspower.cpp" />
--- a/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters	Thu Jul 03 15:39:55 2014 -0700
+++ b/VisualC-WinRT/WinPhone81_VS2013/SDL-WinPhone81.vcxproj.filters	Fri Jul 04 18:20:23 2014 -0400
@@ -381,6 +381,9 @@
     <ClInclude Include="..\..\src\video\winrt\SDL_winrtvideo_cpp.h">
       <Filter>Source Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h">
+      <Filter>Source Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
@@ -485,9 +488,6 @@
     <ClCompile Include="..\..\src\joystick\SDL_joystick.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\src\joystick\winrt\SDL_xinputjoystick.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -683,5 +683,8 @@
     <ClCompile Include="..\..\src\video\winrt\SDL_winrtvideo.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
--- a/include/SDL_config_winrt.h	Thu Jul 03 15:39:55 2014 -0700
+++ b/include/SDL_config_winrt.h	Fri Jul 04 18:20:23 2014 -0400
@@ -78,7 +78,9 @@
 
 /* Useful headers */
 #define HAVE_DXGI_H 1
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
 #define HAVE_XINPUT_H 1
+#endif
 #define HAVE_LIBC 1
 #define HAVE_STDIO_H 1
 #define STDC_HEADERS 1
--- a/src/core/windows/SDL_xinput.c	Thu Jul 03 15:39:55 2014 -0700
+++ b/src/core/windows/SDL_xinput.c	Fri Jul 04 18:20:23 2014 -0400
@@ -35,6 +35,40 @@
 static int s_XInputDLLRefCount = 0;
 
 
+#ifdef __WINRT__
+
+int
+WIN_LoadXInputDLL(void)
+{
+    /* Getting handles to system dlls (via LoadLibrary and its variants) is not
+     * supported on WinRT, thus, pointers to XInput's functions can't be
+     * retrieved via GetProcAddress.
+     *
+     * When on WinRT, assume that XInput is already loaded, and directly map
+     * its XInput.h-declared functions to the SDL_XInput* set of function
+     * pointers.
+     *
+     * Side-note: XInputGetStateEx is not available for use in WinRT.
+     * This seems to mean that support for the guide button is not available
+     * in WinRT, unfortunately.
+     */
+    SDL_XInputGetState = (XInputGetState_t)XInputGetState;
+    SDL_XInputSetState = (XInputSetState_t)XInputSetState;
+    SDL_XInputGetCapabilities = (XInputGetCapabilities_t)XInputGetCapabilities;
+
+    /* XInput 1.4 ships with Windows 8 and 8.1: */
+    SDL_XInputVersion = (1 << 16) | 4;
+
+    return 0;
+}
+
+void
+WIN_UnloadXInputDLL(void)
+{
+}
+
+#else /* !__WINRT__ */
+
 int
 WIN_LoadXInputDLL(void)
 {
@@ -89,6 +123,7 @@
     }
 }
 
+#endif /* __WINRT__ */
 #endif /* HAVE_XINPUT_H */
 
 /* vi: set ts=4 sw=4 expandtab: */