Navigation Menu

Skip to content

Commit

Permalink
WinRT: build fixes and additional WinRT-related integrations with SDL…
Browse files Browse the repository at this point in the history
… 2.0.0
  • Loading branch information
DavidLudwig committed Aug 14, 2013
1 parent f7049b9 commit d41fdc9
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 31 deletions.
3 changes: 2 additions & 1 deletion VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
Expand Up @@ -100,11 +100,11 @@
<ClCompile Include="..\..\src\SDL.c" />
<ClCompile Include="..\..\src\SDL_assert.c" />
<ClCompile Include="..\..\src\SDL_error.c" />
<ClCompile Include="..\..\src\SDL_fatal.c" />
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_log.c" />
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
<ClCompile Include="..\..\src\stdlib\SDL_iconv.c" />
<ClCompile Include="..\..\src\stdlib\SDL_malloc.c" />
<ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
<ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
<ClCompile Include="..\..\src\stdlib\SDL_string.c" />
Expand Down Expand Up @@ -239,6 +239,7 @@
<ClInclude Include="..\..\src\events\SDL_windowevents_c.h" />
<ClInclude Include="..\..\src\haptic\SDL_haptic_c.h" />
<ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
<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\render\direct3d11\SDL_render_d3d11_cpp.h" />
Expand Down
9 changes: 6 additions & 3 deletions VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
Expand Up @@ -96,9 +96,6 @@
<ClCompile Include="..\..\src\events\SDL_events.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\SDL_fatal.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\video\SDL_fillrect.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -267,6 +264,9 @@
<ClCompile Include="..\..\src\joystick\windowsrt\SDL_xinputjoystick.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\stdlib\SDL_malloc.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\begin_code.h">
Expand Down Expand Up @@ -593,6 +593,9 @@
<ClInclude Include="..\..\src\render\direct3d11\SDL_render_d3d11_cpp.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down
4 changes: 3 additions & 1 deletion include/SDL_config_windowsrt.h
Expand Up @@ -83,6 +83,7 @@ typedef unsigned int uintptr_t;
#define HAVE_STRING_H 1
#define HAVE_CTYPE_H 1
#define HAVE_MATH_H 1
#define HAVE_FLOAT_H 1
#define HAVE_SIGNAL_H 1

/* C library functions */
Expand Down Expand Up @@ -123,14 +124,15 @@ typedef unsigned int uintptr_t;
#define HAVE_ATAN 1
#define HAVE_ATAN2 1
#define HAVE_CEIL 1
//#define HAVE_COPYSIGN 1 // TODO, WinRT: consider using _copysign instead
#define HAVE__COPYSIGN 1
#define HAVE_COS 1
#define HAVE_COSF 1
#define HAVE_FABS 1
#define HAVE_FLOOR 1
#define HAVE_LOG 1
#define HAVE_POW 1
//#define HAVE_SCALBN 1
#define HAVE__SCALB 1
#define HAVE_SIN 1
#define HAVE_SINF 1
#define HAVE_SQRT 1
Expand Down
25 changes: 21 additions & 4 deletions include/SDL_platform.h
Expand Up @@ -120,10 +120,27 @@
#undef __SOLARIS__
#define __SOLARIS__ 1
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
#undef __WIN32__
#define __WIN32__ 1
#endif

#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
/* Try to find out what version of Windows we are compiling for */
#if defined(_MSC_VER) && (_MSC_VER >= 1700) /* _MSC_VER==1700 for MSVC 2012 */
#include <winapifamily.h>
#endif
/* Default to classic, Win32 / Desktop compilation either if:
1. the version of Windows is explicity set to a 'Desktop' (non-Metro) app
2. the version of Windows cannot be determined via winapifamily.h
If neither is true, see if we're compiling for WinRT.
*/
#if ! defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#undef __WIN32__
#define __WIN32__ 1
/* See if we're compiling for WinRT: */
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#undef __WINRT__
#define __WINRT__ 1
#endif /* ! defined(WINAPI_FAMILY_PARTITION) */
#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */

#if defined(__PSP__)
#undef __PSP__
#define __PSP__ 1
Expand Down
3 changes: 3 additions & 0 deletions include/SDL_stdinc.h
Expand Up @@ -80,6 +80,9 @@
# endif
# include <math.h>
#endif
#ifdef HAVE_FLOAT_H
# include <float.h>
#endif
#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
# include <iconv.h>
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/SDL_log.c
Expand Up @@ -322,6 +322,8 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
char *output;
size_t length;
LPTSTR tstr;

