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.

182 lines
4.5 KiB

  1. //===== Copyright � 1996-2005, 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. CBudgetPanelEngine *panel = GetBudgetPanel();
  38. Assert( panel != NULL );
  39. if( panel != NULL )
  40. {
  41. panel->UserCmd_ShowBudgetPanel();
  42. }
  43. }
  44. void IN_BudgetUp(void)
  45. {
  46. CBudgetPanelEngine *panel = GetBudgetPanel();
  47. Assert( panel != NULL );
  48. if( panel != NULL )
  49. {
  50. panel->UserCmd_HideBudgetPanel();
  51. }
  52. }
  53. static ConCommand startshowbudget("+showbudget", IN_BudgetDown, "", FCVAR_CHEAT);
  54. static ConCommand endshowbudget("-showbudget", IN_BudgetUp, "", FCVAR_CHEAT);
  55. // Globals.
  56. static CBudgetPanelEngine *g_pBudgetPanel = NULL;
  57. CBudgetPanelEngine *GetBudgetPanel( void )
  58. {
  59. return g_pBudgetPanel;
  60. }
  61. CBudgetPanelEngine::CBudgetPanelEngine( vgui::Panel *pParent, const char *pElementName )
  62. : BaseClass( pParent, pElementName, BUDGETFLAG_CLIENT | BUDGETFLAG_OTHER | BUDGETFLAG_HIDDEN )
  63. {
  64. g_pBudgetPanel = this;
  65. m_bShowBudgetPanelHeld = false;
  66. }
  67. CBudgetPanelEngine::~CBudgetPanelEngine()
  68. {
  69. Assert( g_pBudgetPanel == this );
  70. g_pBudgetPanel = NULL;
  71. }
  72. void CBudgetPanelEngine::PostChildPaint()
  73. {
  74. int r = 255;
  75. int g = 0;
  76. int nDXSupportLevel = g_pMaterialSystemHardwareConfig->GetDXSupportLevel();
  77. if( ( g_fFrameRate >= 60 )
  78. || ( nDXSupportLevel <= 92 && g_fFrameRate >= 30 )
  79. || ( nDXSupportLevel <= 90 && g_fFrameRate >= 20 ) )
  80. {
  81. r = 0;
  82. g = 255;
  83. }
  84. int yPos = 20;
  85. g_pMatSystemSurface->DrawColoredText( m_hFont, 600, yPos, r, g, 0, 255, "%3i fps (showbudget 3D driver time included)", RoundFloatToInt(g_fFrameRate) );
  86. yPos += 14;
  87. g_pMatSystemSurface->DrawColoredText( m_hFont, 600, yPos, r, g, 0, 255, "%5.1f ms", g_fFrameTimeLessBudget*1000.0f );
  88. yPos += 14;
  89. if ( VProfRecord_IsPlayingBack() )
  90. {
  91. int iCur = VProfPlayback_GetCurrentTick();
  92. char str[512];
  93. Q_snprintf( str, sizeof( str ), "VPROF playback (tick %d, %d%%)", iCur, (int)(VProfPlayback_GetCurrentPercent() * 100) );
  94. g_pMatSystemSurface->DrawColoredText( m_hFont, 600, yPos, 255, 0, 0, 255, "%s", str );
  95. yPos += 14;
  96. }
  97. BaseClass::PostChildPaint();
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose:
  101. //-----------------------------------------------------------------------------
  102. void CBudgetPanelEngine::UserCmd_ShowBudgetPanel( void )
  103. {
  104. Cbuf_AddText( Cbuf_GetCurrentPlayer(), "vprof_on\n" );
  105. m_bShowBudgetPanelHeld = true;
  106. SetVisible( true );
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. void CBudgetPanelEngine::UserCmd_HideBudgetPanel( void )
  112. {
  113. Cbuf_AddText( Cbuf_GetCurrentPlayer(), "vprof_off\n" );
  114. m_bShowBudgetPanelHeld = false;
  115. SetVisible( false );
  116. }
  117. void CBudgetPanelEngine::OnTick()
  118. {
  119. // Go away if we were on and sv_cheats is now on.
  120. if ( m_bShowBudgetPanelHeld && !CanCheat() )
  121. {
  122. UserCmd_HideBudgetPanel();
  123. }
  124. BaseClass::OnTick();
  125. SetVisible(m_bShowBudgetPanelHeld);
  126. }
  127. void CBudgetPanelEngine::SetTimeLabelText()
  128. {
  129. for ( int i=0; i < m_TimeLabels.Count(); i++ )
  130. {
  131. char text[512];
  132. Q_snprintf( text, sizeof( text ), "%dms", (int)( i * GetConfigData().m_flTimeLabelInterval ) );
  133. m_TimeLabels[i]->SetText( text );
  134. }
  135. }
  136. void CBudgetPanelEngine::SetHistoryLabelText()
  137. {
  138. Assert( m_HistoryLabels.Count() == 3 );
  139. m_HistoryLabels[0]->SetText( "20 fps (50 ms)" );
  140. m_HistoryLabels[1]->SetText( "30 fps (33 1/3 ms)" );
  141. m_HistoryLabels[2]->SetText( "60 fps (16 2/3 ms)" );
  142. }
  143. bool CBudgetPanelEngine::IsBudgetPanelShown() const
  144. {
  145. return m_bShowBudgetPanelHeld;
  146. }
  147. #endif // VPROF_ENABLED