Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "cdll_bounded_cvars.h"
  9. #include "convar_serverbounded.h"
  10. #include "tier0/icommandline.h"
  11. bool g_bForceCLPredictOff = false;
  12. // ------------------------------------------------------------------------------------------ //
  13. // cl_predict.
  14. // ------------------------------------------------------------------------------------------ //
  15. class CBoundedCvar_Predict : public ConVar_ServerBounded
  16. {
  17. public:
  18. CBoundedCvar_Predict() :
  19. ConVar_ServerBounded( "cl_predict",
  20. "1.0",
  21. #if defined(DOD_DLL) || defined(CSTRIKE_DLL)
  22. FCVAR_USERINFO | FCVAR_CHEAT,
  23. #else
  24. FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
  25. #endif
  26. "Perform client side prediction." )
  27. {
  28. }
  29. virtual float GetFloat() const
  30. {
  31. // Used temporarily for CS kill cam.
  32. if ( g_bForceCLPredictOff )
  33. return 0;
  34. static const ConVar *pClientPredict = g_pCVar->FindVar( "sv_client_predict" );
  35. if ( pClientPredict && pClientPredict->GetInt() != -1 )
  36. {
  37. // Ok, the server wants to control this value.
  38. return pClientPredict->GetFloat();
  39. }
  40. else
  41. {
  42. return GetBaseFloatValue();
  43. }
  44. }
  45. };
  46. static CBoundedCvar_Predict cl_predict_var;
  47. ConVar_ServerBounded *cl_predict = &cl_predict_var;
  48. // ------------------------------------------------------------------------------------------ //
  49. // cl_interp_ratio.
  50. // ------------------------------------------------------------------------------------------ //
  51. class CBoundedCvar_InterpRatio : public ConVar_ServerBounded
  52. {
  53. public:
  54. CBoundedCvar_InterpRatio() :
  55. ConVar_ServerBounded( "cl_interp_ratio",
  56. "2.0",
  57. FCVAR_USERINFO | FCVAR_NOT_CONNECTED | FCVAR_ARCHIVE,
  58. "Sets the interpolation amount (final amount is cl_interp_ratio / cl_updaterate)." )
  59. {
  60. }
  61. virtual float GetFloat() const
  62. {
  63. static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
  64. static const ConVar *pMax = g_pCVar->FindVar( "sv_client_max_interp_ratio" );
  65. if ( pMin && pMax && pMin->GetFloat() != -1 )
  66. {
  67. return clamp( GetBaseFloatValue(), pMin->GetFloat(), pMax->GetFloat() );
  68. }
  69. else
  70. {
  71. return GetBaseFloatValue();
  72. }
  73. }
  74. };
  75. static CBoundedCvar_InterpRatio cl_interp_ratio_var;
  76. ConVar_ServerBounded *cl_interp_ratio = &cl_interp_ratio_var;
  77. // ------------------------------------------------------------------------------------------ //
  78. // cl_interp
  79. // ------------------------------------------------------------------------------------------ //
  80. class CBoundedCvar_Interp : public ConVar_ServerBounded
  81. {
  82. public:
  83. CBoundedCvar_Interp() :
  84. ConVar_ServerBounded( "cl_interp",
  85. "0.1",
  86. FCVAR_USERINFO | FCVAR_NOT_CONNECTED | FCVAR_ARCHIVE,
  87. "Sets the interpolation amount (bounded on low side by server interp ratio settings).", true, 0.0f, true, 0.5f )
  88. {
  89. }
  90. virtual float GetFloat() const
  91. {
  92. static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
  93. static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
  94. if ( pUpdateRate && pMin && pMin->GetFloat() != -1 )
  95. {
  96. return MAX( GetBaseFloatValue(), pMin->GetFloat() / pUpdateRate->GetFloat() );
  97. }
  98. else
  99. {
  100. return GetBaseFloatValue();
  101. }
  102. }
  103. };
  104. static CBoundedCvar_Interp cl_interp_var;
  105. ConVar_ServerBounded *cl_interp = &cl_interp_var;
  106. float GetClientInterpAmount()
  107. {
  108. static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
  109. if ( pUpdateRate )
  110. {
  111. // #define FIXME_INTERP_RATIO
  112. return MAX( cl_interp->GetFloat(), cl_interp_ratio->GetFloat() / pUpdateRate->GetFloat() );
  113. }
  114. else
  115. {
  116. if ( !HushAsserts() )
  117. {
  118. AssertMsgOnce( false, "GetInterpolationAmount: can't get cl_updaterate cvar." );
  119. }
  120. return 0.1;
  121. }
  122. }