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.

209 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "cbase.h"
  3. #if defined( REPLAY_ENABLED )
  4. #include "replay/cdll_replay.h"
  5. #include "replay/replaycamera.h"
  6. #include "replay/replay_ragdoll.h"
  7. #include "replay/iclientreplay.h"
  8. #include "replay/ireplayscreenshotsystem.h"
  9. #include "replay/ireplaysystem.h"
  10. #include "replay/ienginereplay.h"
  11. #include "replay/ireplaymoviemanager.h"
  12. #include "replay/vgui/replayconfirmquitdlg.h"
  13. #include "replay/vgui/replaybrowsermainpanel.h"
  14. #include "replay/vgui/replayinputpanel.h"
  15. #include "replay/vgui/replayperformanceeditor.h"
  16. #include "replayperformanceplaybackhandler.h"
  17. #include "vgui/ILocalize.h"
  18. #include "vgui/ISurface.h"
  19. #include "clientmode.h"
  20. #include "iviewrender.h"
  21. #include "igameevents.h"
  22. #include "replaycamera.h"
  23. #if defined( TF_CLIENT_DLL )
  24. #include "c_tf_gamestats.h"
  25. #endif
  26. #include "steamworks_gamestats.h"
  27. #include "replay_gamestats_shared.h"
  28. //----------------------------------------------------------------------------------------
  29. class IReplayScreenshotSystem;
  30. //----------------------------------------------------------------------------------------
  31. extern void ReplayUI_OpenReplayRenderOverlay();
  32. extern void ReplayUI_HideRenderOverlay();
  33. //----------------------------------------------------------------------------------------
  34. extern IReplayMovieManager *g_pReplayMovieManager;
  35. //----------------------------------------------------------------------------------------
  36. class CClientReplayImp : public IClientReplay
  37. {
  38. public:
  39. virtual uint64 GetServerSessionId()
  40. {
  41. return GetSteamWorksSGameStatsUploader().GetServerSessionID();
  42. }
  43. virtual IReplayScreenshotSystem *GetReplayScreenshotSystem()
  44. {
  45. if ( g_pEngineReplay->IsSupportedModAndPlatform() )
  46. return view->GetReplayScreenshotSystem();
  47. return NULL;
  48. }
  49. virtual IReplayPerformancePlaybackHandler *GetPerformancePlaybackHandler()
  50. {
  51. return g_pReplayPerformancePlaybackHandler;
  52. }
  53. virtual bool CacheReplayRagdolls( const char* pFilename, int nStartTick )
  54. {
  55. return Replay_CacheRagdolls( pFilename, nStartTick );
  56. }
  57. virtual void OnSaveReplay( ReplayHandle_t hNewReplay, bool bShowInputDlg )
  58. {
  59. if ( bShowInputDlg )
  60. {
  61. // Get a name for the replay, saves to disk, add thumbnail to replay browser
  62. ShowReplayInputPanel( hNewReplay );
  63. }
  64. else
  65. {
  66. // Just add the thumbnail if the replay browser exists
  67. CReplayBrowserPanel* pReplayBrowser = ReplayUI_GetBrowserPanel();
  68. if ( pReplayBrowser )
  69. {
  70. pReplayBrowser->OnSaveReplay( hNewReplay );
  71. }
  72. }
  73. // Fire a message the game DLL can intercept (for achievements, etc).
  74. IGameEvent *event = gameeventmanager->CreateEvent( "replay_saved" );
  75. if ( event )
  76. {
  77. gameeventmanager->FireEventClientSide( event );
  78. }
  79. }
  80. virtual void OnDeleteReplay( ReplayHandle_t hReplay )
  81. {
  82. CReplayBrowserPanel* pReplayBrowser = ReplayUI_GetBrowserPanel();
  83. if ( pReplayBrowser )
  84. {
  85. pReplayBrowser->OnDeleteReplay( hReplay );
  86. }
  87. }
  88. virtual void DisplayReplayMessage( const char *pLocalizeStr, bool bUrgent, bool bDlg, const char *pSound )
  89. {
  90. // Display a message?
  91. if ( !pLocalizeStr || !pLocalizeStr[0] )
  92. return;
  93. g_pClientMode->DisplayReplayMessage( pLocalizeStr, -1.0f, bUrgent, pSound, bDlg );
  94. }
  95. virtual void DisplayReplayMessage( const wchar_t *pText, bool bUrgent, bool bDlg, const char *pSound )
  96. {
  97. if ( !pText || !pText[0] )
  98. return;
  99. const int nLen = wcslen( pText ) + 1;
  100. char *pAnsi = new char[ nLen ];
  101. g_pVGuiLocalize->ConvertUnicodeToANSI( pText, pAnsi, nLen );
  102. g_pClientMode->DisplayReplayMessage( pAnsi, -1.0f, bUrgent, pSound, bDlg );
  103. }
  104. virtual bool OnConfirmQuit()
  105. {
  106. return ReplayUI_ShowConfirmQuitDlg();
  107. }
  108. virtual void OnRenderStart()
  109. {
  110. ReplayUI_OpenReplayRenderOverlay();
  111. }
  112. virtual void OnRenderComplete( const RenderMovieParams_t &RenderParams, bool bCancelled, bool bSuccess, bool bShowBrowser )
  113. {
  114. ReplayUI_HideRenderOverlay();
  115. if ( bShowBrowser )
  116. {
  117. ReplayUI_ReloadBrowser();
  118. }
  119. // Upload a row to the OGS now that rendering has completed
  120. GetReplayGameStatsHelper().SW_ReplayStats_WriteRenderDataEnd( RenderParams, bCancelled ? "cancelled" : bSuccess ? "success" : "failed" );
  121. }
  122. virtual void InitPerformanceEditor( ReplayHandle_t hReplay )
  123. {
  124. ReplayUI_InitPerformanceEditor( hReplay );
  125. }
  126. virtual void HidePerformanceEditor()
  127. {
  128. ReplayUI_ClosePerformanceEditor();
  129. }
  130. virtual bool ShouldRender()
  131. {
  132. extern ConVar replay_enablerenderpreview;
  133. return !g_pReplayMovieManager->IsRendering() || replay_enablerenderpreview.GetBool();
  134. }
  135. virtual void PlaySound( const char *pSound )
  136. {
  137. if ( g_pVGuiSurface )
  138. {
  139. g_pVGuiSurface->PlaySound( pSound );
  140. }
  141. }
  142. virtual void UploadOgsData( KeyValues *pData, bool bIncludeTimeField )
  143. {
  144. GetReplayGameStatsHelper().UploadError( pData, bIncludeTimeField );
  145. }
  146. virtual bool ShouldCompletePendingReplay( IGameEvent *pEvent )
  147. {
  148. #if defined( TF_CLIENT_DLL )
  149. return !( pEvent->GetInt( "death_flags" ) & TF_DEATH_FEIGN_DEATH );
  150. #else
  151. return true;
  152. #endif
  153. }
  154. virtual void OnPlaybackComplete( ReplayHandle_t hReplay, int iPerformance )
  155. {
  156. ReplayUI_ReloadBrowser( hReplay, iPerformance );
  157. }
  158. virtual IReplayCamera *GetReplayCamera()
  159. {
  160. return ReplayCamera();
  161. }
  162. virtual bool OnEndOfReplayReached()
  163. {
  164. CReplayPerformanceEditorPanel *pEditor = ReplayUI_GetPerformanceEditor();
  165. if ( !pEditor )
  166. return false;
  167. return pEditor->OnEndOfReplayReached();
  168. }
  169. };
  170. static CClientReplayImp s_ClientReplayImp;
  171. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CClientReplayImp, IClientReplay, CLIENT_REPLAY_INTERFACE_VERSION, s_ClientReplayImp );
  172. #endif // #if defined( REPLAY_ENABLED )