comparison src/timer/wince/SDL_systimer.c @ 1497:420b3f47806d

Fixes from Dmitry Yakimov: fixed bugs 159 and 160: + added threaded timers support ! fixed restoring sdl window focus (AV in windows message handler) ! disabled forgotten cdrom and joystick in config file. * disabled minimizing sdl window while loosing focus. PocketPC does not have a task bar, so it is an inconvenient and unusual behaviour for PPC users. + added WIN_Paint handler for GAPI ! fixed loosing focus while using GAPI videi driver + added TestTimer project * removed unnecessary macros (ENABLE_WINDIB ...) from projects
author Sam Lantinga <slouken@libsdl.org>
date Sat, 11 Mar 2006 23:46:45 +0000
parents bb6839704ed6
children 92947e3a18db
comparison
equal deleted inserted replaced
1496:405e20dc004c 1497:420b3f47806d
23 23
24 #define WIN32_LEAN_AND_MEAN 24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h> 25 #include <windows.h>
26 #include <mmsystem.h> 26 #include <mmsystem.h>
27 27
28 #include "SDL_thread.h"
28 #include "SDL_timer.h" 29 #include "SDL_timer.h"
29 #include "../SDL_timer_c.h" 30 #include "../SDL_timer_c.h"
30 31
31 static Uint64 start_date; 32 static Uint64 start_date;
32 static Uint64 start_ticks; 33 static Uint64 start_ticks;
89 start_ticks=wce_ticks(); 90 start_ticks=wce_ticks();
90 } 91 }
91 92
92 static UINT WIN_timer; 93 static UINT WIN_timer;
93 94
95 #if ( _WIN32_WCE <= 420 )
96
97 static HANDLE timersThread = 0;
98 static HANDLE timersQuitEvent = 0;
99
100 DWORD TimersThreadProc(void *data)
101 {
102 while(WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT)
103 {
104 SDL_ThreadedTimerCheck();
105 }
106 return 0;
107 }
108
94 int SDL_SYS_TimerInit(void) 109 int SDL_SYS_TimerInit(void)
95 { 110 {
96 return(0); 111 // create a thread to process a threaded timers
112 // SetTimer does not suit the needs because
113 // TimerCallbackProc will be called only when WM_TIMER occured
114
115 timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0);
116 if( !timersQuitEvent )
117 {
118 SDL_SetError("Cannot create event for timers thread");
119 return -1;
120 }
121 timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0);
122 if( !timersThread )
123 {
124 SDL_SetError("Cannot create timers thread, check amount of RAM available");
125 return -1;
126 }
127 SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST);
128
129 return(SDL_SetTimerThreaded(1));
97 } 130 }
98 131
99 void SDL_SYS_TimerQuit(void) 132 void SDL_SYS_TimerQuit(void)
100 { 133 {
134 SetEvent(timersQuitEvent);
135 if( WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT )
136 TerminateThread(timersThread, 0);
137 CloseHandle(timersThread);
138 CloseHandle(timersQuitEvent);
101 return; 139 return;
102 } 140 }
103 141
104 /* Forward declaration because this is called by the timer callback */ 142 #else
105 int SDL_SYS_StartTimer(void);
106 143
107 static VOID CALLBACK TimerCallbackProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime) 144 #pragma comment(lib, "mmtimer.lib")
145
146 /* Data to handle a single periodic alarm */
147 static UINT timerID = 0;
148
149 static void CALLBACK HandleAlarm(UINT uID, UINT uMsg, DWORD dwUser,
150 DWORD dw1, DWORD dw2)
108 { 151 {
109 Uint32 ms; 152 SDL_ThreadedTimerCheck();
153 }
110 154
111 ms = SDL_alarm_callback(SDL_alarm_interval); 155
112 if ( ms != SDL_alarm_interval ) { 156 int SDL_SYS_TimerInit(void)
113 KillTimer(NULL, idEvent); 157 {
114 if ( ms ) { 158 MMRESULT result;
115 SDL_alarm_interval = ROUND_RESOLUTION(ms); 159
116 SDL_SYS_StartTimer(); 160 /* Set timer resolution */
117 } else { 161 result = timeBeginPeriod(TIMER_RESOLUTION);
118 SDL_alarm_interval = 0; 162 if ( result != TIMERR_NOERROR ) {
119 } 163 SDL_SetError("Warning: Can't set %d ms timer resolution",
164 TIMER_RESOLUTION);
120 } 165 }
166 /* Allow 10 ms of drift so we don't chew on CPU */
167 timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC);
168 if ( ! timerID ) {
169 SDL_SetError("timeSetEvent() failed");
170 return(-1);
171 }
172 return(SDL_SetTimerThreaded(1));
121 } 173 }
174
175 void SDL_SYS_TimerQuit(void)
176 {
177 if ( timerID ) {
178 timeKillEvent(timerID);
179 }
180 timeEndPeriod(TIMER_RESOLUTION);
181 }
182
183 #endif
122 184
123 int SDL_SYS_StartTimer(void) 185 int SDL_SYS_StartTimer(void)
124 { 186 {
125 int retval; 187 SDL_SetError("Internal logic error: WinCE uses threaded timer");
126 188 return(-1);
127 WIN_timer = SetTimer(NULL, 0, SDL_alarm_interval, TimerCallbackProc);
128 if ( WIN_timer ) {
129 retval = 0;
130 } else {
131 retval = -1;
132 }
133 return retval;
134 } 189 }
135 190
136 void SDL_SYS_StopTimer(void) 191 void SDL_SYS_StopTimer(void)
137 { 192 {
138 if ( WIN_timer ) { 193 return;
139 KillTimer(NULL, WIN_timer);
140 WIN_timer = 0;
141 }
142 } 194 }
143