5
5
internal static class Timers {
7
// win32-specific api-declarations
8
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
9
private static extern bool QueryPerformanceFrequency(out long lpFrequency);
10
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
11
private static extern bool QueryPerformanceCounter(out long lpPerformanceCount);
14
private static bool WindowsHighPrecisionTimer = false;
15
private static double WindowsHighPrecisionTimerInverseFrequency = 0.0;
16
private static long WindowsHighPrecisionTimerCounter = 0;
17
8
private static double SdlTime = 0.0;
20
11
internal static void Initialize() {
21
if (Program.CurrentPlatform == Program.Platform.Windows) {
22
long f; if (QueryPerformanceFrequency(out f)) {
23
WindowsHighPrecisionTimerInverseFrequency = 1.0 / (double)f;
24
QueryPerformanceCounter(out WindowsHighPrecisionTimerCounter);
25
WindowsHighPrecisionTimer = true;
28
if (!WindowsHighPrecisionTimer) {
29
SdlTime = 0.001 * (double)Sdl.SDL_GetTicks();
12
SdlTime = 0.001 * (double)Sdl.SDL_GetTicks();
33
15
// get elapsed time
34
16
internal static double GetElapsedTime() {
35
if (WindowsHighPrecisionTimer) {
36
long a; QueryPerformanceCounter(out a);
37
long d = a - WindowsHighPrecisionTimerCounter;
38
WindowsHighPrecisionTimerCounter = a;
39
return (double)d * WindowsHighPrecisionTimerInverseFrequency;
41
double a = 0.001 * (double)Sdl.SDL_GetTicks();
42
double d = a - SdlTime;
17
double a = 0.001 * (double)Sdl.SDL_GetTicks();
18
double d = a - SdlTime;