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.

124 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. #include "cbase.h"
  5. #include "replay_gamestats_shared.h"
  6. #include "steamworks_gamestats.h"
  7. #if defined( CLIENT_DLL )
  8. #include "../client/replay/genericclassbased_replay.h"
  9. #include "replay/replayvideo.h"
  10. #include "replay/vgui/replaybrowserrenderdialog.h"
  11. #endif
  12. #include "replay/rendermovieparams.h"
  13. #include "replay/performance.h"
  14. // NOTE: This has to be the last file included!
  15. #include "tier0/memdbgon.h"
  16. CReplayGameStatsHelper::CReplayGameStatsHelper()
  17. {
  18. }
  19. void CReplayGameStatsHelper::UploadError( KeyValues *pData, bool bIncludeTimeField )
  20. {
  21. if ( bIncludeTimeField )
  22. {
  23. // pData->SetInt( "Time", GetSteamWorksSGameStatsUploader().GetTimeSinceEpoch() );
  24. }
  25. GetSteamWorksSGameStatsUploader().AddStatsForUpload( pData );
  26. }
  27. CReplayGameStatsHelper &GetReplayGameStatsHelper()
  28. {
  29. static CReplayGameStatsHelper s_Instance;
  30. return s_Instance;
  31. }
  32. #if defined( CLIENT_DLL )
  33. void CReplayGameStatsHelper::SW_ReplayStats_WriteRenderDataStart( const RenderMovieParams_t& RenderParams, const CReplayRenderDialog *pDlg )
  34. {
  35. SW_ReplayStats_WriteRenderData( true, RenderParams, pDlg, NULL );
  36. }
  37. void CReplayGameStatsHelper::SW_ReplayStats_WriteRenderDataEnd( const RenderMovieParams_t& RenderParams, const char *pEndReason )
  38. {
  39. SW_ReplayStats_WriteRenderData( false, RenderParams, NULL, pEndReason );
  40. }
  41. void CReplayGameStatsHelper::SW_ReplayStats_WriteRenderData( bool bStarting, const RenderMovieParams_t& RenderParams,
  42. const CReplayRenderDialog *pDlg, const char *pEndReason/*=NULL*/ )
  43. {
  44. #if !defined( NO_STEAM )
  45. #if defined( REPLAY_ENABLED )
  46. static uint32 s_iReplayRenderCounter = 0;
  47. ReplayHandle_t hReplay = RenderParams.m_hReplay;
  48. CGenericClassBasedReplay *pReplay = GetGenericClassBasedReplay( hReplay );
  49. if ( !pReplay )
  50. return;
  51. KeyValues* pKVData = new KeyValues( "TF2ReplayRenders" );
  52. // Base settings/DB key.
  53. pKVData->SetInt( "RenderCounter", s_iReplayRenderCounter++ );
  54. pKVData->SetInt( "ReplayHandle", hReplay );
  55. pKVData->SetInt( "PeformanceIndex", RenderParams.m_iPerformance );
  56. // Dialog-specific
  57. if ( pDlg )
  58. {
  59. pKVData->SetInt( "ShowAdvancedChecked", pDlg->m_pShowAdvancedOptionsCheck->IsSelected() );
  60. pKVData->SetString( "CodecID", ReplayVideo_GetCodec( pDlg->m_pCodecCombo->GetActiveItem() ).m_pName );
  61. pKVData->SetInt( "RenderQualityPreset", pDlg->m_iQualityPreset );
  62. }
  63. // Render settings
  64. CFmtStr fmtResolution( "%ix%i", RenderParams.m_Settings.m_nWidth, RenderParams.m_Settings.m_nHeight );
  65. pKVData->SetInt( "QuitWhenDoneChecked", RenderParams.m_bQuitWhenFinished );
  66. pKVData->SetString( "ResolutionID", fmtResolution.Access() );
  67. pKVData->SetInt( "AAEnabled", RenderParams.m_Settings.m_bAAEnabled );
  68. pKVData->SetInt( "MotionBlurEnabled", RenderParams.m_Settings.m_bMotionBlurEnabled );
  69. pKVData->SetInt( "MotionBlurQuality", RenderParams.m_Settings.m_nMotionBlurQuality );
  70. pKVData->SetInt( "RenderQuality", RenderParams.m_Settings.m_nEncodingQuality);
  71. pKVData->SetInt( "ExportRawChecked", RenderParams.m_bExportRaw );
  72. pKVData->SetInt( "FPSUPF", RenderParams.m_Settings.m_FPS.GetUnitsPerFrame() );
  73. pKVData->SetInt( "FPSUPS", RenderParams.m_Settings.m_FPS.GetUnitsPerSecond() );
  74. // Replay content.
  75. pKVData->SetString( "MapID", pReplay->GetMapName() );
  76. pKVData->SetString( "PlayerClassID", pReplay->GetPlayerClass() );
  77. pKVData->SetInt( "ReplayLengthRealtime", pReplay->GetDeathTick() - pReplay->GetSpawnTick() );
  78. CReplayPerformance *pPerformance = pReplay->GetPerformance( RenderParams.m_iPerformance );
  79. if ( pPerformance )
  80. {
  81. int iPerformanceStartTick = pPerformance->HasInTick() ? pPerformance->GetTickIn() : pReplay->GetSpawnTick(),
  82. iPeformanceEndTick = pPerformance->HasOutTick() ? pPerformance->GetTickOut() : pReplay->GetDeathTick();
  83. pKVData->SetInt( "TakeLengthRealtime", iPeformanceEndTick - iPerformanceStartTick );
  84. }
  85. else
  86. {
  87. pKVData->SetInt( "TakeLengthRealtime", pReplay->GetDeathTick() - pReplay->GetSpawnTick() );
  88. }
  89. // Start or end time
  90. pKVData->SetInt( bStarting ? "StartRenderTime" : "EndRenderTime", GetSteamWorksSGameStatsUploader().GetTimeSinceEpoch() );
  91. // Write end reason
  92. if ( !bStarting && pEndReason )
  93. {
  94. pKVData->SetString( "EndRenderReasonID", pEndReason );
  95. }
  96. GetSteamWorksSGameStatsUploader().AddStatsForUpload( pKVData );
  97. #endif // REPLAY_ENABLED
  98. #endif // !defined( NO_STEAM )
  99. }
  100. #endif // defined( CLIENT_DLL )