mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-04 02:55:50 +03:00
Fixed local gametime ticking when server is paused
This commit is contained in:
parent
34f23b1577
commit
dacd3bf14e
@ -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
|
// FIXME: there is a loss of precision, because gamedll has already written float gametime in them
|
||||||
if (sv_rehlds_local_gametime.value != 0.0f)
|
if (sv_rehlds_local_gametime.value != 0.0f)
|
||||||
{
|
{
|
||||||
auto convertGameTimeToLocal =
|
auto convertGlobalGameTimeToLocal =
|
||||||
[](float &gameTime)
|
[](float &globalGameTime)
|
||||||
{
|
{
|
||||||
if (gameTime > 0.0f)
|
if (globalGameTime > 0.0f)
|
||||||
{
|
globalGameTime -= (float)g_GameClients[host_client - g_psvs.clients]->GetLocalGameTimeBase();
|
||||||
auto currentLocalGameTime = realtime - host_client->connection_started;
|
|
||||||
auto currentGameTime = g_psv.time;
|
|
||||||
auto difference = gameTime - currentGameTime;
|
|
||||||
gameTime = (float)(currentLocalGameTime + difference);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if (g_bIsCStrike || g_bIsCZero)
|
if (g_bIsCStrike || g_bIsCZero)
|
||||||
convertGameTimeToLocal(std::ref(tdata->m_fAimedDamage));
|
convertGlobalGameTimeToLocal(std::ref(tdata->m_fAimedDamage));
|
||||||
if (g_bIsHL1 || g_bIsCStrike || g_bIsCZero)
|
if (g_bIsHL1 || g_bIsCStrike || g_bIsCZero)
|
||||||
{
|
{
|
||||||
convertGameTimeToLocal(std::ref(tdata->fuser2));
|
convertGlobalGameTimeToLocal(std::ref(tdata->fuser2));
|
||||||
convertGameTimeToLocal(std::ref(tdata->fuser3));
|
convertGlobalGameTimeToLocal(std::ref(tdata->fuser3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1488,7 +1483,7 @@ void SV_WriteSpawn(sizebuf_t *msg)
|
|||||||
#ifdef REHLDS_FIXES
|
#ifdef REHLDS_FIXES
|
||||||
if (sv_rehlds_local_gametime.value != 0.0f)
|
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
|
else
|
||||||
#endif
|
#endif
|
||||||
@ -1591,6 +1586,7 @@ void SV_New_f(void)
|
|||||||
|
|
||||||
host_client->connected = TRUE;
|
host_client->connected = TRUE;
|
||||||
host_client->connection_started = realtime;
|
host_client->connection_started = realtime;
|
||||||
|
g_GameClients[host_client - g_psvs.clients]->SetupLocalGameTime();
|
||||||
host_client->m_sendrescount = 0;
|
host_client->m_sendrescount = 0;
|
||||||
|
|
||||||
SZ_Clear(&host_client->netchan.message);
|
SZ_Clear(&host_client->netchan.message);
|
||||||
@ -4665,7 +4661,7 @@ qboolean SV_SendClientDatagram(client_t *client)
|
|||||||
#ifdef REHLDS_FIXES
|
#ifdef REHLDS_FIXES
|
||||||
if (sv_rehlds_local_gametime.value != 0.0f)
|
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
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,8 +31,7 @@
|
|||||||
CGameClient** g_GameClients;
|
CGameClient** g_GameClients;
|
||||||
|
|
||||||
CGameClient::CGameClient(int id, client_t* cl)
|
CGameClient::CGameClient(int id, client_t* cl)
|
||||||
: m_NetChan(&cl->netchan)
|
: m_NetChan(&cl->netchan), m_localGameTimeBase(0) {
|
||||||
{
|
|
||||||
m_Id = id;
|
m_Id = id;
|
||||||
m_pClient = cl;
|
m_pClient = cl;
|
||||||
m_bSpawnedOnce = false;
|
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
|
// 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.
|
// and client is not yet initialized ScoreBoard which leads to memory corruption in the client.
|
||||||
bool m_bSpawnedOnce;
|
bool m_bSpawnedOnce;
|
||||||
|
|
||||||
|
#ifdef REHLDS_FIXES
|
||||||
|
double m_localGameTimeBase;
|
||||||
|
#endif
|
||||||
public:
|
public:
|
||||||
CGameClient(int id, client_t* cl);
|
CGameClient(int id, client_t* cl);
|
||||||
|
|
||||||
@ -102,6 +106,12 @@ public:
|
|||||||
#ifdef REHLDS_FIXES
|
#ifdef REHLDS_FIXES
|
||||||
uint8_t* GetExtendedMessageBuffer() { return m_NetChan.GetExtendedMessageBuffer(); };
|
uint8_t* GetExtendedMessageBuffer() { return m_NetChan.GetExtendedMessageBuffer(); };
|
||||||
#endif
|
#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 {
|
class CRehldsServerStatic : public IRehldsServerStatic {
|
||||||
|
Loading…
Reference in New Issue
Block a user