Provide timeGetTime compatibility layer

See #17, #24
This commit is contained in:
Alexander Batalov 2022-05-29 18:15:48 +03:00
parent 3d477ed235
commit 3d6019d2ec
4 changed files with 33 additions and 22 deletions

View File

@ -4,6 +4,8 @@
#include "movie_lib.h"
#include "platform_compat.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
@ -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;

View File

@ -5,6 +5,12 @@
#include <filesystem>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif
#ifdef _WIN32
#include <io.h>
#include <stdio.h>
@ -12,6 +18,12 @@
#include <unistd.h>
#endif
#ifdef _WIN32
#include <timeapi.h>
#else
#include <sys/time.h>
#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
}

View File

@ -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 */

View File

@ -1,21 +1,12 @@
#include "random.h"
#include "debug.h"
#include "platform_compat.h"
#include "scripts.h"
#include <limits.h>
#include <stdlib.h>
#if defined(_WIN32)
// clang-format off
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <timeapi.h>
// clang-format on
#else
#include <sys/time.h>
#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