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.

130 lines
3.6 KiB

  1. //========= Copyright 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. void OnKeyCodePressed( KeyCode code )
  78. {
  79. if ( code == KEY_XBUTTON_B )
  80. {
  81. Close();
  82. }
  83. else
  84. {
  85. BaseClass::OnKeyCodePressed(code);
  86. }
  87. }
  88. private:
  89. virtual void OnClose()
  90. {
  91. if ( m_pUploadCheck->IsSelected() )
  92. {
  93. engine->ClientCmd_Unrestricted( "bench_upload\n" );
  94. }
  95. BaseClass::OnClose();
  96. }
  97. vgui::CheckButton *m_pUploadCheck;
  98. };
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Launches the stats dialog
  101. //-----------------------------------------------------------------------------
  102. CON_COMMAND_F( bench_showstatsdialog, "Shows a dialog displaying the most recent benchmark results.", FCVAR_CHEAT )
  103. {
  104. static vgui::DHANDLE<CBenchmarkResultsDialog> g_BenchmarkResultsDialog;
  105. if (!g_BenchmarkResultsDialog.Get())
  106. {
  107. g_BenchmarkResultsDialog = new CBenchmarkResultsDialog( BasePanel(), "BenchmarkResultsDialog" );
  108. }
  109. g_BenchmarkResultsDialog->Activate();
  110. }