Optimized usercmd network
This commit is contained in:
parent
c1e81ad97c
commit
81793ee7a4
7 changed files with 91 additions and 115 deletions
|
@ -72,9 +72,9 @@ public:
|
||||||
CBoundedCvar_CmdRate() :
|
CBoundedCvar_CmdRate() :
|
||||||
ConVar_ServerBounded(
|
ConVar_ServerBounded(
|
||||||
"cl_cmdrate",
|
"cl_cmdrate",
|
||||||
"30",
|
"100",
|
||||||
FCVAR_ARCHIVE | FCVAR_USERINFO,
|
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() :
|
CBoundedCvar_UpdateRate() :
|
||||||
ConVar_ServerBounded(
|
ConVar_ServerBounded(
|
||||||
"cl_updaterate",
|
"cl_updaterate",
|
||||||
"20",
|
"100",
|
||||||
FCVAR_ARCHIVE | FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
|
FCVAR_ARCHIVE | FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
|
||||||
"Number of packets per second of updates you are requesting from the server" )
|
"Number of packets per second of updates you are requesting from the server" )
|
||||||
{
|
{
|
||||||
|
|
|
@ -652,9 +652,6 @@ float CClientState::GetClientInterpAmount()
|
||||||
float flInterpRatio = s_cl_interp_ratio->GetFloat();
|
float flInterpRatio = s_cl_interp_ratio->GetFloat();
|
||||||
float flInterp = s_cl_interp->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
|
//#define FIXME_INTERP_RATIO
|
||||||
return max( flInterpRatio / cl_updaterate->GetFloat(), flInterp );
|
return max( flInterpRatio / cl_updaterate->GetFloat(), flInterp );
|
||||||
}
|
}
|
||||||
|
|
|
@ -588,7 +588,7 @@ jmp_buf host_enddemo;
|
||||||
static ConVar host_profile( "host_profile","0" );
|
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_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_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
|
ConVar host_speeds( "host_speeds","0", 0, "Show general system running times." ); // set for running times
|
||||||
|
|
||||||
|
|
|
@ -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,
|
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 "
|
"cl_cmdrate is moved to within sv_client_cmdrate_difference units of cl_updaterate before it "
|
||||||
"is clamped between sv_mincmdrate and sv_maxcmdrate." );
|
"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,
|
ConVar sv_client_predict( "sv_client_predict", "-1", FCVAR_REPLICATED,
|
||||||
"This can be used to force the value of cl_predict for connected clients "
|
"This can be used to force the value of cl_predict for connected clients "
|
||||||
"(only while they are connected).\n"
|
"(only while they are connected).\n"
|
||||||
|
|
|
@ -63,34 +63,7 @@ ConVar_ServerBounded *cl_predict = &cl_predict_var;
|
||||||
// cl_interp_ratio.
|
// cl_interp_ratio.
|
||||||
// ------------------------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------------------------ //
|
||||||
|
|
||||||
class CBoundedCvar_InterpRatio : public ConVar_ServerBounded
|
ConVar cl_interp_ratio("cl_interp_ratio", "2");
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------------------------ //
|
||||||
|
@ -104,7 +77,7 @@ public:
|
||||||
ConVar_ServerBounded( "cl_interp",
|
ConVar_ServerBounded( "cl_interp",
|
||||||
"-1.0",
|
"-1.0",
|
||||||
FCVAR_USERINFO,
|
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 *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
|
||||||
static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
|
if ( pUpdateRate )
|
||||||
if ( pUpdateRate && pMin && pMin->GetFloat() != -1 )
|
|
||||||
{
|
{
|
||||||
return MAX( value, pMin->GetFloat() / pUpdateRate->GetFloat() );
|
return MAX( value, cl_interp_ratio.GetFloat() / pUpdateRate->GetFloat() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -146,7 +118,7 @@ float GetClientInterpAmount()
|
||||||
if ( pUpdateRate )
|
if ( pUpdateRate )
|
||||||
{
|
{
|
||||||
// #define FIXME_INTERP_RATIO
|
// #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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1305,7 +1305,7 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send interpolated simulation time for lag compensation
|
// 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);
|
auto pEntity = ClientEntityList().GetEnt(i);
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,12 @@
|
||||||
// memdbgon must be the last include file in a .cpp file!!!
|
// memdbgon must be the last include file in a .cpp file!!!
|
||||||
#ifdef CLIENT_DLL
|
#ifdef CLIENT_DLL
|
||||||
#include "c_baseplayer.h"
|
#include "c_baseplayer.h"
|
||||||
|
#include "cliententitylist.h"
|
||||||
#else
|
#else
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#endif
|
#endif
|
||||||
#include "shareddefs.h"
|
|
||||||
#include "tier0/memdbgon.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
|
// TF2 specific, need enough space for OBJ_LAST items from tf_shareddefs.h
|
||||||
#define WEAPON_SUBTYPE_BITS 6
|
#define WEAPON_SUBTYPE_BITS 6
|
||||||
|
@ -179,7 +178,19 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
||||||
buf->WriteOneBit( 0 );
|
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)
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= entityCount; i++)
|
||||||
{
|
{
|
||||||
buf->WriteOneBit(to->has_simulation[i]);
|
buf->WriteOneBit(to->has_simulation[i]);
|
||||||
|
|
||||||
|
@ -190,8 +201,8 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
||||||
|
|
||||||
if (to->simulationtimes[i] != from->simulationtimes[i])
|
if (to->simulationtimes[i] != from->simulationtimes[i])
|
||||||
{
|
{
|
||||||
buf->WriteOneBit( 1 );
|
buf->WriteOneBit(1);
|
||||||
buf->WriteFloat( to->simulationtimes[i] );
|
buf->WriteFloat(to->simulationtimes[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -205,16 +216,19 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (to->animationdata[i].m_flUninterpolatedSimulationTime != from->animationdata[i].m_flUninterpolatedSimulationTime)
|
if (to->animationdata[i].m_flUninterpolatedSimulationTime
|
||||||
|
!= from->animationdata[i].m_flUninterpolatedSimulationTime)
|
||||||
{
|
{
|
||||||
buf->WriteOneBit( 1 );
|
buf->WriteOneBit(1);
|
||||||
buf->WriteFloat( to->animationdata[i].m_flUninterpolatedSimulationTime );
|
buf->WriteFloat(
|
||||||
|
to->animationdata[i].m_flUninterpolatedSimulationTime);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buf->WriteOneBit(0);
|
buf->WriteOneBit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( to->debug_hitboxes != from->debug_hitboxes )
|
if ( to->debug_hitboxes != from->debug_hitboxes )
|
||||||
{
|
{
|
||||||
|
@ -333,7 +347,6 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
move->random_seed = MD5_PseudoRandom( move->command_number ) & 0x7fffffff;
|
move->random_seed = MD5_PseudoRandom( move->command_number ) & 0x7fffffff;
|
||||||
|
|
||||||
if ( buf->ReadOneBit() )
|
if ( buf->ReadOneBit() )
|
||||||
|
@ -346,7 +359,11 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
||||||
move->mousedy = buf->ReadShort();
|
move->mousedy = buf->ReadShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MAX_EDICTS; i++)
|
const auto entityCount = buf->ReadSignedVarInt32();
|
||||||
|
|
||||||
|
if (entityCount > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= entityCount; i++)
|
||||||
{
|
{
|
||||||
// Has simulation ?
|
// Has simulation ?
|
||||||
move->has_simulation[i] = buf->ReadOneBit();
|
move->has_simulation[i] = buf->ReadOneBit();
|
||||||
|
@ -371,7 +388,9 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
||||||
|
|
||||||
if (buf->ReadOneBit())
|
if (buf->ReadOneBit())
|
||||||
{
|
{
|
||||||
move->animationdata[i].m_flUninterpolatedSimulationTime = buf->ReadFloat();
|
move->animationdata[i].m_flUninterpolatedSimulationTime = buf
|
||||||
|
->ReadFloat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue