forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientstats.h
198 lines (155 loc) · 6.06 KB
/
clientstats.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#if !defined( CLIENTSTATS_H )
#define CLIENTSTATS_H
#ifdef _WIN32
#pragma once
#endif
#include "interface.h"
#include <limits.h>
#include "tier0/dbg.h"
#define INTERFACEVERSION_CLIENTSTATS "ClientStats004"
//-----------------------------------------------------------------------------
// An interface used to help the client stats implementation tell time
//-----------------------------------------------------------------------------
struct IClientStatsTime
{
virtual float GetTime() = 0;
};
//-----------------------------------------------------------------------------
// Allows clients to draw their own stats text, will be passed by the
// engine into DisplayStats of the IClientStats interface.
//-----------------------------------------------------------------------------
struct IClientStatsTextDisplay
{
// Draws the stats
virtual void DrawStatsText( PRINTF_FORMAT_STRING const char *fmt, ... ) = 0;
virtual void SetDrawColor( unsigned char r, unsigned char g, unsigned char b ) = 0;
// Sets a color based on a value and its max acceptable limit
virtual void SetDrawColorFromStatValues( float limit, float value ) = 0;
};
//-----------------------------------------------------------------------------
// This will exist as a singleton within the client DLL and will be hooked into
// the engine to allow clients to render their own stats.
//-----------------------------------------------------------------------------
abstract_class IClientStats
{
public:
// This is called at startup to tell the stats about time
virtual void Init( IClientStatsTime* pTime ) = 0;
// These methods are called at the beginning and the end of each run
virtual void BeginRun() = 0;
virtual void EndRun() = 0;
// These methods are called at the beginning and the end of each frame
virtual void BeginFrame() = 0;
virtual void EndFrame() = 0;
// ---------------------------------------------------------------
// All this stuff is used to prop stats for gathering r_speeds data during timedemo.
// ---------------------------------------------------------------
virtual int GetNumTimesStats( void ) const = 0;
// returns timed stats
virtual double TimedStatInFrame( int statID ) const = 0;
virtual double TotalTimedStat( int statID ) const = 0;
};
//-----------------------------------------------------------------------------
// This is a templatized implementation which can be instantiated anywhere
// Note that you still have to install it and display it though.
//-----------------------------------------------------------------------------
template <int timedStatCount, int countedStatCount>
abstract_class CBaseClientStats : public IClientStats
{
public:
void Init( IClientStatsTime* pTime );
void BeginRun();
void EndRun();
void BeginFrame();
void EndFrame();
// Timed stat gathering
void BeginTimedStat( int stat );
void EndTimedStat( int stat );
// ---------------------------------------------------------------
// All this stuff is used to prop stats for gathering r_speeds data during timedemo.
// ---------------------------------------------------------------
// returns timed stats
double TimedStatInFrame( int statID ) const
{
Assert( statID >= 0 && statID < timedStatCount );
Assert( m_StatFrameTime[statID] >= 0.0 );
return m_StatFrameTime[statID];
}
double TotalTimedStat( int statID ) const
{
Assert( statID >= 0 && statID < timedStatCount );
return m_TotalStatTime[statID];
}
virtual const char *GetCountedStatName( int statID ) const = 0;
virtual const char *GetTimedStatName( int statID ) const = 0;
protected:
// Timed statistics
double m_StatFrameTime[timedStatCount];
double m_StatStartTime[timedStatCount];
double m_TotalStatTime[timedStatCount];
private:
IClientStatsTime* m_pTime;
};
//-----------------------------------------------------------------------------
// Initializes client stats
//-----------------------------------------------------------------------------
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::Init( IClientStatsTime* pTime )
{
Assert( pTime );
m_pTime = pTime;
}
//-----------------------------------------------------------------------------
// These methods are called at the beginning and the end of each run
//-----------------------------------------------------------------------------
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::BeginRun()
{
int i;
for (i = 0; i < timedStatCount; ++i)
m_TotalStatTime[i] = 0.0;
}
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::EndRun()
{
}
//-----------------------------------------------------------------------------
// These methods are called at the beginning and the end of each frame
//-----------------------------------------------------------------------------
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::BeginFrame()
{
int i;
for (i = 0; i < timedStatCount; ++i)
m_StatFrameTime[i] = 0.0;
}
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::EndFrame()
{
int i;
for (i = 0; i < timedStatCount; ++i)
m_TotalStatTime[i] += m_StatFrameTime[i];
}
//-----------------------------------------------------------------------------
// Inlined stat gathering methods
//-----------------------------------------------------------------------------
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::BeginTimedStat( int stat )
{
if (m_pTime)
m_StatStartTime[stat] = m_pTime->GetTime();
}
template <int timedStatCount, int countedStatCount>
void CBaseClientStats<timedStatCount, countedStatCount>::EndTimedStat( int stat )
{
if (m_pTime)
m_StatFrameTime[stat] += m_pTime->GetTime() - m_StatStartTime[stat];
}
#endif // CLIENTSTATS_H