Mercurial > sdl-ios-xcode
annotate src/timer/wince/SDL_systimer.c @ 5204:523409574510
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
This compiles, but it untested.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 06 Feb 2011 00:00:13 -0800 |
parents | 481dabb098ef |
children | b530ef003506 |
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 |
3697 | 3 Copyright (C) 1997-2010 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 |
5092
327f181542f1
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
26 #include "../../core/windows/SDL_windows.h" |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 #include "SDL_timer.h" |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 static Uint64 start_date; |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 static Uint64 start_ticks; |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
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
|
33 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
|
34 wce_ticks(void) |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 { |
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
|
36 return ((Uint64) GetTickCount()); |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 } |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
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
|
39 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
|
40 wce_date(void) |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 { |
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
|
42 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
|
43 { |
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 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
|
45 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
|
46 } 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
|
47 SYSTEMTIME stime; |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
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
|
49 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
|
50 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
|
51 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
|
52 // 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
|
53 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
|
54 return (ftime.itime); |
1180
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 |
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
|
57 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
|
58 wce_rel_ticks(void) |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 { |
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
|
60 return ((Sint32) (wce_ticks() - start_ticks)); |
1180
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 |
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
|
63 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
|
64 wce_rel_date(void) |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 { |
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
|
66 return ((Sint32) (wce_date() - start_date)); |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 } |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
5113
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
69 /* Recard start-time of application for reference */ |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
70 void |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
71 SDL_StartTicks(void) |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
72 { |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
73 start_date = wce_date(); |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
74 start_ticks = wce_ticks(); |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
75 } |
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
76 |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 /* 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
|
78 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
|
79 SDL_GetTicks() |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 { |
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
|
81 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
|
82 if ((offset < -1000) || (offset > 1000)) { |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 // 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
|
84 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
|
85 } |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
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 return ((Uint32) wce_rel_ticks()); |
1180
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 |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 /* 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
|
91 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
|
92 SDL_Delay(Uint32 ms) |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 { |
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 Sleep(ms); |
1180
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 } |
bdcb8bb4c831
From: Tyler Montbriand <tsm@accesscomm.ca>
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
5113
481dabb098ef
Improved timer implementation
Sam Lantinga <slouken@libsdl.org>
parents:
5092
diff
changeset
|
97 #endif /* SDL_TIMER_WINCE */ |
1497
420b3f47806d
Fixes from Dmitry Yakimov:
Sam Lantinga <slouken@libsdl.org>
parents:
1433
diff
changeset
|
98 |
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
|
99 /* vi: set ts=4 sw=4 expandtab: */ |