diff --git a/rehlds/engine/net_ws.cpp b/rehlds/engine/net_ws.cpp index cf2dc54..36fec14 100644 --- a/rehlds/engine/net_ws.cpp +++ b/rehlds/engine/net_ws.cpp @@ -1055,7 +1055,7 @@ qboolean NET_QueuePacket(netsrc_t sock) } /* ../engine/net_ws.c:1145 */ -int NET_Sleep_Timeout(void) +int EXT_FUNC NET_Sleep_Timeout(void) { fd_set fdset; struct timeval tv; @@ -1107,7 +1107,7 @@ int NET_Sleep_Timeout(void) } tv.tv_sec = 0; - tv.tv_usec = 1000 * 1000 / fps; + tv.tv_usec = 1000 * 1000 / fps; // hmm if (tv.tv_usec == 0) tv.tv_usec = 1; @@ -1125,6 +1125,40 @@ int NET_Sleep_Timeout(void) } } +DLL_EXPORT int EXT_FUNC NET_Sleep_Timeout_New(unsigned int usec) +{ + int number = 0; + fd_set fdset; + FD_ZERO(&fdset); + + for (int i = 0; i < ARRAYSIZE(ip_sockets); i++) + { + int sock = ip_sockets[i]; + + if (sock > INVALID_SOCKET) + FD_SET(sock, &fdset); + +#ifndef _WIN32 + if (number < sock) + number = sock; + +#else // _WIN32 + sock = ipx_sockets[i]; + + if (sock > INVALID_SOCKET) + FD_SET(sock, &fdset); +#endif // _WIN32 + } + + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = usec; + if (tv.tv_usec == 0) + tv.tv_usec = 1; + + return select(number + 1, &fdset, 0, 0, &tv); +} + /* ../engine/net_ws.c:1211 */ int NET_Sleep(void) { diff --git a/rehlds/engine/sys_dll.cpp b/rehlds/engine/sys_dll.cpp index 8ca5c54..721e405 100644 --- a/rehlds/engine/sys_dll.cpp +++ b/rehlds/engine/sys_dll.cpp @@ -544,18 +544,20 @@ void Sys_Quit(void) double EXT_FUNC Sys_FloatTime(void) { unsigned int currentTime; - int savedOldTime; LARGE_INTEGER PerformanceCount; - - static bool s_NeedInit = true; static unsigned int s_oldTime = 0; - static int s_timeNotChangedCounter = 0; if (!g_PerfCounterInitialized) return 1.0; +#ifndef REHLDS_FIXES + int savedOldTime; + static bool s_NeedInit = true; + static int s_timeNotChangedCounter = 0; + EnterCriticalSection(&g_PerfCounterMutex); - Sys_FPUCW_Push_Prec64(); + Sys_FPUCW_Push_Prec64(); // we don't use fpu +#endif CRehldsPlatformHolder::get()->QueryPerfCounter(&PerformanceCount); if (g_PerfCounterShiftRightAmount) @@ -563,6 +565,14 @@ double EXT_FUNC Sys_FloatTime(void) else currentTime = PerformanceCount.LowPart; +#ifdef REHLDS_FIXES + if (currentTime != s_oldTime) + { + if (s_oldTime) + g_CurrentTime += double(currentTime - s_oldTime) * g_PerfCounterSlice; + s_oldTime = currentTime; + } +#else // REHLDS_FIXES if (!s_NeedInit) { savedOldTime = s_oldTime; @@ -576,7 +586,7 @@ double EXT_FUNC Sys_FloatTime(void) g_CurrentTime = g_CurrentTime + (double)(currentTime - savedOldTime) * g_PerfCounterSlice; if (g_CurrentTime == g_StartTime) { - if (s_timeNotChangedCounter >= 100000) + if (s_timeNotChangedCounter >= 100000) // always 0 { g_CurrentTime = g_CurrentTime + 1.0; s_timeNotChangedCounter = 0; @@ -586,7 +596,7 @@ double EXT_FUNC Sys_FloatTime(void) { s_timeNotChangedCounter = 0; } - g_StartTime = g_CurrentTime; + g_StartTime = g_CurrentTime; // wtf } } else @@ -597,6 +607,7 @@ double EXT_FUNC Sys_FloatTime(void) Sys_FPUCW_Pop_Prec64(); LeaveCriticalSection(&g_PerfCounterMutex); +#endif return g_CurrentTime; } diff --git a/rehlds/public/rehlds/osconfig.h b/rehlds/public/rehlds/osconfig.h index 54bb0c8..5c96f55 100644 --- a/rehlds/public/rehlds/osconfig.h +++ b/rehlds/public/rehlds/osconfig.h @@ -132,6 +132,8 @@ #define _MAX_FNAME NAME_MAX #define MAX_PATH 260 + #define INVALID_SOCKET (-1) + typedef void *HWND; typedef unsigned long DWORD;