mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
25 lines
608 B
C
25 lines
608 B
C
#pragma once
|
|
#include <time.h>
|
|
|
|
struct gametime {
|
|
struct timespec ts;
|
|
time_t ms;
|
|
};
|
|
|
|
#if _POSIX_C_SOURCE >= 199309L
|
|
static inline void gametime_get(struct timespec* ts) {
|
|
clock_gettime(CLOCK_MONOTONIC, ts);
|
|
}
|
|
#elif defined _WIN32
|
|
# include <windows.h>
|
|
static inline void gametime_get(struct timespec* ts) {
|
|
LARGE_INTEGER cnt, frq;
|
|
QueryPerformanceCounter(&cnt);
|
|
QueryPerformanceFrequency(&frq);
|
|
ts->tv_sec = (time_t)(cnt.QuadPart / frq.QuadPart);
|
|
ts->tv_nsec = (time_t)((cnt.QuadPart % frq.QuadPart) * 1000000000 / frq.QuadPart);
|
|
}
|
|
#else
|
|
# error platform not supported
|
|
#endif
|