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.

145 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #ifndef REPLAY_H
  5. #define REPLAY_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //----------------------------------------------------------------------------------------
  10. #include "replay/iqueryablereplayitem.h"
  11. #include "replay/replaytime.h"
  12. #include "replay/basereplayserializeable.h"
  13. #include "qlimits.h"
  14. #include "utlstring.h"
  15. #include "utlvector.h"
  16. #include "replay/shared_defs.h"
  17. //----------------------------------------------------------------------------------------
  18. class IReplayDownloadEventHandler;
  19. class CReplayScreenshot;
  20. class CReplayPerformance;
  21. //----------------------------------------------------------------------------------------
  22. class CReplay : public CBaseReplaySerializeable,
  23. public IQueryableReplayItem
  24. {
  25. typedef CBaseReplaySerializeable BaseClass;
  26. public:
  27. enum ReplayStatus_t
  28. {
  29. REPLAYSTATUS_INVALID,
  30. REPLAYSTATUS_ERROR,
  31. REPLAYSTATUS_DOWNLOADPHASE, // Multiple sub-states during download state
  32. REPLAYSTATUS_READYTOCONVERT, // Download is complete, ready to convert
  33. REPLAYSTATUS_RENDERING, // Currently rendering the file
  34. REPLAYSTATUS_RENDERED,
  35. REPLAYSTATUS_MAX
  36. };
  37. CReplay();
  38. virtual ~CReplay() {}
  39. //
  40. // IReplaySerializeable
  41. //
  42. virtual const char *GetSubKeyTitle() const;
  43. virtual const char *GetPath() const;
  44. virtual void OnDelete();
  45. virtual bool Read( KeyValues *pIn );
  46. virtual void Write( KeyValues *pOut );
  47. virtual void DumpGameSpecificData() const {}
  48. virtual void Update() {}
  49. // Hooks to allow replays to setup event listeners, etc.
  50. virtual void OnBeginRecording() {}
  51. virtual void OnEndRecording() {}
  52. // Called when a replay is "completed"
  53. virtual void OnComplete();
  54. // Should we allow this replay to be deleted?
  55. virtual bool ShouldAllowDelete() const { return true; }
  56. void AutoNameTitleIfEmpty();
  57. void AddScreenshot( int nWidth, int nHeight, const char *pBaseFilename );
  58. bool HasReconstructedReplay() const;
  59. bool IsSignificantBlock( int iBlockReconstruction ) const; // Does this replay care about the given block?
  60. CReplayPerformance *AddNewPerformance( bool bGenTitle = true, bool bGenFilename = true );
  61. void AddPerformance( KeyValues *pIn );
  62. void AddPerformance( CReplayPerformance *pPerformance );
  63. // Accessors:
  64. inline int GetScreenshotCount() const { return m_vecScreenshots.Count(); }
  65. inline const CReplayScreenshot *GetScreenshot( int i ) const { return m_vecScreenshots[ i ]; }
  66. bool IsDownloaded() const;
  67. inline int GetPerformanceCount() const { return m_vecPerformances.Count(); }
  68. CReplayPerformance *GetPerformance( int i );
  69. const CReplayPerformance *GetPerformance( int i ) const;
  70. inline bool HasPerformance( CReplayPerformance *pPerformance ) { return m_vecPerformances.Find( pPerformance ) != m_vecPerformances.InvalidIndex(); }
  71. bool FindPerformance( CReplayPerformance *pPerformance, int &iResult );
  72. CReplayPerformance *GetPerformanceWithTitle( const wchar_t *pTitle );
  73. inline const char *GetMapName() const { return m_szMapName; }
  74. inline int GetSpawnTick() const { return m_nSpawnTick; }
  75. inline int GetDeathTick() const { return m_nDeathTick; }
  76. // IQueryableReplayItem implementation:
  77. virtual const CReplayTime &GetItemDate() const;
  78. virtual bool IsItemRendered() const;
  79. virtual CReplay *GetItemReplay();
  80. virtual ReplayHandle_t GetItemReplayHandle() const;
  81. virtual QueryableReplayItemHandle_t GetItemHandle() const;
  82. virtual const wchar_t *GetItemTitle() const;
  83. virtual void SetItemTitle( const wchar_t *pTitle );
  84. virtual float GetItemLength() const;
  85. virtual void *GetUserData();
  86. virtual void SetUserData( void* pUserData );
  87. virtual bool IsItemAMovie() const;
  88. // Non-persistent data
  89. mutable IReplayDownloadEventHandler *m_pDownloadEventHandler; // Implemented by replay browser - the reason we've got one per replay rather than
  90. // one per download group is because the browser needs to receive events per-thumbnail
  91. bool m_bSaved; // True as soon as the replay is saved to disk for the first time
  92. bool m_bRequestedByUser; // Did the user request to save this replay?
  93. bool m_bComplete; // Indicates whether the replay is done recording - this should be false
  94. // until the player dies, the round ends, or the level changes
  95. void *m_pUserData;
  96. float m_flNextUpdateTime;
  97. bool m_bDirty;
  98. // Persistent data
  99. ReplayHandle_t m_hSession; // The recording session in which this replay was recorded
  100. char m_szMapName[MAX_OSPATH];
  101. ReplayStatus_t m_nStatus;
  102. const char* m_pFileURL; // In the form <protocol>://<server address>:<port number>/path/file - points to the string in the download group
  103. wchar_t m_wszTitle[MAX_REPLAY_TITLE_LENGTH];
  104. CUtlString m_strKilledBy; // Name of player who killed, if any
  105. int m_nDeathTime;
  106. int m_nSpawnTick;
  107. int m_nDeathTick;
  108. float m_flLength; // The length of the entire replay, including the post-death time, in seconds
  109. bool m_bRendered; // Has the replay been rendered yet?
  110. int m_nPlayerSlot; // Player slot (+1), used to determine which player recorded the demo during playback
  111. int m_nPostDeathRecordTime; // replay_postdeathrecordtime at the time of record
  112. CUtlVector< CReplayScreenshot * > m_vecScreenshots;
  113. CUtlVector< CReplayPerformance * > m_vecPerformances;
  114. int m_iMaxSessionBlockRequired; // The maximum session block required to reconstruct a viewable .dem file from spawn tick until length
  115. CReplayTime m_RecordTime; // Contains time/date when spawn tick was recorded
  116. float m_flStartTime; // Start time (uses engine's host_time)
  117. CUtlString m_strReconstructedFilename;
  118. bool m_bSavedDuringThisSession;
  119. };
  120. //----------------------------------------------------------------------------------------
  121. #endif // REPLAY_H