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.

156 lines
3.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "quakedef.h"
  8. #include "enginestats.h"
  9. #include "basetypes.h"
  10. #include "clientstats.h"
  11. #include "limits.h"
  12. #include "sysexternal.h"
  13. #include "gl_matsysiface.h"
  14. #include "filesystem_engine.h"
  15. #include "tier0/vprof.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. //-----------------------------------------------------------------------------
  19. // itty bitty interface for stat time
  20. //-----------------------------------------------------------------------------
  21. class CStatTime : public IClientStatsTime
  22. {
  23. public:
  24. float GetTime()
  25. {
  26. return Sys_FloatTime();
  27. }
  28. };
  29. CStatTime g_StatTime;
  30. CEngineStats::CEngineStats() : m_InFrame( false )
  31. {
  32. m_bInRun = false;
  33. m_szVProfStatsFileName[0] = '\0';
  34. }
  35. #ifdef VPROF_ENABLED
  36. extern void VProf_StartRecording( const char *pFilename );
  37. extern void VProf_StopRecording( void );
  38. #endif
  39. void CEngineStats::BeginRun( void )
  40. {
  41. m_bInRun = true;
  42. m_totalNumFrames = 0;
  43. #ifdef VPROF_ENABLED
  44. if ( m_szVProfStatsFileName[0] != '\0' )
  45. {
  46. VProf_StartRecording( m_szVProfStatsFileName );
  47. }
  48. #endif
  49. // frame timing data
  50. m_runStartTime = Sys_FloatTime();
  51. }
  52. void CEngineStats::EndRun( void )
  53. {
  54. m_runEndTime = Sys_FloatTime();
  55. m_bInRun = false;
  56. #ifdef VPROF_ENABLED
  57. if ( m_szVProfStatsFileName[0] != '\0' )
  58. {
  59. VProf_StopRecording();
  60. m_szVProfStatsFileName[0] = '\0';
  61. }
  62. #endif
  63. }
  64. void CEngineStats::BeginFrame( void )
  65. {
  66. m_bPaused = false;
  67. m_InFrame = false;
  68. }
  69. void CEngineStats::ComputeFrameTimeStats( void )
  70. {
  71. m_StatGroup.m_StatFrameTime[ENGINE_STATS_FRAME_TIME] = m_flFrameTime / 1000.0f;
  72. m_StatGroup.m_StatFrameTime[ENGINE_STATS_FPS_VARIABILITY] = m_flFPSVariability / 1000.0f;
  73. m_StatGroup.m_StatFrameTime[ENGINE_STATS_FPS] = (m_flFrameTime != 0.0f) ? ( 1.0f / (1000.0f * m_flFrameTime) ) : 0.0f;
  74. }
  75. void CEngineStats::EndFrame( void )
  76. {
  77. if (!m_InFrame)
  78. return;
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Advances the next frame for the stats...
  82. //-----------------------------------------------------------------------------
  83. void CEngineStats::NextFrame()
  84. {
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Pause those stats!
  88. //-----------------------------------------------------------------------------
  89. void CEngineStats::PauseStats( bool bPaused )
  90. {
  91. if (bPaused)
  92. {
  93. if (m_InFrame)
  94. {
  95. m_bPaused = true;
  96. m_InFrame = false;
  97. }
  98. }
  99. else // !bPaused
  100. {
  101. if (m_bPaused)
  102. {
  103. m_InFrame = true;
  104. m_bPaused = false;
  105. }
  106. }
  107. }
  108. //-----------------------------------------------------------------------------
  109. // returns timed stats
  110. //-----------------------------------------------------------------------------
  111. double CEngineStats::TimedStatInFrame( EngineTimedStatId_t stat ) const
  112. {
  113. return m_StatGroup.m_StatFrameTime[stat];
  114. }
  115. double CEngineStats::TotalTimedStat( EngineTimedStatId_t stat ) const
  116. {
  117. return m_StatGroup.m_TotalStatTime[stat];
  118. }
  119. double CEngineStats::GetRunTime( void )
  120. {
  121. return m_runEndTime - m_runStartTime;
  122. }
  123. void CEngineStats::EnableVProfStatsRecording( const char *pFileName )
  124. {
  125. Q_strncpy( m_szVProfStatsFileName, pFileName, sizeof( m_szVProfStatsFileName ) );
  126. }