mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Write 'SVC_ServerTick' into snapshot buffer
This should be cheaper and more reliable than sending it as a separate net message.
This commit is contained in:
parent
6a69965b33
commit
e48623102f
@ -10,6 +10,7 @@
|
||||
#include "server/server.h"
|
||||
#include "host.h"
|
||||
#endif // !CLIENT_DLL
|
||||
#include "net.h"
|
||||
#include "networkstringtable.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -89,43 +90,22 @@ bool CNetworkStringTable::Lock(bool bLock)
|
||||
// nTickAck -
|
||||
// *pMsg -
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef CLIENT_DLL
|
||||
CFastTimer CNetworkStringTableContainer::sm_StatsTimer;
|
||||
bool CNetworkStringTableContainer::sm_bStatsInitialized = false;
|
||||
#endif // !CLIENT_DLL
|
||||
void CNetworkStringTableContainer::WriteUpdateMessage(CNetworkStringTableContainer* thisp, CClient* pClient, unsigned int nTickAck, bf_write* pMsg)
|
||||
{
|
||||
#ifndef CLIENT_DLL
|
||||
if (sv_stats->GetBool())
|
||||
{
|
||||
if (!sm_bStatsInitialized)
|
||||
uint8_t nCPUPercentage = static_cast<uint8_t>(g_pServer[MAX_PLAYERS].GetCPUUsage() * 100.0f);
|
||||
SVC_ServerTick serverTick(g_pServer->GetTick(), *host_frametime_unbounded, *host_frametime_stddeviation, nCPUPercentage);
|
||||
|
||||
serverTick.m_nGroup = 0;
|
||||
serverTick.m_bReliable = true;
|
||||
serverTick.m_NetTick.m_nCommandTick = -1; // Statistics only, see 'CClientState::VProcessServerTick'.
|
||||
|
||||
pMsg->WriteUBitLong(serverTick.GetType(), NETMSG_TYPE_BITS);
|
||||
if (!pMsg->IsOverflowed())
|
||||
{
|
||||
sm_bStatsInitialized = true;
|
||||
sm_StatsTimer.Start();
|
||||
}
|
||||
|
||||
if (sm_StatsTimer.GetDurationInProgress().GetSeconds() >= sv_statsUpdateRate->GetDouble())
|
||||
{
|
||||
uint8_t nCPUPercentage = static_cast<uint8_t>(g_pServer[MAX_PLAYERS].GetCPUUsage() * 100.0f);
|
||||
SVC_ServerTick serverTick(g_pServer->GetTick(), *host_frametime_unbounded, *host_frametime_stddeviation, nCPUPercentage);
|
||||
|
||||
serverTick.m_nGroup = 0;
|
||||
serverTick.m_bReliable = 1;
|
||||
serverTick.m_NetTick.m_nCommandTick = -1; // Statistics only, see 'CClientState::VProcessServerTick'.
|
||||
|
||||
// Send individually instead of writing into snapshot buffer to avoid overflow.
|
||||
pClient->SendNetMsg(&serverTick, false, true, false);
|
||||
|
||||
// Re-run timer.
|
||||
sm_StatsTimer.Start();
|
||||
}
|
||||
}
|
||||
else // Reset timer.
|
||||
{
|
||||
if (sm_bStatsInitialized)
|
||||
{
|
||||
sm_bStatsInitialized = false;
|
||||
sm_StatsTimer.End();
|
||||
serverTick.WriteToBuffer(pMsg);
|
||||
}
|
||||
}
|
||||
#endif // !CLIENT_DLL
|
||||
|
@ -45,10 +45,6 @@ class CNetworkStringTableContainer : public INetworkStringTable
|
||||
{
|
||||
public:
|
||||
static void WriteUpdateMessage(CNetworkStringTableContainer* thisp, CClient* client, unsigned int tick_ack, bf_write* msg);
|
||||
#ifndef CLIENT_DLL
|
||||
static CFastTimer sm_StatsTimer;
|
||||
static bool sm_bStatsInitialized;
|
||||
#endif // !CLIENT_DLL
|
||||
|
||||
private:
|
||||
bool m_bAllowCreation; // create guard
|
||||
|
Loading…
x
Reference in New Issue
Block a user