From 0599b7e9fee8c826ccbe8fd0e73ad3190c7f858f Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 16 Apr 2025 14:13:06 +0200 Subject: [PATCH] fix: make gametime compillable for windows --- src/game/gametime.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/game/gametime.h b/src/game/gametime.h index bffb31a..598079d 100644 --- a/src/game/gametime.h +++ b/src/game/gametime.h @@ -6,12 +6,21 @@ struct gametime { time_t ms; }; -#if _POSIX_C_SOURCE >= 199309L +#if __has_include() +# include +# if _POSIX_C_SOURCE >= 199309L +# include static inline void gametime_get(struct timespec* ts) { clock_gettime(CLOCK_MONOTONIC, ts); } -#elif defined _WIN32 +# define GTIME_USE_UNIX +# endif +#endif + +#if defined _WIN32 && !defined GTIME_USE_UNIX +# include # include +# include static inline void gametime_get(struct timespec* ts) { LARGE_INTEGER cnt, frq; 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_nsec = (time_t)((cnt.QuadPart % frq.QuadPart) * 1000000000 / frq.QuadPart); } +#elif defined GTIME_USE_UNIX +# undef GTIME_USE_UNIX #else # error platform not supported #endif