WinRT: got timers working
authorDavid Ludwig <dludwig@pobox.com>
Sat, 24 Nov 2012 12:07:35 -0500
changeset 8364ba0d913b6459
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
     1.1 --- a/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Sat Nov 24 11:46:15 2012 -0500
     1.2 +++ b/VisualC/SDL/SDL_VS2012_WinRT.vcxproj	Sat Nov 24 12:07:35 2012 -0500
     1.3 @@ -94,8 +94,8 @@
     1.4      <ClCompile Include="..\..\src\thread\stdcpp\SDL_syscond.cpp" />
     1.5      <ClCompile Include="..\..\src\thread\stdcpp\SDL_sysmutex.cpp" />
     1.6      <ClCompile Include="..\..\src\thread\stdcpp\SDL_systhread.cpp" />
     1.7 -    <ClCompile Include="..\..\src\timer\dummy\SDL_systimer.c" />
     1.8      <ClCompile Include="..\..\src\timer\SDL_timer.c" />
     1.9 +    <ClCompile Include="..\..\src\timer\windows\SDL_systimer.c" />
    1.10      <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
    1.11      <ClCompile Include="..\..\src\video\dummy\SDL_nullframebuffer.c" />
    1.12      <ClCompile Include="..\..\src\video\dummy\SDL_nullvideo.c" />
     2.1 --- a/include/SDL_config_windowsrt.h	Sat Nov 24 11:46:15 2012 -0500
     2.2 +++ b/include/SDL_config_windowsrt.h	Sat Nov 24 12:07:35 2012 -0500
     2.3 @@ -154,10 +154,7 @@
     2.4  #define SDL_THREAD_STDCPP   1
     2.5  
     2.6  /* Enable various timer systems */
     2.7 -// TODO, WinRT: look into getting SDL's pre-WinRT timers working.
     2.8 -// Some functions there are supported in WinRT, others are not.
     2.9 -//#define SDL_TIMER_WINDOWS	1
    2.10 -#define SDL_TIMERS_DISABLED	1
    2.11 +#define SDL_TIMER_WINDOWS	1
    2.12  
    2.13  /* Enable various video drivers */
    2.14  #define SDL_VIDEO_DRIVER_WINRT	1
     3.1 --- a/src/timer/windows/SDL_systimer.c	Sat Nov 24 11:46:15 2012 -0500
     3.2 +++ b/src/timer/windows/SDL_systimer.c	Sat Nov 24 12:07:35 2012 -0500
     3.3 @@ -48,7 +48,7 @@
     3.4  #ifdef USE_GETTICKCOUNT
     3.5      start = GetTickCount();
     3.6  #else
     3.7 -#if 0                           /* Apparently there are problems with QPC on Win2K */
     3.8 +#ifdef __WINRT__      /* Apparently there are problems with QPC on Win2K */
     3.9      if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
    3.10          hires_timer_available = TRUE;
    3.11          QueryPerformanceCounter(&hires_start_ticks);
    3.12 @@ -56,8 +56,12 @@
    3.13  #endif
    3.14      {
    3.15          hires_timer_available = FALSE;
    3.16 +#ifdef __WINRT__
    3.17 +        start = 0;              /* the timer failed to start! */
    3.18 +#else
    3.19          timeBeginPeriod(1);     /* use 1 ms timer precision */
    3.20          start = timeGetTime();
    3.21 +#endif
    3.22      }
    3.23  #endif
    3.24  }
    3.25 @@ -82,7 +86,11 @@
    3.26  
    3.27          return (DWORD) hires_now.QuadPart;
    3.28      } else {
    3.29 +#ifdef __WINRT__
    3.30 +        now = 0;
    3.31 +#else
    3.32          now = timeGetTime();
    3.33 +#endif
    3.34      }
    3.35  #endif
    3.36  
    3.37 @@ -116,6 +124,19 @@
    3.38      return frequency.QuadPart;
    3.39  }
    3.40  
    3.41 +#ifdef __WINRT__
    3.42 +static void
    3.43 +Sleep(DWORD timeout)
    3.44 +{
    3.45 +    static HANDLE mutex = 0;
    3.46 +    if ( ! mutex )
    3.47 +    {
    3.48 +        mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
    3.49 +    }
    3.50 +    WaitForSingleObjectEx(mutex, timeout, FALSE);
    3.51 +}
    3.52 +#endif
    3.53 +
    3.54  void
    3.55  SDL_Delay(Uint32 ms)
    3.56  {