annotate src/timer/wince/SDL_systimer.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 92947e3a18db
children 4da1ee79c9af
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
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1497
diff changeset
24 #ifdef SDL_TIMER_WINCE
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1497
diff changeset
25
1433
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
26 #define WIN32_LEAN_AND_MEAN
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
27 #include <windows.h>
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #include <mmsystem.h>
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
30 #include "SDL_thread.h"
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #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
32 #include "../SDL_timer_c.h"
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 static Uint64 start_date;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 static Uint64 start_ticks;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
37 static Uint64
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
38 wce_ticks (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
40 return ((Uint64) GetTickCount ());
1180
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
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
43 static Uint64
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
44 wce_date (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
46 union
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
47 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
48 FILETIME ftime;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
49 Uint64 itime;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
50 } ftime;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
51 SYSTEMTIME stime;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
53 GetSystemTime (&stime);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
54 SystemTimeToFileTime (&stime, &ftime.ftime);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
55 ftime.itime /= 10000; // Convert 100ns intervals to 1ms intervals
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
56 // Remove ms portion, which can't be relied on
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
57 ftime.itime -= (ftime.itime % 1000);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
58 return (ftime.itime);
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
61 static Sint32
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
62 wce_rel_ticks (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
64 return ((Sint32) (wce_ticks () - start_ticks));
1180
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
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
67 static Sint32
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
68 wce_rel_date (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
70 return ((Sint32) (wce_date () - start_date));
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 }
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 /* Return time in ms relative to when SDL was started */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
74 Uint32
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
75 SDL_GetTicks ()
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
77 Sint32 offset = wce_rel_date () - wce_rel_ticks ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
78 if ((offset < -1000) || (offset > 1000)) {
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 // fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
80 start_ticks -= offset;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
81 }
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
83 return ((Uint32) wce_rel_ticks ());
1180
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 /* Give up approx. givem milliseconds to the OS. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
87 void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
88 SDL_Delay (Uint32 ms)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
90 Sleep (ms);
1180
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 /* Recard start-time of application for reference */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
94 void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
95 SDL_StartTicks (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
97 start_date = wce_date ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
98 start_ticks = wce_ticks ();
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 static UINT WIN_timer;
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
103 #if ( _WIN32_WCE <= 420 )
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
104
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
105 static HANDLE timersThread = 0;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
106 static HANDLE timersQuitEvent = 0;
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
107
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
108 DWORD
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
109 TimersThreadProc (void *data)
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
110 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
111 while (WaitForSingleObject (timersQuitEvent, 10) == WAIT_TIMEOUT) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
112 SDL_ThreadedTimerCheck ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
113 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
114 return 0;
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
115 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
116
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
117 int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
118 SDL_SYS_TimerInit (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
120 // create a thread to process a threaded timers
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
121 // SetTimer does not suit the needs because
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
122 // TimerCallbackProc will be called only when WM_TIMER occured
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
123
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
124 timersQuitEvent = CreateEvent (0, TRUE, FALSE, 0);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
125 if (!timersQuitEvent) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
126 SDL_SetError ("Cannot create event for timers thread");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
127 return -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
128 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
129 timersThread = CreateThread (NULL, 0, TimersThreadProc, 0, 0, 0);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
130 if (!timersThread) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
131 SDL_SetError
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
132 ("Cannot create timers thread, check amount of RAM available");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
133 return -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
134 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
135 SetThreadPriority (timersThread, THREAD_PRIORITY_HIGHEST);
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
136
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
137 return (SDL_SetTimerThreaded (1));
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
140 void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
141 SDL_SYS_TimerQuit (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
143 SetEvent (timersQuitEvent);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
144 if (WaitForSingleObject (timersThread, 2000) == WAIT_TIMEOUT)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
145 TerminateThread (timersThread, 0);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
146 CloseHandle (timersThread);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
147 CloseHandle (timersQuitEvent);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
148 return;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
151 #else
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
152
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
153 #pragma comment(lib, "mmtimer.lib")
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 /* Data to handle a single periodic alarm */
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
156 static UINT timerID = 0;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
158 static void CALLBACK
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
159 HandleAlarm (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
161 SDL_ThreadedTimerCheck ();
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
162 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
163
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
164
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
165 int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
166 SDL_SYS_TimerInit (void)
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
167 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
168 MMRESULT result;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
170 /* Set timer resolution */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
171 result = timeBeginPeriod (TIMER_RESOLUTION);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
172 if (result != TIMERR_NOERROR) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
173 SDL_SetError ("Warning: Can't set %d ms timer resolution",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
174 TIMER_RESOLUTION);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
175 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
176 /* Allow 10 ms of drift so we don't chew on CPU */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
177 timerID =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
178 timeSetEvent (TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
179 if (!timerID) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
180 SDL_SetError ("timeSetEvent() failed");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
181 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
182 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
183 return (SDL_SetTimerThreaded (1));
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
186 void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
187 SDL_SYS_TimerQuit (void)
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
188 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
189 if (timerID) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
190 timeKillEvent (timerID);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
191 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
192 timeEndPeriod (TIMER_RESOLUTION);
1497
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
193 }
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
194
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
195 #endif
420b3f47806d Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
196
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
197 int
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
198 SDL_SYS_StartTimer (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
200 SDL_SetError ("Internal logic error: WinCE uses threaded timer");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
201 return (-1);
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 }
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
204 void
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
205 SDL_SYS_StopTimer (void)
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
207 return;
1180
bdcb8bb4c831 From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 }
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1497
diff changeset
209
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1497
diff changeset
210 #endif /* SDL_TIMER_WINCE */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
211 /* vi: set ts=4 sw=4 expandtab: */