comparison src/timer/win32/SDL_systimer.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
47 /* The number of ticks per second of the high-resolution performance counter */ 47 /* The number of ticks per second of the high-resolution performance counter */
48 static LARGE_INTEGER hires_ticks_per_second; 48 static LARGE_INTEGER hires_ticks_per_second;
49 #endif 49 #endif
50 50
51 void 51 void
52 SDL_StartTicks (void) 52 SDL_StartTicks(void)
53 { 53 {
54 /* Set first ticks value */ 54 /* Set first ticks value */
55 #ifdef USE_GETTICKCOUNT 55 #ifdef USE_GETTICKCOUNT
56 start = GetTickCount (); 56 start = GetTickCount();
57 #else 57 #else
58 #if 0 /* Apparently there are problems with QPC on Win2K */ 58 #if 0 /* Apparently there are problems with QPC on Win2K */
59 if (QueryPerformanceFrequency (&hires_ticks_per_second) == TRUE) { 59 if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
60 hires_timer_available = TRUE; 60 hires_timer_available = TRUE;
61 QueryPerformanceCounter (&hires_start_ticks); 61 QueryPerformanceCounter(&hires_start_ticks);
62 } else 62 } else
63 #endif 63 #endif
64 { 64 {
65 hires_timer_available = FALSE; 65 hires_timer_available = FALSE;
66 timeBeginPeriod (1); /* use 1 ms timer precision */ 66 timeBeginPeriod(1); /* use 1 ms timer precision */
67 start = timeGetTime (); 67 start = timeGetTime();
68 } 68 }
69 #endif 69 #endif
70 } 70 }
71 71
72 Uint32 72 Uint32
73 SDL_GetTicks (void) 73 SDL_GetTicks(void)
74 { 74 {
75 DWORD now, ticks; 75 DWORD now, ticks;
76 #ifndef USE_GETTICKCOUNT 76 #ifndef USE_GETTICKCOUNT
77 LARGE_INTEGER hires_now; 77 LARGE_INTEGER hires_now;
78 #endif 78 #endif
79 79
80 #ifdef USE_GETTICKCOUNT 80 #ifdef USE_GETTICKCOUNT
81 now = GetTickCount (); 81 now = GetTickCount();
82 #else 82 #else
83 if (hires_timer_available) { 83 if (hires_timer_available) {
84 QueryPerformanceCounter (&hires_now); 84 QueryPerformanceCounter(&hires_now);
85 85
86 hires_now.QuadPart -= hires_start_ticks.QuadPart; 86 hires_now.QuadPart -= hires_start_ticks.QuadPart;
87 hires_now.QuadPart *= 1000; 87 hires_now.QuadPart *= 1000;
88 hires_now.QuadPart /= hires_ticks_per_second.QuadPart; 88 hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
89 89
90 return (DWORD) hires_now.QuadPart; 90 return (DWORD) hires_now.QuadPart;
91 } else { 91 } else {
92 now = timeGetTime (); 92 now = timeGetTime();
93 } 93 }
94 #endif 94 #endif
95 95
96 if (now < start) { 96 if (now < start) {
97 ticks = (TIME_WRAP_VALUE - start) + now; 97 ticks = (TIME_WRAP_VALUE - start) + now;
100 } 100 }
101 return (ticks); 101 return (ticks);
102 } 102 }
103 103
104 void 104 void
105 SDL_Delay (Uint32 ms) 105 SDL_Delay(Uint32 ms)
106 { 106 {
107 Sleep (ms); 107 Sleep(ms);
108 } 108 }
109 109
110 /* Data to handle a single periodic alarm */ 110 /* Data to handle a single periodic alarm */
111 static UINT timerID = 0; 111 static UINT timerID = 0;
112 112
113 static void CALLBACK 113 static void CALLBACK
114 HandleAlarm (UINT uID, UINT uMsg, DWORD_PTR dwUser, 114 HandleAlarm(UINT uID, UINT uMsg, DWORD_PTR dwUser,
115 DWORD_PTR dw1, DWORD_PTR dw2) 115 DWORD_PTR dw1, DWORD_PTR dw2)
116 { 116 {
117 SDL_ThreadedTimerCheck (); 117 SDL_ThreadedTimerCheck();
118 } 118 }
119 119
120 120
121 int 121 int
122 SDL_SYS_TimerInit (void) 122 SDL_SYS_TimerInit(void)
123 { 123 {
124 MMRESULT result; 124 MMRESULT result;
125 125
126 /* Set timer resolution */ 126 /* Set timer resolution */
127 result = timeBeginPeriod (TIMER_RESOLUTION); 127 result = timeBeginPeriod(TIMER_RESOLUTION);
128 if (result != TIMERR_NOERROR) { 128 if (result != TIMERR_NOERROR) {
129 SDL_SetError ("Warning: Can't set %d ms timer resolution", 129 SDL_SetError("Warning: Can't set %d ms timer resolution",
130 TIMER_RESOLUTION); 130 TIMER_RESOLUTION);
131 } 131 }
132 /* Allow 10 ms of drift so we don't chew on CPU */ 132 /* Allow 10 ms of drift so we don't chew on CPU */
133 timerID = 133 timerID =
134 timeSetEvent (TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); 134 timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC);
135 if (!timerID) { 135 if (!timerID) {
136 SDL_SetError ("timeSetEvent() failed"); 136 SDL_SetError("timeSetEvent() failed");
137 return (-1); 137 return (-1);
138 } 138 }
139 return (SDL_SetTimerThreaded (1)); 139 return (SDL_SetTimerThreaded(1));
140 } 140 }
141 141
142 void 142 void
143 SDL_SYS_TimerQuit (void) 143 SDL_SYS_TimerQuit(void)
144 { 144 {
145 if (timerID) { 145 if (timerID) {
146 timeKillEvent (timerID); 146 timeKillEvent(timerID);
147 } 147 }
148 timeEndPeriod (TIMER_RESOLUTION); 148 timeEndPeriod(TIMER_RESOLUTION);
149 } 149 }
150 150
151 int 151 int
152 SDL_SYS_StartTimer (void) 152 SDL_SYS_StartTimer(void)
153 { 153 {
154 SDL_SetError ("Internal logic error: Win32 uses threaded timer"); 154 SDL_SetError("Internal logic error: Win32 uses threaded timer");
155 return (-1); 155 return (-1);
156 } 156 }
157 157
158 void 158 void
159 SDL_SYS_StopTimer (void) 159 SDL_SYS_StopTimer(void)
160 { 160 {
161 return; 161 return;
162 } 162 }
163 163
164 #endif /* SDL_TIMER_WIN32 */ 164 #endif /* SDL_TIMER_WIN32 */