css_enhanced_waf/game/client/cdll_bounded_cvars.cpp

134 lines
3.2 KiB
C++
Raw Normal View History

2020-04-22 17:56:21 +01:00
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "cbase.h"
#include "cdll_bounded_cvars.h"
#include "cdll_client_int.h"
2020-04-22 17:56:21 +01:00
#include "convar_serverbounded.h"
2024-01-25 12:27:03 +00:00
#include "icvar.h"
#include "shareddefs.h"
2020-04-22 17:56:21 +01:00
#include "tier0/icommandline.h"
bool g_bForceCLPredictOff = false;
// ------------------------------------------------------------------------------------------ //
// cl_predict.
// ------------------------------------------------------------------------------------------ //
class CBoundedCvar_Predict : public ConVar_ServerBounded
{
public:
CBoundedCvar_Predict() :
ConVar_ServerBounded( "cl_predict",
2024-01-25 12:27:03 +00:00
"1.0",
2020-04-22 17:56:21 +01:00
#if defined(DOD_DLL) || defined(CSTRIKE_DLL)
FCVAR_USERINFO | FCVAR_CHEAT,
#else
FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
#endif
"Perform client side prediction." )
{
}
virtual float GetFloat() const
{
// Used temporarily for CS kill cam.
if ( g_bForceCLPredictOff )
return 0;
static const ConVar *pClientPredict = g_pCVar->FindVar( "sv_client_predict" );
if ( pClientPredict && pClientPredict->GetInt() != -1 )
{
// Ok, the server wants to control this value.
return pClientPredict->GetFloat();
}
else
{
return GetBaseFloatValue();
}
}
};
static CBoundedCvar_Predict cl_predict_var;
ConVar_ServerBounded *cl_predict = &cl_predict_var;
// ------------------------------------------------------------------------------------------ //
// cl_interp_ratio.
// ------------------------------------------------------------------------------------------ //
2024-07-16 04:13:14 +01:00
ConVar cl_interp_ratio("cl_interp_ratio", "2");
2020-04-22 17:56:21 +01:00
// ------------------------------------------------------------------------------------------ //
// cl_interp
// ------------------------------------------------------------------------------------------ //
class CBoundedCvar_Interp : public ConVar_ServerBounded
{
public:
CBoundedCvar_Interp() :
ConVar_ServerBounded( "cl_interp",
"-1.0",
FCVAR_USERINFO,
2024-07-16 04:13:14 +01:00
"Sets the interpolation amount (bounded on low side by server interp ratio settings).", true, -1.0f, true, 1.0f )
2020-04-22 17:56:21 +01:00
{
}
virtual float GetFloat() const
{
float value = GetBaseFloatValue();
if (value < 0.0f)
{
value = TICK_INTERVAL;
}
2020-04-22 17:56:21 +01:00
static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
2024-07-16 04:13:14 +01:00
if ( pUpdateRate )
2020-04-22 17:56:21 +01:00
{
2024-07-16 04:13:14 +01:00
return MAX( value, cl_interp_ratio.GetFloat() / pUpdateRate->GetFloat() );
2020-04-22 17:56:21 +01:00
}
else
{
return value;
2020-04-22 17:56:21 +01:00
}
}
};
static CBoundedCvar_Interp cl_interp_var;
ConVar_ServerBounded *cl_interp = &cl_interp_var;
float GetClientInterpAmount()
{
2024-01-25 12:27:03 +00:00
static const ConVar *cl_interpolate = g_pCVar->FindVar("cl_interpolate");
2020-04-22 17:56:21 +01:00
static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
2024-01-25 12:27:03 +00:00
if (!cl_interpolate->GetBool())
{
return 0.0f;
}
2020-04-22 17:56:21 +01:00
if ( pUpdateRate )
{
// #define FIXME_INTERP_RATIO
2024-07-16 04:13:14 +01:00
return MAX( cl_interp->GetFloat(), cl_interp_ratio.GetFloat() / pUpdateRate->GetFloat() );
2020-04-22 17:56:21 +01:00
}
else
{
2022-03-01 20:00:42 +00:00
if (!CommandLine()->FindParm("-hushasserts"))
2020-04-22 17:56:21 +01:00
{
AssertMsgOnce( false, "GetInterpolationAmount: can't get cl_updaterate cvar." );
}
2024-01-25 12:27:03 +00:00
return 0.1f;
2020-04-22 17:56:21 +01:00
}
}