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.

99 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "replaysystem.h"
  5. #include "cl_replaymanager.h"
  6. // memdbgon must be the last include file in a .cpp file!!!
  7. #include "tier0/memdbgon.h"
  8. //----------------------------------------------------------------------------------------
  9. void OnReplayEnableChanged( IConVar *pVar, const char *pOldValue, float flOldValue );
  10. void OnReplayRecordingChanged( IConVar *pVar, const char *pOldValue, float flOldValue );
  11. //----------------------------------------------------------------------------------------
  12. // Replicated
  13. ConVar replay_enable( "replay_enable", "0", FCVAR_REPLICATED | FCVAR_DONTRECORD, "Enable Replay recording on server", true, 0, true, 1, OnReplayEnableChanged );
  14. ConVar replay_recording( "replay_recording", "0", FCVAR_REPLICATED | FCVAR_DONTRECORD | FCVAR_HIDDEN, "", true, 0, true, 1, OnReplayRecordingChanged );
  15. ConVar replay_flushinterval( "replay_flushinterval", "15", FCVAR_DONTRECORD | FCVAR_ARCHIVE, "Replay system will flush to disk a maximum of every replay_flushinterval seconds.", true, 1.0f, true, 60.0f );
  16. //----------------------------------------------------------------------------------------
  17. //
  18. // A little class to keep OnReplayEnableChanged() from recursing unnecessarily
  19. //
  20. class CSimpleCounter
  21. {
  22. public:
  23. CSimpleCounter() { ++m_nCounter; }
  24. ~CSimpleCounter() { --m_nCounter; }
  25. int GetCounter() const { return m_nCounter; }
  26. private:
  27. static int m_nCounter;
  28. };
  29. int CSimpleCounter::m_nCounter = 0;
  30. //----------------------------------------------------------------------------------------
  31. void OnReplayEnableChanged( IConVar *pVar, const char *pOldValue, float flOldValue )
  32. {
  33. // We want to avoid recursing when we SetValue() on replay_enable (ie 'var')
  34. CSimpleCounter counter;
  35. if ( counter.GetCounter() != 1 )
  36. return;
  37. if ( !g_pEngine->IsDedicated() )
  38. return;
  39. ConVarRef var( pVar );
  40. if ( (int)flOldValue == var.GetInt() )
  41. return;
  42. /*
  43. ConVarRef tv_enable( "tv_enable" );
  44. if ( var.GetBool() && tv_enable.IsValid() && tv_enable.GetBool() )
  45. {
  46. var.SetValue( 0 );
  47. Warning( "Error: SourceTV is enabled. Please disable SourceTV if you wish to enable Replay.\n" );
  48. return;
  49. }
  50. */
  51. const int nNewValue = var.GetInt();
  52. if ( nNewValue )
  53. {
  54. g_pServerReplayContext->FlagForConVarSanityCheck();
  55. }
  56. else
  57. {
  58. // Reset value - note that the recursion depth counter will keep this from being dumb.
  59. var.SetValue( 0 );
  60. // End recording, which will clear the value again.
  61. g_pReplay->SV_EndRecordingSession( false );
  62. }
  63. g_pEngine->RecalculateTags();
  64. }
  65. void OnReplayRecordingChanged( IConVar *pVar, const char *pOldValue, float flOldValue )
  66. {
  67. if ( g_pEngine->IsDedicated() )
  68. return;
  69. #if !defined( DEDICATED )
  70. // If we're playing back a replay, we don't care
  71. if ( g_pEngineClient->IsPlayingReplayDemo() )
  72. return;
  73. // Client-only
  74. CL_GetReplayManager()->OnReplayRecordingCvarChanged();
  75. #endif
  76. }