Leviathan  0.8.0.0
Leviathan game engine
TimeIncludes.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "TimeIncludes.h"
3 
4 #ifdef __linux__
5 #include <sys/time.h>
6 #elif _WIN32
7 #include "WindowsInclude.h"
8 #endif
9 using namespace Leviathan;
10 // ------------------------------------ //
12 {
13 #ifdef _WIN32
14  /* Windows */
15  FILETIME ft;
16  LARGE_INTEGER li;
17 
18  /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and
19  * copy it to a LARGE_INTEGER structure. */
20  GetSystemTimeAsFileTime(&ft);
21  li.LowPart = ft.dwLowDateTime;
22  li.HighPart = ft.dwHighDateTime;
23 
24  int64_t ret = li.QuadPart;
25  ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
26  ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */
27 
28  return ret;
29 #elif defined __linux__
30  /* Linux */
31  struct timeval tv;
32 
33  gettimeofday(&tv, NULL);
34 
35  int64_t ret = tv.tv_usec;
36  /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */
37  ret /= 1000;
38 
39  /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */
40  ret += (tv.tv_sec * 1000);
41 
42  return ret;
43 #else
44 #error no working get time on platform
45 #endif
46 }
47 
49 {
50 #ifdef _WIN32
51  /* Windows */
52  FILETIME ft;
53  LARGE_INTEGER li;
54 
55  /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and
56  * copy it to a LARGE_INTEGER structure. */
57  GetSystemTimeAsFileTime(&ft);
58  li.LowPart = ft.dwLowDateTime;
59  li.HighPart = ft.dwHighDateTime;
60 
61  int64_t ret = li.QuadPart;
62  ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
63  ret /= 10; /* From 100 nano seconds (10^-7) to 1 microsecond (10^-6) intervals */
64 
65  return ret;
66 #elif defined __linux__
67  /* Linux */
68  struct timeval tv;
69 
70  gettimeofday(&tv, NULL);
71 
72  int64_t ret = tv.tv_usec;
73 
74  /* Adds the seconds (10^0) after converting them to microseconds (10^-6) */
75  ret += (tv.tv_sec * 1000000);
76 
77  return ret;
78 #else
79 #error no working get time on platform
80 #endif
81 }
82 // ------------------------------------ //
83 DLLEXPORT WantedClockType::time_point Time::GetThreadSafeSteadyTimePoint()
84 {
85 
86  return WantedClockType::now();
87 }
88 // ------------------------------------ //
static DLLEXPORT WantedClockType::time_point GetThreadSafeSteadyTimePoint()
static DLLEXPORT int64_t GetTimeMs64()
static DLLEXPORT int64_t GetTimeMicro64()
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12