12
12
13
13
namespace
14
14
{
15
- #define GRAPHSTAT_HISTORY_SIZE 256
16
-
17
15
struct SGraphStatLine
18
16
{
19
17
TIMEUS prevData;
@@ -113,6 +111,11 @@ void CGraphStats::AddTimingPoint(const char* szName)
113
111
if (!IsEnabled ())
114
112
return ;
115
113
114
+ CGraphicsInterface* pGraphics = g_pCore->GetGraphics ();
115
+
116
+ std::uint32_t viewportWidth = pGraphics->GetViewportWidth ();
117
+ std::uint32_t sizeX = viewportWidth / 4 ; // one quarter of screen width
118
+
116
119
// Start of next frame?
117
120
if (szName[0 ] == 0 )
118
121
{
@@ -133,7 +136,7 @@ void CGraphStats::AddTimingPoint(const char* szName)
133
136
for (int i = 0 ; i < Dups; i++)
134
137
{
135
138
pLine->iDataPos ++;
136
- if (pLine->iDataPos > GRAPHSTAT_HISTORY_SIZE - 1 )
139
+ if (pLine->iDataPos > sizeX - 1 )
137
140
pLine->iDataPos = 0 ;
138
141
pLine->dataHistory [pLine->iDataPos ] = Data;
139
142
}
@@ -153,7 +156,7 @@ void CGraphStats::AddTimingPoint(const char* szName)
153
156
// Add new line
154
157
MapSet (m_LineList, szName, SGraphStatLine ());
155
158
pLine = MapFind (m_LineList, szName);
156
- pLine->dataHistory .resize (GRAPHSTAT_HISTORY_SIZE );
159
+ pLine->dataHistory .resize (sizeX );
157
160
memset (&pLine->dataHistory [0 ], 0 , pLine->dataHistory .size ());
158
161
pLine->iDataPos = 0 ;
159
162
pLine->prevData = 0 ;
@@ -179,7 +182,7 @@ void CGraphStats::AddTimingPoint(const char* szName)
179
182
180
183
// Inc position
181
184
pLine->iDataPos ++;
182
- if (pLine->iDataPos > GRAPHSTAT_HISTORY_SIZE - 1 )
185
+ if (pLine->iDataPos > sizeX - 1 )
183
186
pLine->iDataPos = 0 ;
184
187
185
188
// Insert data point
@@ -199,44 +202,49 @@ void CGraphStats::Draw()
199
202
return ;
200
203
201
204
CGraphicsInterface* pGraphics = g_pCore->GetGraphics ();
205
+ CLocalGUI* pLocalGUI = g_pCore->GetLocalGUI ();
206
+
207
+ std::uint32_t viewportWidth = pGraphics->GetViewportWidth (); // get width of current resolution
208
+ std::uint32_t viewportHeight = pGraphics->GetViewportHeight (); // get height of current resolution
209
+ std::uint32_t originX = 10 ; // offset the graph by 10 pixels from left side of screen
210
+ std::uint32_t originY = pLocalGUI->GetChatBottomPosition (); // get chat bottom screen position
211
+ std::uint32_t sizeX = viewportWidth / 4 ; // set the width of graph to 1/4 of current resolution
212
+ std::uint32_t sizeY = viewportHeight / 4 ; // set the height of graph to 1/4 of current resolution
213
+ std::uint32_t rangeY = 100 ; // 100ms
214
+
215
+ originY = originY + sizeY + 30 ; // add graph height plus a little gap to the overall Y position
202
216
203
- uint uiViewportHeight = pGraphics->GetViewportHeight ();
204
- uint uiOriginX = 10 ;
205
- uint uiOriginY = std::min<int >(500 , uiViewportHeight - 10 );
206
- uint uiSizeX = GRAPHSTAT_HISTORY_SIZE;
207
- uint uiSizeY = 150 ;
208
- uint uiRangeY = 100 ; // 100ms
209
- float fLineScale = 1 / 1000 .f / uiRangeY * uiSizeY;
217
+ float fLineScale = 1 / 1000 .f / rangeY * sizeY;
210
218
float fLineHeight = pGraphics->GetDXFontHeight ();
211
219
212
220
// Backgroung box
213
- pGraphics->DrawRectQueued (uiOriginX, uiOriginY - uiSizeY, uiSizeX, uiSizeY , SColorRGBA (0 , 0 , 0 , 128 ), true );
221
+ pGraphics->DrawRectQueued (originX, originY - sizeY, sizeX, sizeY , SColorRGBA (0 , 0 , 0 , 128 ), true );
214
222
215
223
// Draw data lines
216
- float fLabelX = uiOriginX + uiSizeX + 22 ;
217
- float fLabelY = uiOriginY - m_LineList.size () * fLineHeight ;
224
+ float fLabelX = originX + sizeX + 22 ;
225
+ float fLabelY = originY - m_LineList.size () * fLineHeight ;
218
226
for (const auto & dataLine : m_LineList)
219
227
{
220
228
const SGraphStatLine& line = dataLine.second ;
221
229
int iDataPos = line.iDataPos ;
222
230
int iDataPosPrev = iDataPos;
223
231
224
- for (int i = uiSizeX - 1 ; i > 0 ; i--)
232
+ for (int i = sizeX - 1 ; i > 0 ; i--)
225
233
{
226
234
float fY0 = line.dataHistory [iDataPos] * fLineScale ;
227
235
float fY1 = line.dataHistory [iDataPosPrev] * fLineScale ;
228
236
229
237
iDataPosPrev = iDataPos;
230
238
iDataPos--;
231
239
if (iDataPos == -1 )
232
- iDataPos = GRAPHSTAT_HISTORY_SIZE - 1 ;
240
+ iDataPos = sizeX - 1 ;
233
241
234
- pGraphics->DrawLineQueued (uiOriginX + i - 1 , uiOriginY - fY0 , uiOriginX + i, uiOriginY - fY1 , 1 , line.color , true );
242
+ pGraphics->DrawLineQueued (originX + i - 1 , originY - fY0 , originX + i, originY - fY1 , 1 , line.color , true );
235
243
236
- if (i == uiSizeX - 1 )
244
+ if (i == sizeX - 1 )
237
245
{
238
246
// Line from graph to label
239
- pGraphics->DrawLineQueued (uiOriginX + i - 1 , uiOriginY - fY0 , fLabelX - 2 , fLabelY + fLineHeight / 2 , 1 , line.color , true );
247
+ pGraphics->DrawLineQueued (originX + i - 1 , originY - fY0 , fLabelX - 2 , fLabelY + fLineHeight / 2 , 1 , line.color , true );
240
248
}
241
249
}
242
250
0 commit comments