Counter Strike : Global Offensive Source Code
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.

150 lines
4.3 KiB

  1. //===== Copyright � 1996-2005, 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. // NOTE: This has to be the last file included!
  12. #include "tier0/memdbgon.h"
  13. bool g_bForceCLPredictOff = false;
  14. bool g_bSpectatingForceCLPredictOff = false;
  15. // ------------------------------------------------------------------------------------------ //
  16. // cl_predict.
  17. // ------------------------------------------------------------------------------------------ //
  18. class CBoundedCvar_Predict : public ConVar_ServerBounded
  19. {
  20. public:
  21. CBoundedCvar_Predict() :
  22. ConVar_ServerBounded( "cl_predict",
  23. "1.0",
  24. FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
  25. "Perform client side prediction." )
  26. {
  27. }
  28. virtual float GetFloat() const
  29. {
  30. // Used temporarily for CS kill cam.
  31. if ( g_bForceCLPredictOff || g_bSpectatingForceCLPredictOff )
  32. return 0;
  33. static const ConVar *pClientPredict = g_pCVar->FindVar( "sv_client_predict" );
  34. if ( pClientPredict && pClientPredict->GetInt() != -1 )
  35. {
  36. // Ok, the server wants to control this value.
  37. return pClientPredict->GetFloat();
  38. }
  39. else
  40. {
  41. return GetBaseFloatValue();
  42. }
  43. }
  44. };
  45. static CBoundedCvar_Predict cl_predict_var;
  46. ConVar_ServerBounded *cl_predict = &cl_predict_var;
  47. // ------------------------------------------------------------------------------------------ //
  48. // cl_interp_ratio.
  49. // ------------------------------------------------------------------------------------------ //
  50. class CBoundedCvar_InterpRatio : public ConVar_ServerBounded
  51. {
  52. public:
  53. CBoundedCvar_InterpRatio() :
  54. ConVar_ServerBounded( "cl_interp_ratio",
  55. "2.0",
  56. FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
  57. "Sets the interpolation amount (final amount is cl_interp_ratio / cl_updaterate)." )
  58. {
  59. }
  60. virtual float GetFloat() const
  61. {
  62. static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
  63. static const ConVar *pMax = g_pCVar->FindVar( "sv_client_max_interp_ratio" );
  64. float flBaseFloatValue = GetBaseFloatValue();
  65. if ( engine->IsPlayingDemo() && engine->GetDemoPlaybackParameters() )
  66. flBaseFloatValue = 2.0f; // use the default value when playing demos
  67. if ( pMin && pMax && pMin->GetFloat() != -1 )
  68. {
  69. return clamp( flBaseFloatValue, pMin->GetFloat(), pMax->GetFloat() );
  70. }
  71. else
  72. {
  73. return flBaseFloatValue;
  74. }
  75. }
  76. };
  77. static CBoundedCvar_InterpRatio cl_interp_ratio_var;
  78. ConVar_ServerBounded *cl_interp_ratio = &cl_interp_ratio_var;
  79. // ------------------------------------------------------------------------------------------ //
  80. // cl_interp
  81. // ------------------------------------------------------------------------------------------ //
  82. class CBoundedCvar_Interp : public ConVar_ServerBounded
  83. {
  84. public:
  85. CBoundedCvar_Interp() :
  86. ConVar_ServerBounded( "cl_interp",
  87. "0.03125", // 2 / 102.4
  88. FCVAR_USERINFO | FCVAR_NOT_CONNECTED,
  89. "Sets the interpolation amount (bounded on low side by server interp ratio settings).", true, 0.0f, true, 0.5f )
  90. {
  91. }
  92. virtual float GetFloat() const
  93. {
  94. static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
  95. static const ConVar *pMin = g_pCVar->FindVar( "sv_client_min_interp_ratio" );
  96. float flBaseFloatValue = GetBaseFloatValue();
  97. if ( engine->IsPlayingDemo() && engine->GetDemoPlaybackParameters() && pUpdateRate )
  98. flBaseFloatValue = 2.0f / pUpdateRate->GetFloat(); // use a default value 2/updaterate when playing demos
  99. if ( pUpdateRate && pMin && pMin->GetFloat() != -1 )
  100. {
  101. return MAX( flBaseFloatValue, pMin->GetFloat() / pUpdateRate->GetFloat() );
  102. }
  103. else
  104. {
  105. return flBaseFloatValue;
  106. }
  107. }
  108. };
  109. static CBoundedCvar_Interp cl_interp_var;
  110. ConVar_ServerBounded *cl_interp = &cl_interp_var;
  111. float GetClientInterpAmount()
  112. {
  113. static const ConVar *pUpdateRate = g_pCVar->FindVar( "cl_updaterate" );
  114. if ( pUpdateRate )
  115. {
  116. // #define FIXME_INTERP_RATIO
  117. float interp = cl_interp_ratio->GetFloat() / pUpdateRate->GetFloat();
  118. return interp;
  119. }
  120. else
  121. {
  122. AssertMsgOnce( false, "GetInterpolationAmount: can't get cl_updaterate cvar." );
  123. return 0.1f;
  124. }
  125. }