-
Notifications
You must be signed in to change notification settings - Fork 5
/
Time.cpp
98 lines (77 loc) · 1.61 KB
/
Time.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "Time.hpp"
#ifdef ___INANITY_PLATFORM_WINDOWS
#include "platform/windows.hpp"
#endif
#ifdef ___INANITY_PLATFORM_MACOS
#include <mach/mach_time.h>
#endif
#ifdef ___INANITY_PLATFORM_SWITCH
#include <nn/os.h>
#endif
#ifdef ___INANITY_PLATFORM_EMSCRIPTEN
#include <emscripten/emscripten.h>
#endif
#include <ctime>
BEGIN_INANITY
long long Time::GetUnixTime()
{
// используем стандартную функцию C++
return time(0);
}
#if defined(___INANITY_PLATFORM_WINDOWS)
long long Time::GetTick()
{
LARGE_INTEGER li;
QueryPerformanceCounter(&li);
return li.QuadPart;
}
long long Time::GetTicksPerSecond()
{
LARGE_INTEGER li;
QueryPerformanceFrequency(&li);
return li.QuadPart;
}
#elif defined(___INANITY_PLATFORM_EMSCRIPTEN)
Time::Tick Time::GetTick()
{
return emscripten_get_now();
}
Time::Tick Time::GetTicksPerSecond()
{
return 1000.0f;
}
#elif defined(___INANITY_PLATFORM_MACOS)
long long Time::GetTick()
{
return mach_absolute_time();
}
long long Time::GetTicksPerSecond()
{
mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase);
return 1000000000LL * timebase.numer / timebase.denom;
}
#elif defined(___INANITY_PLATFORM_SWITCH)
long long Time::GetTick()
{
return nn::os::GetSystemTick().GetInt64Value();
}
long long Time::GetTicksPerSecond()
{
return nn::os::GetSystemTickFrequency();
}
#elif defined(___INANITY_PLATFORM_POSIX)
long long Time::GetTick()
{
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return t.tv_sec * 1000000000LL + t.tv_nsec;
}
long long Time::GetTicksPerSecond()
{
return 1000000000LL;
}
#else
#error Unknown platform
#endif
END_INANITY