From 2714708ca916f5e40166407b4a8824248ff2a20c Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 20 May 2020 17:56:35 +0300 Subject: [PATCH] avoid redefining CLOCK_MONOTONIC and shit --- include/PR/ultratypes.h | 4 +++- src/pc/gfx/gfx_pc.c | 44 ++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 7c35d291..1ebde775 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -32,6 +32,7 @@ typedef double f64; #include #include #include + #if defined(__MINGW32__) #include <_mingw.h> #if !defined(__MINGW64_VERSION_MAJOR) @@ -40,4 +41,5 @@ typedef long ssize_t; typedef ptrdiff_t ssize_t; #endif #endif -#endif + +#endif // _ULTRA64_TYPES_H_ diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 51fe919a..e2aadfa1 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -40,8 +40,6 @@ #define MAX_LIGHTS 2 #define MAX_VERTICES 64 -#define CLOCK_MONOTONIC 0 - struct RGBA { uint8_t r, g, b, a; }; @@ -157,23 +155,37 @@ static size_t buf_vbo_num_tris; static struct GfxWindowManagerAPI *gfx_wapi; static struct GfxRenderingAPI *gfx_rapi; -#if defined(__MINGW32__) -#include <_mingw.h> -#if !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) && !defined(__APPLE__) +// old mingw +# include <_mingw.h> +# define NO_CLOCK_GETTIME +#endif + +#ifdef NO_CLOCK_GETTIME + +#if defined(_WIN32) #include -//https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows -struct timespec { long tv_sec; long tv_nsec; }; //header part -int clock_gettime(int arg, struct timespec *spec) //C-file part -{ __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime); - wintime -=116444736000000000LL; //1jan1601 to 1jan1970 - spec->tv_sec =wintime / 10000000LL; //seconds - spec->tv_nsec =wintime % 10000000LL*100; //nano-seconds - return 0; +#define CLOCK_MONOTONIC 0 +// https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows +struct timespec { long tv_sec; long tv_nsec; }; +int clock_gettime(int arg, struct timespec *spec) { + __int64 wintime; + GetSystemTimeAsFileTime((FILETIME*)&wintime); + wintime -= 116444736000000000LL; //1jan1601 to 1jan1970 + spec->tv_sec = wintime / 10000000LL; //seconds + spec->tv_nsec = wintime % 10000000LL*100; //nano-seconds + return 0; } -#else +#else // _WIN32 +#error "Add a clock_gettime() impl for your platform!" +#endif // _WIN32 + +#else // NO_CLOCK_GETTIME + #include -#endif -#endif + +#endif // NO_CLOCK_GETTIME + static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);