Mercurial > sdl-ios-xcode
annotate src/timer/wince/SDL_systimer.c @ 2960:91708bc14aab
It's probably not worth pushing palettized textures. The memory optimization
isn't worth the effort on modern hardware with the sorts of games that would
be using the SDL 1.3 texture API.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 02 Jan 2009 09:27:36 +0000 |
parents | 99210400e8b9 |
children | f7b03b6838cb |
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 |
2859 | 3 Copyright (C) 1997-2009 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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
37 static Uint64 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
43 static Uint64 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
46 union |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
47 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
48 FILETIME ftime; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
49 Uint64 itime; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
50 } ftime; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
53 GetSystemTime(&stime); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
54 SystemTimeToFileTime(&stime, &ftime.ftime); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
55 ftime.itime /= 10000; // Convert 100ns intervals to 1ms intervals |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
56 // Remove ms portion, which can't be relied on |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
57 ftime.itime -= (ftime.itime % 1000); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
61 static Sint32 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
67 static Sint32 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
74 Uint32 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
77 Sint32 offset = wce_rel_date() - wce_rel_ticks(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
80 start_ticks -= offset; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
87 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
94 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
97 start_date = wce_date(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
108 DWORD |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
111 while (WaitForSingleObject(timersQuitEvent, 10) == WAIT_TIMEOUT) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
112 SDL_ThreadedTimerCheck(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
113 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
117 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
120 // create a thread to process a threaded timers |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
121 // SetTimer does not suit the needs because |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
124 timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
125 if (!timersQuitEvent) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
126 SDL_SetError("Cannot create event for timers thread"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
127 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
128 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
129 timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
130 if (!timersThread) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
131 SDL_SetError |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
132 ("Cannot create timers thread, check amount of RAM available"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
133 return -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
134 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
140 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
143 SetEvent(timersQuitEvent); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
144 if (WaitForSingleObject(timersThread, 2000) == WAIT_TIMEOUT) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
145 TerminateThread(timersThread, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
146 CloseHandle(timersThread); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
147 CloseHandle(timersQuitEvent); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
158 static void CALLBACK |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
165 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
170 /* Set timer resolution */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
171 result = timeBeginPeriod(TIMER_RESOLUTION); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
172 if (result != TIMERR_NOERROR) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
173 SDL_SetError("Warning: Can't set %d ms timer resolution", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
174 TIMER_RESOLUTION); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
175 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
176 /* Allow 10 ms of drift so we don't chew on CPU */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
177 timerID = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
178 timeSetEvent(TIMER_RESOLUTION, 1, HandleAlarm, 0, TIME_PERIODIC); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
179 if (!timerID) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
180 SDL_SetError("timeSetEvent() failed"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
181 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
182 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
186 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
189 if (timerID) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
190 timeKillEvent(timerID); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
191 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
197 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
200 SDL_SetError("Internal logic error: WinCE uses threaded timer"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
204 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
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 */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
211 /* vi: set ts=4 sw=4 expandtab: */ |