mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
fix: make gametime compillable for windows
This commit is contained in:
@@ -6,12 +6,21 @@ struct gametime {
|
||||
time_t ms;
|
||||
};
|
||||
|
||||
#if _POSIX_C_SOURCE >= 199309L
|
||||
#if __has_include(<features.h>)
|
||||
# include <features.h>
|
||||
# if _POSIX_C_SOURCE >= 199309L
|
||||
# include <bits/time.h>
|
||||
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 <profileapi.h>
|
||||
# include <windows.h>
|
||||
# include <winnt.h>
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user