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.

128 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #ifndef CL_REPLAYMANAGER_H
  5. #define CL_REPLAYMANAGER_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //----------------------------------------------------------------------------------------
  10. #include "genericpersistentmanager.h"
  11. #include "replay/ireplaymanager.h"
  12. #include "cl_replaycontext.h"
  13. #include "replay/replay.h"
  14. //----------------------------------------------------------------------------------------
  15. class IReplayFactory;
  16. //----------------------------------------------------------------------------------------
  17. //
  18. // Manages and serializes all replays on the client.
  19. //
  20. class CReplayManager : public CGenericPersistentManager< CReplay >,
  21. public IReplayManager
  22. {
  23. typedef CGenericPersistentManager< CReplay > BaseClass;
  24. public:
  25. CReplayManager();
  26. ~CReplayManager();
  27. virtual bool Init( CreateInterfaceFn fnCreateFactory );
  28. void Shutdown();
  29. void OnSessionStart();
  30. void OnSessionEnd();
  31. int GetNumReplaysDependentOnSession( ReplayHandle_t hSession );
  32. // IReplayManager
  33. virtual CReplay *GetReplay( ReplayHandle_t hReplay );
  34. virtual void FlagReplayForFlush( CReplay *pReplay, bool bForceImmediate );
  35. virtual int GetUnrenderedReplayCount();
  36. virtual void DeleteReplay( ReplayHandle_t hReplay, bool bNotifyUI );
  37. virtual CReplay *GetPlayingReplay();
  38. virtual CReplay *GetReplayForCurrentLife();
  39. virtual void GetReplays( CUtlLinkedList< CReplay *, int > &lstReplays );
  40. virtual void GetReplaysAsQueryableItems( CUtlLinkedList< IQueryableReplayItem *, int > &lstReplays );
  41. virtual int GetReplayCount() const { return Count(); }
  42. virtual float GetDownloadProgress( const CReplay *pReplay );
  43. virtual const char *GetReplaysDir() const;
  44. void CommitPendingReplayAndBeginDownload();
  45. void CompletePendingReplay();
  46. void AddEventsForListen();
  47. void ClearPendingReplay();
  48. void SanityCheckReplay( CReplay *pReplay );
  49. void SaveDanglingReplay();
  50. void OnClientSideDisconnect();
  51. inline ObjContainer_t &Replays() { return m_vecObjs; }
  52. bool Commit( CReplay *pNewReplay );
  53. void UpdateCurrentReplayDataFromServer();
  54. void OnReplayRecordingCvarChanged();
  55. void AttemptToSetupNewReplay();
  56. CReplay *m_pReplayThisLife; // Valid only between replay completion (ie player death) and player respawn, otherwise NULL
  57. //
  58. // CGenericPersistentManager
  59. //
  60. virtual const char *GetRelativeIndexPath() const;
  61. private:
  62. //
  63. // CGenericPersistentManager
  64. //
  65. virtual const char *GetDebugName() const { return "replay manager"; }
  66. virtual const char *GetIndexFilename() const { return "replays." GENERIC_FILE_EXTENSION; }
  67. virtual CReplay *Create();
  68. virtual int GetVersion() const;
  69. virtual void Think();
  70. virtual IReplayContext *GetReplayContext() const;
  71. virtual bool ShouldLoadObj( const CReplay *pReplay ) const;
  72. virtual void OnObjLoaded( CReplay *pReplay );
  73. //
  74. // CBaseThinker
  75. //
  76. virtual float GetNextThinkTime() const;
  77. void DebugThink();
  78. void InitReplay( CReplay *pReplay );
  79. IReplayFactory *GetReplayFactory( CreateInterfaceFn fnCreateFactory );
  80. void CleanupReplay( CReplay *&pReplay );
  81. void FreeLifeIfNotSaved( CReplay *&pReplay );
  82. CReplay *CreatePendingReplay();
  83. CReplay *m_pPendingReplay; // This is the replay we're currently recording - one which will
  84. // either be committed (via Commit()) or not, depending on whether
  85. // the player chooses to save the replay.
  86. CReplay *m_pReplayLastLife; // The previous life (ie between the player's previous spawn and the current spawn), if any (otherwise NULL)
  87. float m_flPlayerSpawnCreateReplayFailTime;
  88. IReplayFactory *m_pReplayFactory;
  89. };
  90. //----------------------------------------------------------------------------------------
  91. inline CReplay *GetReplay( ReplayHandle_t hReplay )
  92. {
  93. extern CClientReplayContext *g_pClientReplayContextInternal;
  94. return g_pClientReplayContextInternal->m_pReplayManager->GetReplay( hReplay );
  95. }
  96. //----------------------------------------------------------------------------------------
  97. #define FOR_EACH_REPLAY( _i ) FOR_EACH_OBJ( CL_GetReplayManager(), _i )
  98. #define GET_REPLAY_AT( _i ) CL_GetReplayManager()->m_vecObjs[ _i ]
  99. //----------------------------------------------------------------------------------------
  100. #endif // CL_REPLAYMANAGER_H