Add a function to obtain relative millisecond-timestamps
'Relative' in the sense that they can only sensibly compared to another time value obtained using the same function during the same program invocation.
This commit is contained in:
parent
cbfb7e6979
commit
2f4a917bb1
@ -178,6 +178,7 @@
|
|||||||
<ClInclude Include="..\PixelAttributes.h" />
|
<ClInclude Include="..\PixelAttributes.h" />
|
||||||
<ClInclude Include="..\PlayerAttributes.h" />
|
<ClInclude Include="..\PlayerAttributes.h" />
|
||||||
<ClInclude Include="..\porting.h" />
|
<ClInclude Include="..\porting.h" />
|
||||||
|
<ClInclude Include="..\porting_win32.h" />
|
||||||
<ClInclude Include="..\Settings.h" />
|
<ClInclude Include="..\Settings.h" />
|
||||||
<ClInclude Include="..\TileGenerator.h" />
|
<ClInclude Include="..\TileGenerator.h" />
|
||||||
<ClInclude Include="..\types.h" />
|
<ClInclude Include="..\types.h" />
|
||||||
|
@ -54,6 +54,9 @@
|
|||||||
<ClInclude Include="..\porting.h">
|
<ClInclude Include="..\porting.h">
|
||||||
<Filter>Header files</Filter>
|
<Filter>Header files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\porting_win32.h">
|
||||||
|
<Filter>Header files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="resource.h">
|
<ClInclude Include="resource.h">
|
||||||
<Filter>Header files</Filter>
|
<Filter>Header files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
11
porting.h
11
porting.h
@ -2,15 +2,9 @@
|
|||||||
#define _PORTING_H
|
#define _PORTING_H
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include "porting_win32.h"
|
||||||
#include <windows.h>
|
|
||||||
#define sleepMs(x) Sleep(x)
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#include "porting_posix.h"
|
||||||
#include <unistd.h>
|
|
||||||
#define sleepMs(x) usleep(x*1000)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -20,3 +14,4 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // _PORTING_H
|
#endif // _PORTING_H
|
||||||
|
|
||||||
|
30
porting_posix.h
Normal file
30
porting_posix.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#define sleepMs(x) usleep((x)*1000)
|
||||||
|
|
||||||
|
inline uint64_t getRelativeTimeStampMs()
|
||||||
|
{
|
||||||
|
int rv = -1;
|
||||||
|
struct timespec ts;
|
||||||
|
#ifdef CLOCK_MONOTONIC_RAW
|
||||||
|
if (rv == -1)
|
||||||
|
rv = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||||
|
#endif
|
||||||
|
#ifdef _POSIX_MONOTONIC_CLOCK
|
||||||
|
if (rv == -1)
|
||||||
|
rv = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
#endif
|
||||||
|
if (rv == -1) {
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
10
porting_win32.h
Normal file
10
porting_win32.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#define sleepMs(x) Sleep(x)
|
||||||
|
|
||||||
|
inline uint64_t getRelativeTimeStampMs()
|
||||||
|
{
|
||||||
|
return GetTickCount64();
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user