Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
99 lines (80 loc) · 2.27 KB

SDL_systimer.c

File metadata and controls

99 lines (80 loc) · 2.27 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 12, 2011
Feb 12, 2011
3
Copyright (C) 1997-2011 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
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
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 14, 2006
Apr 14, 2006
24
25
#ifdef SDL_TIMER_WINCE
Jan 25, 2011
Jan 25, 2011
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;
Jul 10, 2006
Jul 10, 2006
33
34
static Uint64
wce_ticks(void)
Jul 10, 2006
Jul 10, 2006
36
return ((Uint64) GetTickCount());
37
38
}
Jul 10, 2006
Jul 10, 2006
39
40
static Uint64
wce_date(void)
Jul 10, 2006
Jul 10, 2006
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
}
Jul 10, 2006
Jul 10, 2006
57
58
static Sint32
wce_rel_ticks(void)
Jul 10, 2006
Jul 10, 2006
60
return ((Sint32) (wce_ticks() - start_ticks));
61
62
}
Jul 10, 2006
Jul 10, 2006
63
64
static Sint32
wce_rel_date(void)
Jul 10, 2006
Jul 10, 2006
66
return ((Sint32) (wce_date() - start_date));
67
68
}
Jan 27, 2011
Jan 27, 2011
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 */
Jul 10, 2006
Jul 10, 2006
78
79
Uint32
SDL_GetTicks()
Jul 10, 2006
Jul 10, 2006
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);
Jul 10, 2006
Jul 10, 2006
84
85
start_ticks -= offset;
}
Jul 10, 2006
Jul 10, 2006
87
return ((Uint32) wce_rel_ticks());
88
89
90
}
/* Give up approx. givem milliseconds to the OS. */
Jul 10, 2006
Jul 10, 2006
91
92
void
SDL_Delay(Uint32 ms)
Jul 10, 2006
Jul 10, 2006
94
Sleep(ms);
95
96
}
Apr 14, 2006
Apr 14, 2006
97
#endif /* SDL_TIMER_WINCE */
Jan 27, 2011
Jan 27, 2011
98
Jul 10, 2006
Jul 10, 2006
99
/* vi: set ts=4 sw=4 expandtab: */