Optimized usercmd network

This commit is contained in:
Kamay Xutax 2024-07-16 05:13:14 +02:00
parent c1e81ad97c
commit 81793ee7a4
7 changed files with 91 additions and 115 deletions

View file

@ -72,9 +72,9 @@ public:
CBoundedCvar_CmdRate() :
ConVar_ServerBounded(
"cl_cmdrate",
"30",
"100",
FCVAR_ARCHIVE | FCVAR_USERINFO,
"Max number of command packets sent to server per second", true, MIN_CMD_RATE, true, MAX_CMD_RATE )
"Max number of command packets sent to server per second", true, MIN_CMD_RATE, true, 1000.0f )
{
}
@ -119,7 +119,7 @@ public:
CBoundedCvar_UpdateRate() :
ConVar_ServerBounded(
"cl_updaterate",
"20",
"100",
FCVAR_ARCHIVE | FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
"Number of packets per second of updates you are requesting from the server" )
{

View file

@ -652,9 +652,6 @@ float CClientState::GetClientInterpAmount()
float flInterpRatio = s_cl_interp_ratio->GetFloat();
float flInterp = s_cl_interp->GetFloat();
const ConVar_ServerBounded *pBounded = static_cast<const ConVar_ServerBounded*>( s_cl_interp_ratio );
if ( pBounded )
flInterpRatio = pBounded->GetFloat();
//#define FIXME_INTERP_RATIO
return max( flInterpRatio / cl_updaterate->GetFloat(), flInterp );
}

View file

@ -588,7 +588,7 @@ jmp_buf host_enddemo;
static ConVar host_profile( "host_profile","0" );
ConVar host_limitlocal( "host_limitlocal", "0", 0, "Apply cl_cmdrate and cl_updaterate to loopback connection" );
ConVar host_framerate( "host_framerate","0", 0, "Set to lock per-frame time elapse." );
ConVar host_framerate( "host_framerate","0", FCVAR_REPLICATED, "Set to lock per-frame time elapse." );
ConVar host_timescale( "host_timescale","1.0", FCVAR_REPLICATED, "Prescale the clock by this amount." );
ConVar host_speeds( "host_speeds","0", 0, "Show general system running times." ); // set for running times

View file

