From dacd3bf14ee6fec632aecf72b057162ebf7957a7 Mon Sep 17 00:00:00 2001 From: WPMGPRoSToTeMa Date: Mon, 6 Feb 2017 02:43:59 +0300 Subject: [PATCH] Fixed local gametime ticking when server is paused --- rehlds/engine/sv_main.cpp | 24 ++++++++++-------------- rehlds/rehlds/rehlds_interfaces_impl.cpp | 3 +-- rehlds/rehlds/rehlds_interfaces_impl.h | 10 ++++++++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 991bf86..0a216de 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -1389,23 +1389,18 @@ void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg) // FIXME: there is a loss of precision, because gamedll has already written float gametime in them if (sv_rehlds_local_gametime.value != 0.0f) { - auto convertGameTimeToLocal = - [](float &gameTime) + auto convertGlobalGameTimeToLocal = + [](float &globalGameTime) { - if (gameTime > 0.0f) - { - auto currentLocalGameTime = realtime - host_client->connection_started; - auto currentGameTime = g_psv.time; - auto difference = gameTime - currentGameTime; - gameTime = (float)(currentLocalGameTime + difference); - } + if (globalGameTime > 0.0f) + globalGameTime -= (float)g_GameClients[host_client - g_psvs.clients]->GetLocalGameTimeBase(); }; if (g_bIsCStrike || g_bIsCZero) - convertGameTimeToLocal(std::ref(tdata->m_fAimedDamage)); + convertGlobalGameTimeToLocal(std::ref(tdata->m_fAimedDamage)); if (g_bIsHL1 || g_bIsCStrike || g_bIsCZero) { - convertGameTimeToLocal(std::ref(tdata->fuser2)); - convertGameTimeToLocal(std::ref(tdata->fuser3)); + convertGlobalGameTimeToLocal(std::ref(tdata->fuser2)); + convertGlobalGameTimeToLocal(std::ref(tdata->fuser3)); } } #endif @@ -1488,7 +1483,7 @@ void SV_WriteSpawn(sizebuf_t *msg) #ifdef REHLDS_FIXES if (sv_rehlds_local_gametime.value != 0.0f) { - MSG_WriteFloat(msg, (float)(realtime - host_client->connection_started)); + MSG_WriteFloat(msg, (float)g_GameClients[host_client - g_psvs.clients]->GetLocalGameTime()); } else #endif @@ -1591,6 +1586,7 @@ void SV_New_f(void) host_client->connected = TRUE; host_client->connection_started = realtime; + g_GameClients[host_client - g_psvs.clients]->SetupLocalGameTime(); host_client->m_sendrescount = 0; SZ_Clear(&host_client->netchan.message); @@ -4665,7 +4661,7 @@ qboolean SV_SendClientDatagram(client_t *client) #ifdef REHLDS_FIXES if (sv_rehlds_local_gametime.value != 0.0f) { - MSG_WriteFloat(&msg, (float)(realtime - client->connection_started)); + MSG_WriteFloat(&msg, (float)g_GameClients[client - g_psvs.clients]->GetLocalGameTime()); } else #endif diff --git a/rehlds/rehlds/rehlds_interfaces_impl.cpp b/rehlds/rehlds/rehlds_interfaces_impl.cpp index b09903f..ca2b4c4 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.cpp +++ b/rehlds/rehlds/rehlds_interfaces_impl.cpp @@ -31,8 +31,7 @@ CGameClient** g_GameClients; CGameClient::CGameClient(int id, client_t* cl) - : m_NetChan(&cl->netchan) -{ + : m_NetChan(&cl->netchan), m_localGameTimeBase(0) { m_Id = id; m_pClient = cl; m_bSpawnedOnce = false; diff --git a/rehlds/rehlds/rehlds_interfaces_impl.h b/rehlds/rehlds/rehlds_interfaces_impl.h index caab23c..98dd23e 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.h +++ b/rehlds/rehlds/rehlds_interfaces_impl.h @@ -64,6 +64,10 @@ private: // we would also use the field client_t:connected, but actually can't because there is a bug in CS client when server sends TeamScore // and client is not yet initialized ScoreBoard which leads to memory corruption in the client. bool m_bSpawnedOnce; + +#ifdef REHLDS_FIXES + double m_localGameTimeBase; +#endif public: CGameClient(int id, client_t* cl); @@ -102,6 +106,12 @@ public: #ifdef REHLDS_FIXES uint8_t* GetExtendedMessageBuffer() { return m_NetChan.GetExtendedMessageBuffer(); }; #endif + +#ifdef REHLDS_FIXES + void SetupLocalGameTime() { m_localGameTimeBase = g_psv.time; } + double GetLocalGameTime() const { return g_psv.time - m_localGameTimeBase; } + double GetLocalGameTimeBase() const { return m_localGameTimeBase; } +#endif }; class CRehldsServerStatic : public IRehldsServerStatic {