WinRT: got timers working
authorDavid Ludwig <dludwig@pobox.com>
Sat, 24 Nov 2012 12:07:35 -0500
changeset 8364 ba0d913b6459
parent 8363 35a4405157ab
child 8365 83e5a0c5f77b
WinRT: got timers working
VisualC/SDL/SDL_VS2012_WinRT.vcxproj
include/SDL_config_windowsrt.h
src/timer/windows/SDL_systimer.c
--- a/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Sat Nov 24 11:46:15 2012 -0500
+++ b/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Sat Nov 24 12:07:35 2012 -0500
@@ -94,8 +94,8 @@
     <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp" />
     <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp" />
     <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp" />
-    <ClCompile Include="..\..\src\timer\dummy\SDL_systimer.c" />
     <ClCompile Include="..\..\src\timer\SDL_timer.c" />
+    <ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
     <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
     <ClCompile Include="..\..\src\video\dummy\SDL_nullframebuffer.c" />
     <ClCompile Include="..\..\src\video\dummy\SDL_nullvideo.c" />
--- a/include/SDL_config_windowsrt.h	Sat Nov 24 11:46:15 2012 -0500
+++ b/include/SDL_config_windowsrt.h	Sat Nov 24 12:07:35 2012 -0500
@@ -154,10 +154,7 @@
 #define SDL_THREAD_STDCPP   1
 
 /* Enable various timer systems */
-// TODO, WinRT: look into getting SDL's pre-WinRT timers working.
-// Some functions there are supported in WinRT, others are not.
-//#define SDL_TIMER_WINDOWS	1
-#define SDL_TIMERS_DISABLED	1
+#define SDL_TIMER_WINDOWS	1
 
 /* Enable various video drivers */
 #define SDL_VIDEO_DRIVER_WINRT	1
--- a/src/timer/windows/SDL_systimer.c	Sat Nov 24 11:46:15 2012 -0500
+++ b/src/timer/windows/SDL_systimer.c	Sat Nov 24 12:07:35 2012 -0500
@@ -48,7 +48,7 @@
 #ifdef USE_GETTICKCOUNT
     start = GetTickCount();
 #else
-#if 0                           /* Apparently there are problems with QPC on Win2K */
+#ifdef __WINRT__      /* Apparently there are problems with QPC on Win2K */
     if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
         hires_timer_available = TRUE;
         QueryPerformanceCounter(&hires_start_ticks);
@@ -56,8 +56,12 @@
 #endif
     {
         hires_timer_available = FALSE;
+#ifdef __WINRT__
+        start = 0;              /* the timer failed to start! */
+#else
         timeBeginPeriod(1);     /* use 1 ms timer precision */
         start = timeGetTime();
+#endif
     }
 #endif
 }
@@ -82,7 +86,11 @@
 
         return (DWORD) hires_now.QuadPart;
     } else {
+#ifdef __WINRT__
+        now = 0;
+#else
         now = timeGetTime();
+#endif
     }
 #endif
 
@@ -116,6 +124,19 @@
     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)
 {