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