fix: make gametime compillable for windows

This commit is contained in:
2025-04-16 14:13:06 +02:00
parent a2ab7da423
commit 0599b7e9fe

View File

@@ -6,12 +6,21 @@ struct gametime {
time_t ms; time_t ms;
}; };
#if __has_include(<features.h>)
# include <features.h>
# if _POSIX_C_SOURCE >= 199309L # if _POSIX_C_SOURCE >= 199309L
# include <bits/time.h>
static inline void gametime_get(struct timespec* ts) { static inline void gametime_get(struct timespec* ts) {
clock_gettime(CLOCK_MONOTONIC, ts); clock_gettime(CLOCK_MONOTONIC, ts);
} }
#elif defined _WIN32 # define GTIME_USE_UNIX
# endif
#endif
#if defined _WIN32 && !defined GTIME_USE_UNIX
# include <profileapi.h>
# include <windows.h> # include <windows.h>
# include <winnt.h>
static inline void gametime_get(struct timespec* ts) { static inline void gametime_get(struct timespec* ts) {
LARGE_INTEGER cnt, frq; LARGE_INTEGER cnt, frq;
QueryPerformanceCounter(&cnt); QueryPerformanceCounter(&cnt);
@@ -19,6 +28,8 @@ static inline void gametime_get(struct timespec* ts) {
ts->tv_sec = (time_t)(cnt.QuadPart / frq.QuadPart); ts->tv_sec = (time_t)(cnt.QuadPart / frq.QuadPart);
ts->tv_nsec = (time_t)((cnt.QuadPart % frq.QuadPart) * 1000000000 / frq.QuadPart); ts->tv_nsec = (time_t)((cnt.QuadPart % frq.QuadPart) * 1000000000 / frq.QuadPart);
} }
#elif defined GTIME_USE_UNIX
# undef GTIME_USE_UNIX
#else #else
# error platform not supported # error platform not supported
#endif #endif