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.

266 lines
6.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #include "cl_replaymovie.h"
  5. #include "replay/replayutils.h"
  6. #include "replay/shared_defs.h"
  7. #include "KeyValues.h"
  8. #include "replay/replay.h"
  9. #include "cl_replaycontext.h"
  10. #include "cl_replaymanager.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //----------------------------------------------------------------------------------------
  14. CReplayMovie::CReplayMovie()
  15. : m_hReplay( REPLAY_HANDLE_INVALID ),
  16. m_bRendered( false ),
  17. m_bUploaded( false ),
  18. m_flRenderTime( 0.0f ),
  19. m_flLength( 0.0f ),
  20. m_pUserData( NULL )
  21. {
  22. V_wcsncpy( m_wszTitle, L"Untitled", sizeof( m_wszTitle ) );
  23. }
  24. bool CReplayMovie::Read( KeyValues *pIn )
  25. {
  26. if ( !BaseClass::Read( pIn ) )
  27. return false;
  28. m_hReplay = (ReplayHandle_t)pIn->GetInt( "replay_handle", REPLAY_HANDLE_INVALID );
  29. m_bRendered = pIn->GetInt( "rendered" ) != 0;
  30. V_wcsncpy( m_wszTitle, pIn->GetWString( "title" ), sizeof( m_wszTitle ) );
  31. m_strFilename = pIn->GetString( "filename" );
  32. m_strUploadURL = pIn->GetString( "upload_url" );
  33. m_bUploaded = pIn->GetInt( "uploaded" ) != 0;
  34. m_flRenderTime = pIn->GetFloat( "rendertime" );
  35. m_flLength = pIn->GetFloat( "length" );
  36. m_RecordTime.Read( pIn );
  37. return ReadRenderSettings( pIn );
  38. }
  39. void CReplayMovie::Write( KeyValues* pOut )
  40. {
  41. BaseClass::Write( pOut );
  42. pOut->SetInt( "replay_handle", (int)m_hReplay );
  43. pOut->SetInt( "rendered", (int)m_bRendered );
  44. pOut->SetWString( "title", m_wszTitle );
  45. pOut->SetString( "filename", m_strFilename.Get() );
  46. pOut->SetString( "upload_url", m_strUploadURL.Get() );
  47. pOut->SetInt( "uploaded", (int)m_bUploaded );
  48. pOut->SetFloat( "rendertime", m_flRenderTime );
  49. pOut->SetFloat( "length", m_flLength );
  50. m_RecordTime.Write( pOut );
  51. WriteRenderSettings( pOut );
  52. }
  53. bool CReplayMovie::ReadRenderSettings( KeyValues *pIn )
  54. {
  55. KeyValues *pRenderSettingsSubKey = pIn->FindKey( "rendersettings" );
  56. if ( !pRenderSettingsSubKey )
  57. {
  58. AssertMsg( 0, "No render settings sub key found for movie!" );
  59. return true; // Continue to load anyway
  60. }
  61. m_RenderSettings.m_nWidth = pRenderSettingsSubKey->GetInt( "width" );
  62. m_RenderSettings.m_nHeight = pRenderSettingsSubKey->GetInt( "height" );
  63. m_RenderSettings.m_nMotionBlurQuality = pRenderSettingsSubKey->GetInt( "motionblurquality" );
  64. m_RenderSettings.m_FPS.SetRaw( pRenderSettingsSubKey->GetInt( "fps.ups" ), pRenderSettingsSubKey->GetInt( "fps.upf" ) );
  65. m_RenderSettings.m_Codec = ( VideoEncodeCodec_t )pRenderSettingsSubKey->GetInt( "codec" );
  66. m_RenderSettings.m_nEncodingQuality = pRenderSettingsSubKey->GetInt( "encoding_quality" );
  67. m_RenderSettings.m_bMotionBlurEnabled = pRenderSettingsSubKey->GetBool( "mb_enabled" );
  68. m_RenderSettings.m_bAAEnabled = pRenderSettingsSubKey->GetBool( "aa_enabled" );
  69. m_RenderSettings.m_bRaw = pRenderSettingsSubKey->GetBool( "raw" );
  70. return true;
  71. }
  72. void CReplayMovie::WriteRenderSettings( KeyValues *pOut )
  73. {
  74. KeyValues *pRenderSettingsSubKey = new KeyValues( "rendersettings" );
  75. if ( !pRenderSettingsSubKey )
  76. {
  77. AssertMsg( 0, "Failed to allocate render settings sub key for movie!" );
  78. return;
  79. }
  80. pOut->AddSubKey( pRenderSettingsSubKey );
  81. pRenderSettingsSubKey->SetInt( "width", m_RenderSettings.m_nWidth );
  82. pRenderSettingsSubKey->SetInt( "height", m_RenderSettings.m_nHeight );
  83. pRenderSettingsSubKey->SetInt( "motionblurquality", m_RenderSettings.m_nMotionBlurQuality );
  84. pRenderSettingsSubKey->SetInt( "fps.ups", m_RenderSettings.m_FPS.GetUnitsPerSecond() );
  85. pRenderSettingsSubKey->SetInt( "fps.upf", m_RenderSettings.m_FPS.GetUnitsPerFrame() );
  86. pRenderSettingsSubKey->SetInt( "codec", (int)m_RenderSettings.m_Codec );
  87. pRenderSettingsSubKey->SetInt( "encoding_quality", m_RenderSettings.m_nEncodingQuality );
  88. pRenderSettingsSubKey->SetInt( "mb_enabled", (int)m_RenderSettings.m_bMotionBlurEnabled );
  89. pRenderSettingsSubKey->SetInt( "aa_enabled", (int)m_RenderSettings.m_bAAEnabled );
  90. pRenderSettingsSubKey->SetInt( "raw", (int)m_RenderSettings.m_bRaw );
  91. }
  92. const char *CReplayMovie::GetSubKeyTitle() const
  93. {
  94. return Replay_va( "movie_%i", GetHandle() );
  95. }
  96. const char *CReplayMovie::GetPath() const
  97. {
  98. return Replay_va( "%s%s%c", g_pClientReplayContextInternal->GetBaseDir(), SUBDIR_MOVIES, CORRECT_PATH_SEPARATOR );
  99. }
  100. void CReplayMovie::OnDelete()
  101. {
  102. // Remove the actual movie from disk
  103. g_pFullFileSystem->RemoveFile( Replay_va( "%s%s", CL_GetMovieManager()->GetRenderDir(), m_strFilename.Get() ) );
  104. }
  105. ReplayHandle_t CReplayMovie::GetMovieHandle() const
  106. {
  107. return GetHandle();
  108. }
  109. ReplayHandle_t CReplayMovie::GetReplayHandle() const
  110. {
  111. return m_hReplay;
  112. }
  113. const ReplayRenderSettings_t &CReplayMovie::GetRenderSettings()
  114. {
  115. return m_RenderSettings;
  116. }
  117. void CReplayMovie::GetFrameDimensions( int &nWidth, int &nHeight )
  118. {
  119. nWidth = m_RenderSettings.m_nWidth;
  120. nHeight = m_RenderSettings.m_nHeight;
  121. }
  122. void CReplayMovie::SetIsRendered( bool bIsRendered )
  123. {
  124. m_bRendered = bIsRendered;
  125. }
  126. void CReplayMovie::SetMovieFilename( const char *pFilename )
  127. {
  128. m_strFilename = pFilename;
  129. }
  130. const char *CReplayMovie::GetMovieFilename() const
  131. {
  132. return m_strFilename.Get();
  133. }
  134. void CReplayMovie::SetMovieTitle( const wchar_t *pTitle )
  135. {
  136. V_wcsncpy( m_wszTitle, pTitle, sizeof( m_wszTitle ) );
  137. }
  138. void CReplayMovie::SetRenderTime( float flRenderTime )
  139. {
  140. m_flRenderTime = flRenderTime;
  141. }
  142. float CReplayMovie::GetRenderTime() const
  143. {
  144. return m_flRenderTime;
  145. }
  146. void CReplayMovie::CaptureRecordTime()
  147. {
  148. m_RecordTime.InitDateAndTimeToNow();
  149. }
  150. void CReplayMovie::SetLength( float flLength )
  151. {
  152. m_flLength = flLength;
  153. }
  154. CReplay *CReplayMovie::GetReplay() const
  155. {
  156. return static_cast< CReplay * >( ::GetReplay( m_hReplay ) );
  157. }
  158. bool CReplayMovie::IsUploaded() const
  159. {
  160. return m_bUploaded;
  161. }
  162. void CReplayMovie::SetUploaded( bool bUploaded )
  163. {
  164. m_bUploaded = bUploaded;
  165. }
  166. void CReplayMovie::SetUploadURL( const char *pURL )
  167. {
  168. m_strUploadURL = pURL;
  169. }
  170. const char *CReplayMovie::GetUploadURL() const
  171. {
  172. return m_strUploadURL.Get();
  173. }
  174. const CReplayTime &CReplayMovie::GetItemDate() const
  175. {
  176. return m_RecordTime;
  177. }
  178. bool CReplayMovie::IsItemRendered() const
  179. {
  180. return GetReplay()->IsItemRendered();
  181. }
  182. CReplay *CReplayMovie::GetItemReplay()
  183. {
  184. return GetReplay();
  185. }
  186. ReplayHandle_t CReplayMovie::GetItemReplayHandle() const
  187. {
  188. return m_hReplay;
  189. }
  190. QueryableReplayItemHandle_t CReplayMovie::GetItemHandle() const
  191. {
  192. return (QueryableReplayItemHandle_t)GetHandle();
  193. }
  194. const wchar_t *CReplayMovie::GetItemTitle() const
  195. {
  196. return m_wszTitle;
  197. }
  198. void CReplayMovie::SetItemTitle( const wchar_t *pTitle )
  199. {
  200. V_wcsncpy( m_wszTitle, pTitle, sizeof( m_wszTitle ) );
  201. }
  202. float CReplayMovie::GetItemLength() const
  203. {
  204. return m_flLength;
  205. }
  206. void *CReplayMovie::GetUserData()
  207. {
  208. return m_pUserData;
  209. }
  210. void CReplayMovie::SetUserData( void *pUserData )
  211. {
  212. m_pUserData = pUserData;
  213. }
  214. bool CReplayMovie::IsItemAMovie() const
  215. {
  216. return true;
  217. }
  218. //----------------------------------------------------------------------------------------