diff --git a/MSVC/minetestmapper.vcxproj b/MSVC/minetestmapper.vcxproj index 1d53c05..d1841cf 100644 --- a/MSVC/minetestmapper.vcxproj +++ b/MSVC/minetestmapper.vcxproj @@ -178,6 +178,7 @@ + diff --git a/MSVC/minetestmapper.vcxproj.filters b/MSVC/minetestmapper.vcxproj.filters index 31f18d9..8bbdb73 100644 --- a/MSVC/minetestmapper.vcxproj.filters +++ b/MSVC/minetestmapper.vcxproj.filters @@ -54,6 +54,9 @@ Header files + + Header files + Header files diff --git a/porting.h b/porting.h index c093beb..cb692b9 100644 --- a/porting.h +++ b/porting.h @@ -2,15 +2,9 @@ #define _PORTING_H #ifdef _WIN32 - -#include -#define sleepMs(x) Sleep(x) - +#include "porting_win32.h" #else - -#include -#define sleepMs(x) usleep(x*1000) - +#include "porting_posix.h" #endif #ifdef _MSC_VER @@ -20,3 +14,4 @@ #endif #endif // _PORTING_H + diff --git a/porting_posix.h b/porting_posix.h new file mode 100644 index 0000000..6365526 --- /dev/null +++ b/porting_posix.h @@ -0,0 +1,30 @@ + +#include +#include +#include +#include + +#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; + } +} + diff --git a/porting_win32.h b/porting_win32.h new file mode 100644 index 0000000..7a3f8ab --- /dev/null +++ b/porting_win32.h @@ -0,0 +1,10 @@ + +#include + +#define sleepMs(x) Sleep(x) + +inline uint64_t getRelativeTimeStampMs() +{ + return GetTickCount64(); +} +