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.

244 lines
8.2 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef CL_DEMO_H
  7. #define CL_DEMO_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "demofile.h"
  12. #include "cl_demoactionmanager.h"
  13. #include "netmessages_signon.h"
  14. struct DemoCommandQueue
  15. {
  16. DemoCommandQueue()
  17. {
  18. tick = 0;
  19. }
  20. int tick;
  21. democmdinfo_t info;
  22. int filepos;
  23. };
  24. struct DemoCustomDataCallbackMapping_t
  25. {
  26. pfnDemoCustomDataCallback pCallback;
  27. CUtlString name;
  28. };
  29. struct DemoHighlightEntry_t
  30. {
  31. int nSeekToTick;
  32. int nFastForwardToTick;
  33. int nPlayToTick;
  34. int nActualFirstEventTick;
  35. int nActualLastEventTick;
  36. int nNumEvents;
  37. uint32 unAccountID;
  38. };
  39. class CDemoPlayer : public IDemoPlayer
  40. {
  41. public: // IDemoPlayer interface implementation:
  42. CDemoPlayer();
  43. ~CDemoPlayer();
  44. bool StartPlayback( const char *filename, bool bAsTimeDemo, CDemoPlaybackParameters_t const *pPlaybackParameters, int nStartingTick = -1 ) ;
  45. bool StartBroadcastPlayback( int nStartingTick );
  46. virtual bool IsPlayingBack( void ) const OVERRIDE; // true if demo loaded and playing back
  47. virtual bool IsPlaybackPaused( void ) const OVERRIDE; // true if playback paused
  48. virtual bool IsPlayingTimeDemo( void ) const OVERRIDE; // true if playing back in timedemo mode
  49. CDemoPlaybackParameters_t const * GetDemoPlaybackParameters() OVERRIDE;
  50. void PausePlayback( float seconds );
  51. void SkipToTick( int tick, bool bRelative, bool bPause );
  52. void SkipToImportantTick( const DemoImportantTick_t *pTick );
  53. void ResumePlayback( void );
  54. void StopPlayback( void );
  55. void RestartPlayback( void );
  56. int GetPlaybackStartTick( void );
  57. int GetPlaybackTick( void );
  58. virtual int GetPlaybackDeltaTick( void ) ;
  59. virtual int GetPacketTick( void ) ;
  60. float GetPlaybackTimeScale( void );
  61. int GetTotalTicks( void );
  62. virtual bool IsSkipping( void ) const OVERRIDE; // true, if demo player skipping trough packets
  63. // true if demoplayer can skip backwards
  64. virtual bool CanSkipBackwards( void ) const OVERRIDE { return false; }
  65. void SetPlaybackTimeScale( float timescale );
  66. void InterpolateViewpoint(); // override viewpoint
  67. netpacket_t *ReadPacket( void );
  68. void ResetDemoInterpolation( void );
  69. void SetPacketReadSuspended( bool bSuspendPacketReading );
  70. virtual IDemoStream* GetDemoStream() OVERRIDE { return &m_DemoFile; }
  71. public: // other public functions
  72. void MarkFrame( float flFPSVariability );
  73. void SetBenchframe( int tick, const char *filename );
  74. void ResyncDemoClock( void );
  75. bool CheckPausedPlayback( void );
  76. void WriteTimeDemoResults( void );
  77. bool ParseAheadForInterval( int curtick, int intervalticks );
  78. void InterpolateDemoCommand( int nSlot, int targettick, DemoCommandQueue& prev, DemoCommandQueue& next );
  79. void SetImportantEventData( const KeyValues *pData ) OVERRIDE;
  80. void GetImportantGameEventIDs();
  81. void ScanForImportantTicks( void );
  82. int FindNextImportantTick( int nCurrentTick, const char *pEventName = NULL ) OVERRIDE; // -1 = no next important tick
  83. int FindPreviousImportantTick( int nCurrentTick, const char *pEventName = NULL ) OVERRIDE; // -1 = no previous important tick
  84. int FindNextImportantTickByXuidAndEvent( int nCurrentTick, const CSteamID &steamID, const char *pKeyWithXuid, const char *pEventName = NULL ); // -1 = no next important tick
  85. int FindPreviousImportantTickByXuidAndEvent( int nCurrentTick, const CSteamID &steamID, const char *pKeyWithXuid, const char *pEventName = NULL ); // -1 = no next important tick
  86. int FindNextImportantTickByXuid( int nCurrentTick, const CSteamID &steamID ); // -1 = no next important tick
  87. const DemoImportantTick_t *GetImportantTick( int nIndex ) OVERRIDE;
  88. const DemoImportantGameEvent_t *GetImportantGameEvent( const char *pszEventName ) OVERRIDE;
  89. void ListImportantTicks( void ) OVERRIDE;
  90. void SetHighlightXuid( uint64 xuid, bool bLowlights ) OVERRIDE;
  91. void ListHighlightData( void ) OVERRIDE;
  92. bool ScanDemo( const char *filename, const char* pszMode ) OVERRIDE;
  93. protected:
  94. bool OverrideView( democmdinfo_t& info );
  95. void BuildHighlightList( void );
  96. public:
  97. CDemoFile m_DemoFile;
  98. int m_nStartTick; // For synchronizing playback during timedemo.
  99. int m_nPreviousTick;
  100. netpacket_t m_DemoPacket; // last read demo packet
  101. bool m_bPlayingBack; // true if demo playback
  102. bool m_bPlaybackPaused; // true if demo is paused right now
  103. float m_flAutoResumeTime; // how long do we pause demo playback
  104. float m_flPlaybackRateModifier;
  105. int m_nSkipToTick; // skip to tick ASAP, -1 = off
  106. bool m_bPacketReadSuspended;
  107. int m_nTickToPauseOn;
  108. CDemoPlaybackParameters_t const *m_pPlaybackParameters;
  109. // view origin/angle interpolation:
  110. CUtlVector< DemoCommandQueue > m_DestCmdInfo;
  111. democmdinfo_t m_LastCmdInfo;
  112. bool m_bInterpolateView;
  113. bool m_bResetInterpolation;
  114. // timedemo stuff:
  115. bool m_bTimeDemo; // ture if in timedemo mode
  116. int m_nTimeDemoStartFrame; // host_tickcount at start
  117. double m_flTimeDemoStartTime; // Sys_FloatTime() at second frame of timedemo
  118. float m_flTotalFPSVariability; // Frame rate variability
  119. int m_nTimeDemoCurrentFrame; // last frame we read a packet
  120. int m_nPacketTick;
  121. // benchframe stuff
  122. int m_nSnapshotTick;
  123. char m_SnapshotFilename[MAX_OSPATH];
  124. CUtlVector< DemoCustomDataCallbackMapping_t > m_CustomDataCallbackMap; //maps callbacks in the file to callbacks in the dll when reading
  125. // important tick stuff
  126. CUtlVector< DemoImportantGameEvent_t > m_ImportantGameEvents;
  127. CUtlVector< DemoImportantTick_t > m_ImportantTicks;
  128. KeyValues *m_pImportantEventData;
  129. private:
  130. int m_nRestartFilePos;
  131. bool m_bSavedInterpolateState;
  132. CSteamID m_highlightSteamID;
  133. int m_nHighlightPlayerIndex;
  134. bool m_bDoHighlightScan;
  135. CUtlVector< DemoHighlightEntry_t > m_highlights;
  136. int m_nCurrentHighlight;
  137. bool m_bLowlightsMode;
  138. bool m_bScanMode;
  139. char m_szScanMode[ 64 ];
  140. };
  141. class CDemoRecorder : public IDemoRecorder
  142. {
  143. public:
  144. ~CDemoRecorder();
  145. CDemoRecorder();
  146. CDemoFile *GetDemoFile( void );
  147. int GetRecordingTick( void );
  148. void StartRecording( const char *filename, bool bContinuously );
  149. void SetSignonState( SIGNONSTATE state );
  150. bool IsRecording( void );
  151. void PauseRecording( void );
  152. void ResumeRecording( void );
  153. void StopRecording( const CGameInfo *pGameInfo = NULL );
  154. void RecordCommand( const char *cmdstring ); // record a console command
  155. void RecordUserInput( int cmdnumber ); // record a user input command
  156. void RecordMessages( bf_read &data, int bits ); // add messages to current packet
  157. void RecordPacket( void ); // packet finished, write all recorded stuff to file
  158. void RecordServerClasses( ServerClass *pClasses ); // packet finished, write all recorded stuff to file
  159. void RecordStringTables();
  160. void RecordCustomData( int iCallbackIndex, const void *pData, size_t iDataLength ); //record a chunk of custom data
  161. void ResetDemoInterpolation( void );
  162. protected:
  163. void ResyncDemoClock( void );
  164. void StartupDemoFile( void );
  165. void StartupDemoHeader( void );
  166. void CloseDemoFile( void );
  167. void GetClientCmdInfo( democmdinfo_t& info );
  168. void WriteDemoCvars( void );
  169. void WriteBSPDecals( void );
  170. void WriteSplitScreenPlayers( void );
  171. void WriteMessages( bf_write &message );
  172. bool ComputeNextIncrementalDemoFilename( char *name, int namesize );
  173. public:
  174. CDemoFile m_DemoFile;
  175. // For synchronizing playback during timedemo.
  176. int m_nStartTick; // host_tickcount when starting recoring
  177. // Name of demo file we are appending onto.
  178. char m_szDemoBaseName[ MAX_OSPATH ];
  179. // For demo file handle
  180. bool m_bIsDemoHeader; // true, if m_hDemoFile is the header file
  181. bool m_bCloseDemoFile; // if true, demo file will be closed ASAP
  182. bool m_bRecording; // true if recording
  183. bool m_bContinuously; // start new record after each
  184. int m_nDemoNumber; // demo count, increases each changelevel
  185. int m_nFrameCount; // # of demo frames in this segment.
  186. bf_write m_MessageData; // temp buffer for all network messages
  187. bool m_bResetInterpolation;
  188. };
  189. extern CDemoPlayer *g_pClientDemoPlayer;
  190. extern CDemoRecorder *g_pClientDemoRecorder;
  191. struct RegisteredDemoCustomDataCallbackPair_t
  192. {
  193. pfnDemoCustomDataCallback pCallback;
  194. string_t szSaveID;
  195. };
  196. extern CUtlVector<RegisteredDemoCustomDataCallbackPair_t> g_RegisteredDemoCustomDataCallbacks;
  197. #endif // CL_DEMO_H