@ -223,18 +223,6 @@ ConVar sv_maxcmdrate( "sv_maxcmdrate", "100", FCVAR_REPLICATED, "(If sv_mincmdr
ConVar sv_client_cmdrate_difference( "sv_client_cmdrate_difference", "20", FCVAR_REPLICATED,
"cl_cmdrate is moved to within sv_client_cmdrate_difference units of cl_updaterate before it "
"is clamped between sv_mincmdrate and sv_maxcmdrate." );
ConVar sv_client_min_interp_ratio( "sv_client_min_interp_ratio", "1", FCVAR_REPLICATED,
"This can be used to limit the value of cl_interp_ratio for connected clients "
"(only while they are connected).\n"
" -1 = let clients set cl_interp_ratio to anything\n"
" any other value = set minimum value for cl_interp_ratio"
);
ConVar sv_client_max_interp_ratio( "sv_client_max_interp_ratio", "5", FCVAR_REPLICATED,
"This can be used to limit the value of cl_interp_ratio for connected clients "
"(only while they are connected). If sv_client_min_interp_ratio is -1, "
"then this cvar has no effect."
);
ConVar sv_client_predict( "sv_client_predict", "-1", FCVAR_REPLICATED,
"This can be used to force the value of cl_predict for connected clients "
"(only while they are connected).\n"

View file

@ -63,34 +63,7 @@ ConVar_ServerBounded *cl_predict = &cl_predict_var;
// cl_interp_ratio.
// ------------------------------------------------------------------------------------------ //
class CBoundedCvar_InterpRatio : public ConVar_ServerBounded
{
public:
CBoundedCvar_InterpRatio() :
ConVar_ServerBounded( "cl_interp_ratio",
"2.0",
FCVAR_USERINFO,
"Sets the interpolation amount (final amount is cl_interp_ratio / cl_updaterate)." )
{
}
virtual float GetFloat() const
{
static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
static const ConVar *pMax = g_pCVar->FindVar( "sv_client_max_interp_ratio" );
if ( pMin && pMax && pMin->GetFloat() != -1 )
{
return clamp( GetBaseFloatValue(), pMin->GetFloat(), pMax->GetFloat() );
}
else
{
return GetBaseFloatValue();
}
}
};
static CBoundedCvar_InterpRatio cl_interp_ratio_var;
ConVar_ServerBounded *cl_interp_ratio = &cl_interp_ratio_var;
ConVar cl_interp_ratio("cl_interp_ratio", "2");
// ------------------------------------------------------------------------------------------ //
@ -104,7 +77,7 @@ public:
ConVar_ServerBounded( "cl_interp",
"-1.0",
FCVAR_USERINFO,
"Sets the interpolation amount (bounded on low side by server interp ratio settings).", true, -1.0f, true, 0.5f )
"Sets the interpolation amount (bounded on low side by server interp ratio settings).", true, -1.0f, true, 1.0f )
{
}
@ -118,10 +91,9 @@ public:
}
static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
if ( pUpdateRate && pMin && pMin->GetFloat() != -1 )
if ( pUpdateRate )
{
return MAX( value, pMin->GetFloat() / pUpdateRate->GetFloat() );
return MAX( value, cl_interp_ratio.GetFloat() / pUpdateRate->GetFloat() );
}
else
{
@ -146,7 +118,7 @@ float GetClientInterpAmount()
if ( pUpdateRate )
{
// #define FIXME_INTERP_RATIO
return MAX( cl_interp->GetFloat(), cl_interp_ratio->GetFloat() / pUpdateRate->GetFloat() );
return MAX( cl_interp->GetFloat(), cl_interp_ratio.GetFloat() / pUpdateRate->GetFloat() );
}
else
{

View file

@ -1305,7 +1305,7 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo
}
// Send interpolated simulation time for lag compensation
for (int i = 0; i <= gpGlobals->maxClients; i++)
for (int i = 0; i <= ClientEntityList().GetHighestEntityIndex(); i++)
{
auto pEntity = ClientEntityList().GetEnt(i);

View file

@ -15,13 +15,12 @@
// memdbgon must be the last include file in a .cpp file!!!
#ifdef CLIENT_DLL
#include "c_baseplayer.h"
#include "cliententitylist.h"
#else
#include "player.h"
#endif
#include "shareddefs.h"
#include "tier0/memdbgon.h"
#include "util_shared.h"
#include "utlvector.h"
// TF2 specific, need enough space for OBJ_LAST items from tf_shareddefs.h
#define WEAPON_SUBTYPE_BITS 6
@ -179,44 +178,59 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
buf->WriteOneBit( 0 );
}
for (int i = 0; i < MAX_EDICTS; i++)
int entityCount = 0;
#ifdef CLIENT_DLL
if (cl_entitylist)
entityCount = cl_entitylist->GetHighestEntityIndex();
#else
entityCount = MAX_EDICTS;
#endif
buf->WriteSignedVarInt32(entityCount);
if (entityCount > 0)
{
buf->WriteOneBit(to->has_simulation[i]);
if (!to->has_simulation[i])
for (int i = 0; i <= entityCount; i++)
{
continue;
}
buf->WriteOneBit(to->has_simulation[i]);
if (to->simulationtimes[i] != from->simulationtimes[i])
{
buf->WriteOneBit( 1 );
buf->WriteFloat( to->simulationtimes[i] );
}
else
{
buf->WriteOneBit(0);
if (!to->has_simulation[i])
{
continue;
}
if (to->simulationtimes[i] != from->simulationtimes[i])
{
buf->WriteOneBit(1);
buf->WriteFloat(to->simulationtimes[i]);
}
else
{
buf->WriteOneBit(0);
}
buf->WriteOneBit(to->has_animation[i]);
if (!to->has_animation[i])
{
continue;
}
if (to->animationdata[i].m_flUninterpolatedSimulationTime
!= from->animationdata[i].m_flUninterpolatedSimulationTime)
{
buf->WriteOneBit(1);
buf->WriteFloat(
to->animationdata[i].m_flUninterpolatedSimulationTime);
}
else
{
buf->WriteOneBit(0);
}
}
}
buf->WriteOneBit(to->has_animation[i]);
if (!to->has_animation[i])
{
continue;
}
if (to->animationdata[i].m_flUninterpolatedSimulationTime != from->animationdata[i].m_flUninterpolatedSimulationTime)
{
buf->WriteOneBit( 1 );
buf->WriteFloat( to->animationdata[i].m_flUninterpolatedSimulationTime );
}
else
{
buf->WriteOneBit(0);
}
}
if ( to->debug_hitboxes != from->debug_hitboxes )
if ( to->debug_hitboxes != from->debug_hitboxes )
{
buf->WriteOneBit( 1 );
buf->WriteByte( to->debug_hitboxes );
@ -333,7 +347,6 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
}
}
move->random_seed = MD5_PseudoRandom( move->command_number ) & 0x7fffffff;
if ( buf->ReadOneBit() )
@ -346,36 +359,42 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
move->mousedy = buf->ReadShort();
}
for (int i = 0; i < MAX_EDICTS; i++)
const auto entityCount = buf->ReadSignedVarInt32();
if (entityCount > 0)
{
// Has simulation ?
move->has_simulation[i] = buf->ReadOneBit();
if (!move->has_simulation[i])
for (int i = 0; i <= entityCount; i++)
{
continue;
}
// Has simulation ?
move->has_simulation[i] = buf->ReadOneBit();
if (buf->ReadOneBit())
{
move->simulationtimes[i] = buf->ReadFloat();
if (!move->has_simulation[i])
{
continue;
}
if (buf->ReadOneBit())
{
move->simulationtimes[i] = buf->ReadFloat();
}
// Has animation ?
move->has_animation[i] = buf->ReadOneBit();
if (!move->has_animation[i])
{
continue;
}
if (buf->ReadOneBit())
{
move->animationdata[i].m_flUninterpolatedSimulationTime = buf
->ReadFloat();
}
}
}
// Has animation ?
move->has_animation[i] = buf->ReadOneBit();
if (!move->has_animation[i])
{
continue;
}
if (buf->ReadOneBit())
{
move->animationdata[i].m_flUninterpolatedSimulationTime = buf->ReadFloat();
}
}
if ( buf->ReadOneBit() )
if ( buf->ReadOneBit() )
{
move->debug_hitboxes = (CUserCmd::debug_hitboxes_t)buf->ReadByte();
}