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.

191 lines
5.2 KiB

  1. //======= Copyright (c) Valve Corporation, All rights reserved. ======
  2. #ifndef HLTV_REPLAY_SYSTEM
  3. #define HLTV_REPLAY_SYSTEM
  4. // this struct is followed by matrix3x4a_t bones
  5. struct ALIGN16 CachedRagdollBones_t
  6. {
  7. int nBones;
  8. int nBodyParts;
  9. bool bAllAsleep;
  10. matrix3x4a_t *GetBones() { return ( matrix3x4a_t * )( this + 1 ); }
  11. matrix3x4a_t *GetBodyParts() { return GetBones() + nBones; }
  12. } ALIGN16_POST;
  13. class CHltvReplaySystem: public CGameEventListener
  14. {
  15. public:
  16. struct ReplayParams_t
  17. {
  18. int nRequest; // member of enum ReplayEventType_t
  19. int nPrimaryTargetEntIndex;
  20. float flEventTime;
  21. float flTime; // when gpGlobal->curtime reaches this value, replay starts
  22. int nPrimaryVictimEntIndex;
  23. bool bPrimaryVictimIsLocalPlayer;
  24. bool bFinalKillOfRound;
  25. ReplayParams_t()
  26. {
  27. Reset();
  28. }
  29. void Stop()
  30. {
  31. nRequest = -1;
  32. }
  33. void Reset()
  34. {
  35. nRequest = -1;
  36. flTime = -1000;
  37. nPrimaryVictimEntIndex = nPrimaryVictimEntIndex = -1;
  38. bPrimaryVictimIsLocalPlayer = false;
  39. flEventTime = 0;
  40. bFinalKillOfRound = false;
  41. }
  42. bool IsValid() { return nRequest >= 0; }
  43. void Invalidate() { nRequest = -1; }
  44. };
  45. class CLocalPlayerProps
  46. {
  47. public:
  48. bool m_bLastSeenAlive;
  49. int m_nLastTickUpdated;
  50. public:
  51. CLocalPlayerProps();
  52. bool Update();
  53. };
  54. public:
  55. CHltvReplaySystem();
  56. ~CHltvReplaySystem();
  57. void OnHltvReplay( const CSVCMsg_HltvReplay &msg );
  58. void OnHltvReplayTick();
  59. void EmitTimeJump();
  60. int GetHltvReplayDelay() { return m_nHltvReplayDelay; }
  61. void StopHltvReplay();
  62. float GetReplayVideoFadeAmount()const { m_flDebugLastRequestedReplayVideoFadeAmount = m_flReplayVideoFadeAmount; return m_flReplayVideoFadeAmount; }
  63. float GetHltvReplayDistortAmount()const;
  64. bool IsHltvReplayButtonEnabled();
  65. bool IsHltvReplayButtonTimedOut();
  66. void RequestHltvReplayDeath();
  67. void RequestHltvReplay( const ReplayParams_t &replay );
  68. void RequestCancelHltvReplay( bool bSuppressFadeout = false );
  69. bool IsHltvReplayFeatureEnabled();
  70. bool IsFadeoutFinished();
  71. bool IsFadeoutActive();
  72. bool IsDelayedReplayRequestPending() { return m_DelayedReplay.IsValid(); }
  73. bool PrepareHltvReplayCountdown( );
  74. void CancelDelayedHltvReplay();
  75. void OnLevelInit();
  76. void OnPlayerDeath( IGameEvent *event );
  77. bool WantsReplayEffect()const;
  78. void OnDemoPlayback( bool bPlaying );
  79. void SetDemoPlaybackHighlightXuid( uint64 xuid, bool bLowlights );
  80. void SetDemoPlaybackFadeBrackets( int nCurrentPlaybackTick, int nStartAt, int nStopAt );
  81. bool IsDemoPlayback() const { return m_bDemoPlayback; }
  82. bool IsDemoPlaybackLowLights() const { return m_bDemoPlaybackLowLights; }
  83. void FireGameEvent( IGameEvent *event );
  84. void OnLevelShutdown();
  85. void OnLocalPlayerRespawning();
  86. int GetPrimaryVictimEntIndex()const { return m_DelayedReplay.nPrimaryVictimEntIndex; }
  87. bool IsPrimaryVictimLocalPlayer()const { return m_DelayedReplay.bPrimaryVictimIsLocalPlayer; }
  88. bool IsReplayingFinalKillOfRound()const { return m_nHltvReplayDelay && m_DelayedReplay.bFinalKillOfRound; }
  89. void StopFades();
  90. void StopFadeout();
  91. void StartFadeout(float flEndTime, float flDuration );
  92. void StartFadein( float flStartRealTime );
  93. void SetReplaySoundMixLayer( float flFade );
  94. C_BasePlayer *GetDemoPlaybackPlayer();
  95. bool IsDemoPlaybackXuidOther()const;
  96. void Update();
  97. void PurgeRagdollBoneCache();
  98. void CacheRagdollBones();
  99. CachedRagdollBones_t *GetCachedRagdollBones( int nEntIndex, bool bTake );
  100. void FreeCachedRagdollBones( CachedRagdollBones_t* );
  101. enum ExperimentalEvents_t
  102. {
  103. EE_REPLAY_OFFERED = 1,
  104. EE_REPLAY_REQUESTED = 2,
  105. EE_REPLAY_STARTED = 4,
  106. EE_REPLAY_CANCELLED = 8,
  107. EE_REPLAY_AUTOMATIC = 16,
  108. EE_REPLAY_STUCK = 32
  109. //EE_REPLAY_VICTIM_POV = 64 // never shipped, removed after discussions with Vitaliy, BrianL, Gautam
  110. };
  111. uint GetExperimentalEvents() const { return m_nExperimentalEvents; }
  112. bool UpdateHltvReplayButtonTimeOutState();
  113. protected:
  114. static float GetReplayMessageTime();
  115. protected:
  116. int m_nHltvReplayDelay;
  117. int m_nHltvReplayStopAt;
  118. int m_nHltvReplayStartAt;
  119. int m_nHltvReplaySlowdownBegin;
  120. int m_nHltvReplaySlowdownEnd;
  121. float m_flHltvReplaySlowdownRate;
  122. float m_flHltvLastRequestRealTime;
  123. float m_flLastReplayStoppedRealTime;
  124. float m_flLastPlayerDeath;
  125. bool m_bHltvReplayButtonTimedOut;
  126. int m_nHltvReplayPrimaryTarget;
  127. CLocalPlayerProps m_LocalPlayer;
  128. bool m_bWaitingForHltvReplayTick;
  129. float m_flStartedWaitingForHltvReplayTickRealTime;
  130. int m_nHltvReplayBeginTick;
  131. ReplayParams_t m_DelayedReplay;
  132. bool m_bDemoPlayback;
  133. bool m_bListeningForGameEvents;
  134. int m_nDemoPlaybackStartAt;
  135. int m_nDemoPlaybackStopAt;
  136. uint64 m_nDemoPlaybackXuid;
  137. bool m_bDemoPlaybackLowLights;
  138. CHandle< C_BasePlayer > m_DemoPlaybackPlayer;
  139. int m_nCurrentPlaybackTick;
  140. float m_flCurrentPlaybackTime;
  141. float m_flReplayVideoFadeAmount;
  142. float m_flReplaySoundFadeAmount;
  143. float m_flFadeinStartRealTime;
  144. float m_flFadeinDuration;
  145. float m_flFadeoutEndTime;
  146. float m_flFadeoutDuration;
  147. mutable float m_flDebugLastRequestedReplayVideoFadeAmount;
  148. uint32 m_nSteamSelfAccountId;
  149. uint32 m_nExperimentalEvents;
  150. float m_flFreeCachedRagdollBonesTime; // time (when not replaying) to destroy cached-off ragdoll bones
  151. CUtlHashtable< int, CachedRagdollBones_t* > m_mapCachedRagdollBones;
  152. };
  153. extern CHltvReplaySystem g_HltvReplaySystem;
  154. extern int CL_GetHltvReplayDelay();
  155. #endif // HLTV_REPLAY_SYSTEM