This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_systimer.c
99 lines (80 loc) · 2.27 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2011 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
22
#include "SDL_config.h"
23
24
25
#ifdef SDL_TIMER_WINCE
26
#include "../../core/windows/SDL_windows.h"
27
28
29
30
31
32
#include "SDL_timer.h"
static Uint64 start_date;
static Uint64 start_ticks;
33
34
static Uint64
wce_ticks(void)
35
{
36
return ((Uint64) GetTickCount());
37
38
}
39
40
static Uint64
wce_date(void)
41
{
42
43
44
45
46
47
48
49
50
51
52
53
54
union
{
FILETIME ftime;
Uint64 itime;
} ftime;
SYSTEMTIME stime;
GetSystemTime(&stime);
SystemTimeToFileTime(&stime, &ftime.ftime);
ftime.itime /= 10000; // Convert 100ns intervals to 1ms intervals
// Remove ms portion, which can't be relied on
ftime.itime -= (ftime.itime % 1000);
return (ftime.itime);
55
56
}
57
58
static Sint32
wce_rel_ticks(void)
59
{
60
return ((Sint32) (wce_ticks() - start_ticks));
61
62
}
63
64
static Sint32
wce_rel_date(void)
65
{
66
return ((Sint32) (wce_date() - start_date));
67
68
}
69
70
71
72
73
74
75
76
/* Recard start-time of application for reference */
void
SDL_StartTicks(void)
{
start_date = wce_date();
start_ticks = wce_ticks();
}
77
/* Return time in ms relative to when SDL was started */
78
79
Uint32
SDL_GetTicks()
80
{
81
82
Sint32 offset = wce_rel_date() - wce_rel_ticks();
if ((offset < -1000) || (offset > 1000)) {
83
// fprintf(stderr,"Time desync(%+d), resyncing\n",offset/1000);
84
85
start_ticks -= offset;
}
86
87
return ((Uint32) wce_rel_ticks());
88
89
90
}
/* Give up approx. givem milliseconds to the OS. */
91
92
void
SDL_Delay(Uint32 ms)
93
{
94
Sleep(ms);
95
96
}
97
#endif /* SDL_TIMER_WINCE */
98
99
/* vi: set ts=4 sw=4 expandtab: */