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.

154 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #ifndef PERFORMANCECONTROLLER_H
  5. #define PERFORMANCECONTROLLER_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //----------------------------------------------------------------------------------------
  10. #include "replay/ireplayperformancecontroller.h"
  11. #include "basethinker.h"
  12. #include "replay/replayhandle.h"
  13. #include <utllinkedlist.h>
  14. //----------------------------------------------------------------------------------------
  15. class IReplayPerformancePlaybackHandler;
  16. class IReplayPerformanceEditor;
  17. class KeyValues;
  18. class Vector;
  19. class QAngle;
  20. class CReplayPerformance;
  21. class CReplay;
  22. class CJob;
  23. //----------------------------------------------------------------------------------------
  24. class CPerformanceController : public CBaseThinker,
  25. public IReplayPerformanceController
  26. {
  27. public:
  28. CPerformanceController();
  29. ~CPerformanceController();
  30. //
  31. // IReplayPerforamnceController
  32. //
  33. virtual void SetEditor( IReplayPerformanceEditor *pEditor );
  34. virtual void StartRecording( CReplay *pReplay, bool bSnip );
  35. virtual void Stop(); // Stop playback/recording
  36. virtual bool SaveAsync();
  37. virtual bool SaveAsAsync( const wchar_t *pTitle );
  38. virtual bool IsSaving() const;
  39. virtual void SaveThink();
  40. virtual bool GetLastSaveStatus() const;
  41. virtual bool IsRecording() const;
  42. virtual bool IsPlaying() const;
  43. virtual bool IsPlaybackDataLeft();
  44. virtual bool IsDirty() const;
  45. virtual void NotifyDirty();
  46. virtual void OnSignonStateFull();
  47. virtual float GetPlaybackTimeScale() const;
  48. private:
  49. //
  50. // Common to recording/playback
  51. //
  52. void Cleanup();
  53. void CleanupDbgStream();
  54. void CleanupStream(); // Cleans up m_pRoot if necessary
  55. float GetTime() const; // Get m_pCurEvent time
  56. void ClearDirtyFlag();
  57. enum State_t
  58. {
  59. STATE_DORMANT = -1, // Not playing back or recording
  60. STATE_RECORDING,
  61. STATE_PLAYING,
  62. };
  63. State_t m_nState;
  64. //
  65. // CBaseThinker
  66. //
  67. virtual void Think();
  68. virtual float GetNextThinkTime() const;
  69. //
  70. // Recorder-specific:
  71. //
  72. virtual void NotifyPauseState( bool bPaused );
  73. virtual void Snip();
  74. virtual void NotifyRewinding();
  75. virtual void ClearRewinding();
  76. virtual bool IsRewinding() const { return m_bRewinding; }
  77. virtual const KeyValues *GetUnsavedRecordingData() const { return m_pRoot; }
  78. virtual void AddEvent_Camera_Change_FirstPerson( float flTime, int nEntityIndex );
  79. virtual void AddEvent_Camera_Change_ThirdPerson( float flTime, int nEntityIndex );
  80. virtual void AddEvent_Camera_Change_Free( float flTime );
  81. virtual void AddEvent_Camera_ChangePlayer( float flTime, int nEntIndex );
  82. virtual void AddEvent_Camera_SetView( const SetViewParams_t &params );
  83. virtual void AddEvent_TimeScale( float flTime, float flScale );
  84. void CreateNewScratchPerformance( CReplay *pReplay );
  85. bool DumpStreamToFileAsync( const char *pFullFilename );
  86. bool FlushReplay();
  87. bool IsCameraChangeEvent( int nType ) const;
  88. void AddEvent( KeyValues *pEvent );
  89. void RemoveDuplicateEventsFromQueue();
  90. ReplayHandle_t m_hReplay;
  91. CReplayPerformance *m_pSavedPerformance; // Points to the saved performance - scratch copies to saved - should not be modified directly
  92. CReplayPerformance *m_pScratchPerformance; // The working performance, ie the temporary performance we muck with until the user saves or discards
  93. bool m_bRewinding;
  94. bool m_bPaused; // Maintain our own state for paused/playing for event queueing
  95. CUtlLinkedList< KeyValues * > m_EventQueue; // If user pauses and changes camera, etc, it gets queued here - if multiple camera changes occur, previous is stomped
  96. IReplayPerformanceEditor *m_pEditor; // Pointer to the editor UI in the client
  97. //
  98. // Playback-specific
  99. //
  100. void PlaybackThink();
  101. void ReadSetViewEvent( KeyValues *pEventSubKey, Vector &origin, QAngle &angles, float &fov,
  102. float *pAccel, float *pSpeed, float *pRotFilter );
  103. void DebugRender();
  104. bool SetupPlaybackHandler();
  105. void SetupPlaybackFromPerformance( CReplayPerformance *pPerformance );
  106. void SetupPlaybackExistingStream(); // Don't load anything from disk - use what's already in memory - used for rewind
  107. void FinishBeginPerformancePlayback();
  108. virtual CReplayPerformance *GetPerformance();
  109. virtual CReplayPerformance *GetSavedPerformance();
  110. virtual bool HasSavedPerformance();
  111. KeyValues *m_pRoot;
  112. KeyValues *m_pCurEvent;
  113. KeyValues *m_pDbgRoot; // Copy of performance data for debug rendering
  114. KeyValues *m_pSetViewEvent;
  115. bool m_bViewOverrideMode;
  116. bool m_bDirty; // If we recorded at all, was anything changed?
  117. float m_flLastCamSetViewTime;
  118. float m_flTimeScale;
  119. CJob *m_pSaveJob;
  120. bool m_bLastSaveStatus;
  121. IReplayPerformancePlaybackHandler *m_pPlaybackHandler;
  122. };
  123. //----------------------------------------------------------------------------------------
  124. #endif // PERFORMANCECONTROLLER_H