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.

171 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Does anyone ever read this?
  4. //
  5. //===========================================================================//
  6. #include "client_pch.h"
  7. #include "vgui_budgetpanel.h"
  8. #include "vgui_controls/Label.h"
  9. #include "vgui_baseui_interface.h"
  10. #include "tier0/vprof.h"
  11. #include "tier0/fasttimer.h"
  12. #include "materialsystem/imaterialsystem.h"
  13. #include "VGuiMatSurface/IMatSystemSurface.h"
  14. #include "vgui/IScheme.h"
  15. #include "convar.h"
  16. #include "ivrenderview.h"
  17. #include "engine/ivmodelinfo.h"
  18. #include "mathlib/mathlib.h"
  19. #include "gl_cvars.h"
  20. #include "gl_matsysiface.h"
  21. #include "materialsystem/imaterialsystemhardwareconfig.h"
  22. #include "cmd.h"
  23. #include "vgui/IVGui.h"
  24. #include "vprof_engine.h"
  25. #include "ivprofexport.h"
  26. #include "vprof_record.h"
  27. #include "tier2/tier2.h"
  28. // memdbgon must be the last include file in a .cpp file!!!
  29. #include "tier0/memdbgon.h"
  30. #ifdef VPROF_ENABLED
  31. CON_COMMAND( vprof_adddebuggroup1, "add a new budget group dynamically for debugging" )
  32. {
  33. VPROF_BUDGET( "vprof_adddebuggroup1", "vprof_adddebuggroup1" );
  34. }
  35. void IN_BudgetDown(void)
  36. {
  37. GetBudgetPanel()->UserCmd_ShowBudgetPanel();
  38. }
  39. void IN_BudgetUp(void)
  40. {
  41. GetBudgetPanel()->UserCmd_HideBudgetPanel();
  42. }
  43. static ConCommand startshowbudget("+showbudget", IN_BudgetDown, "" );
  44. static ConCommand endshowbudget("-showbudget", IN_BudgetUp, "" );
  45. // Globals.
  46. static CBudgetPanelEngine *g_pBudgetPanel = NULL;
  47. CBudgetPanelEngine *GetBudgetPanel( void )
  48. {
  49. return g_pBudgetPanel;
  50. }
  51. CBudgetPanelEngine::CBudgetPanelEngine( vgui::Panel *pParent, const char *pElementName )
  52. : BaseClass( pParent, pElementName, BUDGETFLAG_CLIENT | BUDGETFLAG_OTHER | BUDGETFLAG_HIDDEN )
  53. {
  54. g_pBudgetPanel = this;
  55. m_bShowBudgetPanelHeld = false;
  56. }
  57. CBudgetPanelEngine::~CBudgetPanelEngine()
  58. {
  59. Assert( g_pBudgetPanel == this );
  60. g_pBudgetPanel = NULL;
  61. }
  62. void CBudgetPanelEngine::PostChildPaint()
  63. {
  64. int r = 255;
  65. int g = 0;
  66. int nDXSupportLevel = g_pMaterialSystemHardwareConfig->GetDXSupportLevel();
  67. if( ( g_fFrameRate >= 60 )
  68. || ( nDXSupportLevel <= 80 && g_fFrameRate >= 30 )
  69. || ( nDXSupportLevel <= 70 && g_fFrameRate >= 20 ) )
  70. {
  71. r = 0;
  72. g = 255;
  73. }
  74. int yPos = 20;
  75. g_pMatSystemSurface->DrawColoredText( m_hFont, 600, yPos, r, g, 0, 255, "%3i fps (showbudget 3D driver time included)", RoundFloatToInt(g_fFrameRate) );
  76. yPos += 14;
  77. g_pMatSystemSurface->DrawColoredText( m_hFont, 600, yPos, r, g, 0, 255, "%5.1f ms", g_fFrameTimeLessBudget*1000.0f );
  78. yPos += 14;
  79. #ifndef _XBOX
  80. if ( VProfRecord_IsPlayingBack() )
  81. {
  82. int iCur = VProfPlayback_GetCurrentTick();
  83. char str[512];
  84. Q_snprintf( str, sizeof( str ), "VPROF playback (tick %d, %d%%)", iCur, (int)(VProfPlayback_GetCurrentPercent() * 100) );
  85. g_pMatSystemSurface->DrawColoredText( m_hFont, 600, yPos, 255, 0, 0, 255, "%s", str );
  86. yPos += 14;
  87. }
  88. #endif
  89. BaseClass::PostChildPaint();
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. //-----------------------------------------------------------------------------
  94. void CBudgetPanelEngine::UserCmd_ShowBudgetPanel( void )
  95. {
  96. Cbuf_AddText( "vprof_on\n" );
  97. m_bShowBudgetPanelHeld = true;
  98. SetVisible( true );
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. //-----------------------------------------------------------------------------
  103. void CBudgetPanelEngine::UserCmd_HideBudgetPanel( void )
  104. {
  105. Cbuf_AddText( "vprof_off\n" );
  106. m_bShowBudgetPanelHeld = false;
  107. SetVisible( false );
  108. }
  109. void CBudgetPanelEngine::OnTick()
  110. {
  111. // Go away if we were on and sv_cheats is now on.
  112. if ( m_bShowBudgetPanelHeld && !CanCheat() )
  113. {
  114. UserCmd_HideBudgetPanel();
  115. }
  116. BaseClass::OnTick();
  117. SetVisible(m_bShowBudgetPanelHeld);
  118. }
  119. void CBudgetPanelEngine::SetTimeLabelText()
  120. {
  121. for ( int i=0; i < m_TimeLabels.Count(); i++ )
  122. {
  123. char text[512];
  124. Q_snprintf( text, sizeof( text ), "%dms", (int)( i * GetConfigData().m_flTimeLabelInterval ) );
  125. m_TimeLabels[i]->SetText( text );
  126. }
  127. }
  128. void CBudgetPanelEngine::SetHistoryLabelText()
  129. {
  130. Assert( m_HistoryLabels.Count() == 3 );
  131. m_HistoryLabels[0]->SetText( "20 fps (50 ms)" );
  132. m_HistoryLabels[1]->SetText( "30 fps (33 1/3 ms)" );
  133. m_HistoryLabels[2]->SetText( "60 fps (16 2/3 ms)" );
  134. }
  135. bool CBudgetPanelEngine::IsBudgetPanelShown() const
  136. {
  137. return m_bShowBudgetPanelHeld;
  138. }
  139. #endif // VPROF_ENABLED