annotate 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
rev   line source
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
6 modify it under the terms of the GNU Lesser General Public
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
13 Lesser General Public License for more details.
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1180
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@libsdl.org
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
1433
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
24 #define WIN32_LEAN_AND_MEAN
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
25 #include <windows.h>
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #include <mmsystem.h>
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
28 #include "SDL_thread.h"
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #include "SDL_timer.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
30 #include "../SDL_timer_c.h"
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 static Uint64 start_date;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 static Uint64 start_ticks;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 static Uint64 wce_ticks(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 return((Uint64)GetTickCount());
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 static Uint64 wce_date(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 union
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 FILETIME ftime;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 Uint64 itime;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 } ftime;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 SYSTEMTIME stime;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 GetSystemTime(&stime);
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 SystemTimeToFileTime(&stime,&ftime.ftime);
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 ftime.itime/=10000; // Convert 100ns intervals to 1ms intervals
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 // Remove ms portion, which can't be relied on
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 ftime.itime -= (ftime.itime % 1000);
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 return(ftime.itime);
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 static Sint32 wce_rel_ticks(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 return((Sint32)(wce_ticks()-start_ticks));
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 static Sint32 wce_rel_date(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 return((Sint32)(wce_date()-start_date));
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 /* Return time in ms relative to when SDL was started */
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 Uint32 SDL_GetTicks()
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 Sint32 offset=wce_rel_date()-wce_rel_ticks();
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 if((offset < -1000) || (offset > 1000))
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 // fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000);
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 start_ticks-=offset;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 return((Uint32)wce_rel_ticks());
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 /* Give up approx. givem milliseconds to the OS. */
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 void SDL_Delay(Uint32 ms)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 Sleep(ms);
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 /* Recard start-time of application for reference */
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 void SDL_StartTicks(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 {
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 start_date=wce_date();
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 start_ticks=wce_ticks();
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 static UINT WIN_timer;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
95 #if ( _WIN32_WCE <= 420 )
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
96
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
97 static HANDLE timersThread = 0;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
98 static HANDLE timersQuitEvent = 0;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
99
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
100 DWORD TimersThreadProc(void *data)
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
101 {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
102 while(WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT)
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
103 {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
104 SDL_ThreadedTimerCheck();
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
105 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
106 return 0;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
107 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
108
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 int SDL_SYS_TimerInit(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 {
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
111 // create a thread to process a threaded timers
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
112 // SetTimer does not suit the needs because
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
113 // TimerCallbackProc will be called only when WM_TIMER occured
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
114
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
115 timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
116 if( !timersQuitEvent )
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
117 {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
118 SDL_SetError("Cannot create event for timers thread");
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
119 return -1;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
120 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
121 timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
122 if( !timersThread )
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
123 {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
124 SDL_SetError("Cannot create timers thread, check amount of RAM available");
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
125 return -1;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
126 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
127 SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
128
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
129 return(SDL_SetTimerThreaded(1));
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 void SDL_SYS_TimerQuit(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 {
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
134 SetEvent(timersQuitEvent);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
135 if( WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT )
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
136 TerminateThread(timersThread, 0);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
137 CloseHandle(timersThread);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
138 CloseHandle(timersQuitEvent);
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 return;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
142 #else
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
143
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
144 #pragma comment(lib, "mmtimer.lib")
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
145
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
146 /* Data to handle a single periodic alarm */
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
147 static UINT timerID = 0;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
149 static void CALLBACK HandleAlarm(UINT uID, UINT uMsg, DWORD dwUser,
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
150 DWORD dw1, DWORD dw2)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 {
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
152 SDL_ThreadedTimerCheck();
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
153 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
154
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
155
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
156 int SDL_SYS_TimerInit(void)
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
157 {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
158 MMRESULT result;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
160 /* Set timer resolution */
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
161 result = timeBeginPeriod(TIMER_RESOLUTION);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
162 if ( result != TIMERR_NOERROR ) {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
163 SDL_SetError("Warning: Can't set %d ms timer resolution",
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
164 TIMER_RESOLUTION);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
165 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
166 /* Allow 10 ms of drift so we don't chew on CPU */
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
167 timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
168 if ( ! timerID ) {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
169 SDL_SetError("timeSetEvent() failed");
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
170 return(-1);
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 }
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
172 return(SDL_SetTimerThreaded(1));
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
175 void SDL_SYS_TimerQuit(void)
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
176 {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
177 if ( timerID ) {
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
178 timeKillEvent(timerID);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
179 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
180 timeEndPeriod(TIMER_RESOLUTION);
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
181 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
182
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
183 #endif
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
184
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 int SDL_SYS_StartTimer(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 {
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
187 SDL_SetError("Internal logic error: WinCE uses threaded timer");
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
188 return(-1);
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 void SDL_SYS_StopTimer(void)
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 {
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
193 return;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 }