#ifndef __WINRT__
BOOL attachResult;
DWORD attachError;
unsigned long charsWritten;
Expand Down Expand Up @@ -353,6 +355,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
}
}
#endif /* ifndef __WINRT__ */

length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1;
output = SDL_stack_alloc(char, length);
Expand All @@ -362,6 +365,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
/* Output to debugger */
OutputDebugString(tstr);

#ifndef __WINRT__
/* Screen output to stderr, if console was attached. */
if (consoleAttached == 1) {
if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
Expand All @@ -371,6 +375,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
OutputDebugString(TEXT("Insufficient heap memory to write message"));
}
}
#endif /* ifndef __WINRT__ */

SDL_free(tstr);
SDL_stack_free(output);
Expand Down
6 changes: 1 addition & 5 deletions src/audio/xaudio2/SDL_xaudio2.c
Expand Up @@ -91,15 +91,11 @@ extern "C" {
}
#endif

#if defined(__WINRT__)
# define SDL_XAUDIO2_HAS_SDK 1
#endif
#if defined(__WIN32__)
#ifdef __GNUC__
/* The configure script already did any necessary checking */
# define SDL_XAUDIO2_HAS_SDK 1
#elif defined(__WINRT__)
/* WinRT always has access to the .the XAudio 2 SD
/* WinRT always has access to the .the XAudio 2 SDK */
# define SDL_XAUDIO2_HAS_SDK
#else
#include <dxsdkver.h> /* XAudio2 exists as of the March 2008 DirectX SDK */
Expand Down
2 changes: 2 additions & 0 deletions src/joystick/SDL_gamecontrollerdb.h
Expand Up @@ -38,6 +38,8 @@ static const char *s_ControllerMappings [] =
"4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
"25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,",
"xinput,X360 Controller,a:b10,b:b11,back:b5,dpdown:b1,dpleft:b2,dpright:b3,dpup:b0,guide:b14,leftshoulder:b8,leftstick:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b7,righttrigger:a5,rightx:a2,righty:a3,start:b4,x:b12,y:b13,",
#elif defined(SDL_JOYSTICK_XINPUT)
"xinput,X360 Controller,a:b10,b:b11,back:b5,dpdown:b1,dpleft:b2,dpright:b3,dpup:b0,guide:b14,leftshoulder:b8,leftstick:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b7,righttrigger:a5,rightx:a2,righty:a3,start:b4,x:b12,y:b13,",
#elif defined(__MACOSX__)
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
Expand Down
3 changes: 3 additions & 0 deletions src/render/SDL_render.c
Expand Up @@ -49,6 +49,9 @@ static const SDL_RenderDriver *render_drivers[] = {
#if SDL_VIDEO_RENDER_D3D
&D3D_RenderDriver,
#endif
#if SDL_VIDEO_RENDER_D3D11
&D3D11_RenderDriver,
#endif
#if SDL_VIDEO_RENDER_OGL
&GL_RenderDriver,
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/stdlib/SDL_stdlib.c
Expand Up @@ -61,6 +61,8 @@ SDL_copysign(double x, double y)
{
#if defined(HAVE_COPYSIGN)
return copysign(x, y);
#elif defined(HAVE__COPYSIGN)
return _copysign(x, y);
#else
return SDL_uclibc_copysign(x, y);
#endif /* HAVE_COPYSIGN */
Expand Down Expand Up @@ -131,6 +133,8 @@ SDL_scalbn(double x, int n)
{
#if defined(HAVE_SCALBN)
return scalbn(x, n);
#elif defined(HAVE__SCALB)
return _scalb(x, n);
#else
return SDL_uclibc_scalbn(x, n);
#endif /* HAVE_SCALBN */
Expand Down
16 changes: 15 additions & 1 deletion src/thread/stdcpp/SDL_systhread.cpp
Expand Up @@ -24,8 +24,8 @@

extern "C" {
#include "SDL_thread.h"
#include "../SDL_systhread.h"
#include "../SDL_thread_c.h"
#include "../SDL_systhread.h"
#include "SDL_log.h"
}

Expand Down Expand Up @@ -121,4 +121,18 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
}
}

extern "C"
SDL_TLSData *
SDL_SYS_GetTLSData()
{
return SDL_Generic_GetTLSData();
}

extern "C"
int
SDL_SYS_SetTLSData(SDL_TLSData *data)
{
return SDL_Generic_SetTLSData(data);
}

/* vi: set ts=4 sw=4 expandtab: */
25 changes: 25 additions & 0 deletions src/timer/windows/SDL_systimer.c
Expand Up @@ -41,6 +41,7 @@ static LARGE_INTEGER hires_start_ticks;
static LARGE_INTEGER hires_ticks_per_second;
#endif

#ifndef __WINRT__
static void
timeSetPeriod(UINT uPeriod)
{
Expand Down Expand Up @@ -74,6 +75,7 @@ SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValu
timeSetPeriod(uPeriod);
}
}
#endif /* ifndef __WINRT__ */

