mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-01 01:25:38 +03:00
Merge pull request #337 from WPMGPRoSToTeMa/LocalGametime
Fixed local gametime ticking when server is paused
This commit is contained in:
commit
027a01bf42
@ -1392,23 +1392,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
|
||||
@ -1491,7 +1486,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
|
||||
@ -1594,6 +1589,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);
|
||||
@ -4679,7 +4675,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
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user