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.

118 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "benchmarkdialog.h"
  7. #include "engineinterface.h"
  8. #include "basepanel.h"
  9. #include "tier1/keyvalues.h"
  10. #include "tier1/convar.h"
  11. #include "filesystem.h"
  12. #include "vgui_controls/Button.h"
  13. #include "vgui_controls/CheckButton.h"
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Constructor
  17. //-----------------------------------------------------------------------------
  18. CBenchmarkDialog::CBenchmarkDialog(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
  19. {
  20. Button *button = new Button(this, "RunButton", "RunButton");
  21. button->SetCommand(new KeyValues("RunBenchmark"));
  22. SetSizeable(false);
  23. SetDeleteSelfOnClose(true);
  24. LoadControlSettings("Resource/BenchmarkDialog.res");
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Launches the benchmark
  28. //-----------------------------------------------------------------------------
  29. void CBenchmarkDialog::RunBenchmark()
  30. {
  31. // apply settings
  32. BasePanel()->ApplyOptionsDialogSettings();
  33. // launch the map
  34. engine->ClientCmd_Unrestricted("disconnect\n");
  35. engine->ClientCmd_Unrestricted("wait\n");
  36. engine->ClientCmd_Unrestricted("wait\n");
  37. engine->ClientCmd_Unrestricted("maxplayers 1\n");
  38. engine->ClientCmd_Unrestricted("progress_enable\n");
  39. engine->ClientCmd_Unrestricted("map test_hardware\n");
  40. // close this dialog
  41. Close();
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Displays benchmark results
  45. //-----------------------------------------------------------------------------
  46. class CBenchmarkResultsDialog : public vgui::Frame
  47. {
  48. DECLARE_CLASS_SIMPLE( CBenchmarkResultsDialog, vgui::Frame );
  49. public:
  50. CBenchmarkResultsDialog( vgui::Panel *parent, const char *name ) : BaseClass( parent, name )
  51. {
  52. SetTitle("#GameUI_BenchmarkResults_Title", true);
  53. SetDeleteSelfOnClose(true);
  54. SetSizeable(false);
  55. m_pUploadCheck = new CheckButton( this, "UploadCheck", "#GameUI_BenchmarkResults_UploadNow" );
  56. LoadControlSettings("Resource/BenchmarkResultsDialog.res");
  57. m_pUploadCheck->SetSelected( true );
  58. MoveToCenterOfScreen();
  59. }
  60. virtual void Activate()
  61. {
  62. BaseClass::Activate();
  63. KeyValues *kv = new KeyValues( "Benchmark" );
  64. if ( kv->LoadFromFile( g_pFullFileSystem, "results/results.txt", "MOD" ) )
  65. {
  66. // get the framerate
  67. char szFrameRate[32];
  68. Q_snprintf( szFrameRate, sizeof(szFrameRate), "%.2f", kv->GetFloat("framerate") );
  69. SetDialogVariable( "framerate", szFrameRate );
  70. }
  71. else
  72. {
  73. Close();
  74. }
  75. kv->deleteThis();
  76. }
  77. private:
  78. virtual void OnClose()
  79. {
  80. if ( m_pUploadCheck->IsSelected() )
  81. {
  82. engine->ClientCmd_Unrestricted( "bench_upload\n" );
  83. }
  84. BaseClass::OnClose();
  85. }
  86. vgui::CheckButton *m_pUploadCheck;
  87. };
  88. //-----------------------------------------------------------------------------
  89. // Purpose: Launches the stats dialog
  90. //-----------------------------------------------------------------------------
  91. CON_COMMAND_F( bench_showstatsdialog, "Shows a dialog displaying the most recent benchmark results.", FCVAR_CHEAT )
  92. {
  93. static vgui::DHANDLE<CBenchmarkResultsDialog> g_BenchmarkResultsDialog;
  94. if (!g_BenchmarkResultsDialog.Get())
  95. {
  96. g_BenchmarkResultsDialog = new CBenchmarkResultsDialog( BasePanel(), "BenchmarkResultsDialog" );
  97. }
  98. g_BenchmarkResultsDialog->Activate();
  99. }