void
SDL_StartTicks(void)
Expand All @@ -90,13 +92,19 @@ SDL_StartTicks(void)
QueryPerformanceCounter(&hires_start_ticks);
} else {
hires_timer_available = FALSE;
#ifdef __WINRT__
start = 0; /* the timer failed to start! */
#else
timeSetPeriod(1); /* use 1 ms timer precision */
start = timeGetTime();
#endif /* ifdef __WINRT__ */
}
#endif

#ifndef __WINRT__
SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
SDL_TimerResolutionChanged, NULL);
#endif
}

Uint32
Expand All @@ -119,7 +127,11 @@ SDL_GetTicks(void)

return (DWORD) hires_now.QuadPart;
} else {
#ifdef __WINRT__
now = 0;
#else
now = timeGetTime();
#endif // ifdef __WINRT__
}
#endif

Expand Down Expand Up @@ -148,6 +160,19 @@ SDL_GetPerformanceFrequency(void)
return frequency.QuadPart;
}

#ifdef __WINRT__
static void
Sleep(DWORD timeout)
{
static HANDLE mutex = 0;
if ( ! mutex )
{
mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
}
WaitForSingleObjectEx(mutex, timeout, FALSE);
}
#endif

void
SDL_Delay(Uint32 ms)
{
Expand Down
36 changes: 20 additions & 16 deletions src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -13,7 +13,7 @@ extern "C" {
#include "SDL_stdinc.h"
#include "SDL_render.h"
#include "../SDL_sysvideo.h"
#include "../../SDL_hints_c.h"
//#include "../../SDL_hints_c.h"
#include "../../events/scancodes_windows.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_keyboard_c.h"
Expand Down Expand Up @@ -86,7 +86,7 @@ __declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFu
return 0;
}

static void WINRT_SetDisplayOrientationsPreference(const char *name, const char *oldValue, const char *newValue)
static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
{
SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);

Expand Down Expand Up @@ -163,8 +163,8 @@ void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
// otherwise the hint callback won't get registered.
//
// WinRT, TODO: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown");
SDL_RegisterHintChangedCb(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference);
//SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight Portrait PortraitUpsideDown"); // DavidL: this is no longer needed (for SDL_AddHintCallback)
SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
}

void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
Expand Down Expand Up @@ -316,15 +316,19 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven
// Windows device.
//
// Commencing hack in 3... 2... 1...
SDL_Renderer * rendererForMainWindow = SDL_GetRenderer(m_sdlWindowData->sdlWindow);
//
// UPDATE, SDL 2.0.0 update: the 'resized' flag is now gone. This
// hack might not be necessary any more.
//
//SDL_Renderer * rendererForMainWindow = SDL_GetRenderer(m_sdlWindowData->sdlWindow);
// For now, limit the hack to when the Direct3D 11.1 is getting used:
const bool usingD3D11Renderer = \
(rendererForMainWindow != NULL) &&
(SDL_strcmp(rendererForMainWindow->info.name, "direct3d 11.1") == 0);
SDL_bool wasD3D11RendererResized = SDL_FALSE;
if (usingD3D11Renderer) {
wasD3D11RendererResized = rendererForMainWindow->resized;
}
//const bool usingD3D11Renderer = \
// (rendererForMainWindow != NULL) &&
// (SDL_strcmp(rendererForMainWindow->info.name, "direct3d 11.1") == 0);
//SDL_bool wasD3D11RendererResized = SDL_FALSE;
//if (usingD3D11Renderer) {
// wasD3D11RendererResized = rendererForMainWindow->resized;
//}

// Send the window-resize event to the rest of SDL, and to apps:
const int windowWidth = (int) ceil(args->Size.Width);
Expand All @@ -335,10 +339,10 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven
windowWidth,
windowHeight);

// Viewport hack, part two:
if (usingD3D11Renderer) {
rendererForMainWindow->resized = wasD3D11RendererResized;
}
//// Viewport hack, part two:
//if (usingD3D11Renderer) {
// rendererForMainWindow->resized = wasD3D11RendererResized;
//}
}
}

Expand Down

0 comments on commit d41fdc9

Please sign in to comment.