diff --git a/src/movie_lib.cc b/src/movie_lib.cc index 6d9d7cb..e500352 100644 --- a/src/movie_lib.cc +++ b/src/movie_lib.cc @@ -4,6 +4,8 @@ #include "movie_lib.h" +#include "platform_compat.h" + #include #include #include @@ -717,9 +719,9 @@ int _syncWait() result = 0; if (_sync_active) { - if (((_sync_time + 1000 * timeGetTime()) & 0x80000000) != 0) { + if (((_sync_time + 1000 * compat_timeGetTime()) & 0x80000000) != 0) { result = 1; - while (((_sync_time + 1000 * timeGetTime()) & 0x80000000) != 0) + while (((_sync_time + 1000 * compat_timeGetTime()) & 0x80000000) != 0) ; } _sync_time += _sync_wait_quanta; @@ -1043,7 +1045,7 @@ int _syncInit(int a1, int a2) void _syncReset(int a1) { _sync_active = 1; - _sync_time = -1000 * timeGetTime() + a1; + _sync_time = -1000 * compat_timeGetTime() + a1; } // 0x4F5570 @@ -1100,7 +1102,7 @@ int _MVE_sndConfigure(int a1, int a2, int a3, int a4, int a5, int a6) void _MVE_syncSync() { if (_sync_active) { - while (((_sync_time + 1000 * timeGetTime()) & 0x80000000) != 0) { + while (((_sync_time + 1000 * compat_timeGetTime()) & 0x80000000) != 0) { } } } @@ -1269,7 +1271,7 @@ int _syncWaitLevel(int a1) v2 = _sync_time + a1; do { - result = v2 + 1000 * timeGetTime(); + result = v2 + 1000 * compat_timeGetTime(); } while (result < 0); _sync_time += _sync_wait_quanta; diff --git a/src/platform_compat.cc b/src/platform_compat.cc index 34f6f9e..837903f 100644 --- a/src/platform_compat.cc +++ b/src/platform_compat.cc @@ -5,6 +5,12 @@ #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#endif + #ifdef _WIN32 #include #include @@ -12,6 +18,12 @@ #include #endif +#ifdef _WIN32 +#include +#else +#include +#endif + int compat_stricmp(const char* string1, const char* string2) { return SDL_strcasecmp(string1, string2); @@ -107,3 +119,14 @@ int compat_mkdir(const char* path) return ec.value(); } + +unsigned int compat_timeGetTime() +{ +#ifdef _WIN32 + return timeGetTime(); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec / 1000; +#endif +} diff --git a/src/platform_compat.h b/src/platform_compat.h index 759bda8..1ba9358 100644 --- a/src/platform_compat.h +++ b/src/platform_compat.h @@ -26,5 +26,6 @@ void compat_splitpath(const char* path, char* drive, char* dir, char* fname, cha void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext); long compat_filelength(int fd); int compat_mkdir(const char* path); +unsigned int compat_timeGetTime(); #endif /* PLATFORM_COMPAT_H */ diff --git a/src/random.cc b/src/random.cc index b9ed226..03d854c 100644 --- a/src/random.cc +++ b/src/random.cc @@ -1,21 +1,12 @@ #include "random.h" #include "debug.h" +#include "platform_compat.h" #include "scripts.h" #include #include -#if defined(_WIN32) -// clang-format off -#define WIN32_LEAN_AND_MEAN -#include -#include -// clang-format on -#else -#include -#endif - // 0x50D4BA const double dbl_50D4BA = 36.42; @@ -212,13 +203,7 @@ void randomSeedPrerandomInternal(int seed) // 0x4A3258 unsigned int randomGetSeed() { -#if defined(_WIN32) - return timeGetTime(); -#else - struct timeval tv; - gettimeofday(&tv, NULL); - return tv.tv_usec / 1000; -#endif + return compat_timeGetTime(); } // 0x4A3264