Mercurial > sdl-ios-xcode
comparison src/timer/win32/SDL_systimer.c @ 89:69b8fac3e1c0
Added Holger Schemel's fix for SDL_GetTicks() on W2K
This adds QueryPerformanceCounter() support, which is probably a good thing.
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Sat, 07 Jul 2001 08:03:34 +0000 |
parents | 74212992fb08 |
children | e8157fcb3114 |
comparison
equal
deleted
inserted
replaced
88:71774090f286 | 89:69b8fac3e1c0 |
---|---|
37 #define USE_SETTIMER | 37 #define USE_SETTIMER |
38 #endif | 38 #endif |
39 | 39 |
40 #define TIME_WRAP_VALUE (~(DWORD)0) | 40 #define TIME_WRAP_VALUE (~(DWORD)0) |
41 | 41 |
42 /* The first ticks value of the application */ | 42 /* The first (low-resolution) ticks value of the application */ |
43 static DWORD start; | 43 static DWORD start; |
44 | |
45 #ifndef USE_GETTICKCOUNT | |
46 /* Store if a high-resolution performance counter exists on the system */ | |
47 static BOOL hires_timer_available; | |
48 /* The first high-resolution ticks value of the application */ | |
49 static LARGE_INTEGER hires_start_ticks; | |
50 /* The number of ticks per second of the high-resolution performance counter */ | |
51 static LARGE_INTEGER hires_ticks_per_second; | |
52 #endif | |
44 | 53 |
45 void SDL_StartTicks(void) | 54 void SDL_StartTicks(void) |
46 { | 55 { |
47 /* Set first ticks value */ | 56 /* Set first ticks value */ |
48 #ifdef USE_GETTICKCOUNT | 57 #ifdef USE_GETTICKCOUNT |
49 start = GetTickCount(); | 58 start = GetTickCount(); |
50 #else | 59 #else |
51 start = timeGetTime(); | 60 if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) |
61 { | |
62 hires_timer_available = TRUE; | |
63 QueryPerformanceCounter(&hires_start_ticks); | |
64 } | |
65 else | |
66 { | |
67 hires_timer_available = FALSE; | |
68 timeBeginPeriod(1); /* use 1 ms timer precision */ | |
69 start = timeGetTime(); | |
70 } | |
52 #endif | 71 #endif |
53 } | 72 } |
54 | 73 |
55 Uint32 SDL_GetTicks(void) | 74 Uint32 SDL_GetTicks(void) |
56 { | 75 { |
57 DWORD now, ticks; | 76 DWORD now, ticks; |
77 #ifndef USE_GETTICKCOUNT | |
78 LARGE_INTEGER hires_now; | |
79 #endif | |
58 | 80 |
59 #ifdef USE_GETTICKCOUNT | 81 #ifdef USE_GETTICKCOUNT |
60 now = GetTickCount(); | 82 now = GetTickCount(); |
61 #else | 83 #else |
62 now = timeGetTime(); | 84 if (hires_timer_available) |
63 #endif | 85 { |
86 QueryPerformanceCounter(&hires_now); | |
87 | |
88 hires_now.QuadPart -= hires_start_ticks.QuadPart; | |
89 hires_now.QuadPart *= 1000; | |
90 hires_now.QuadPart /= hires_ticks_per_second.QuadPart; | |
91 | |
92 return (DWORD)hires_now.QuadPart; | |
93 } | |
94 else | |
95 { | |
96 now = timeGetTime(); | |
97 } | |
98 #endif | |
99 | |
64 if ( now < start ) { | 100 if ( now < start ) { |
65 ticks = (TIME_WRAP_VALUE-start) + now; | 101 ticks = (TIME_WRAP_VALUE-start) + now; |
66 } else { | 102 } else { |
67 ticks = (now - start); | 103 ticks = (now - start); |
68 } | 104 } |