Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit f612dec

Browse files
committed
Eliminate intermediate draw steps for performance stats
1 parent 7c28b73 commit f612dec

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ namespace RTE {
5959
g_NetworkServer.Initialize();
6060
g_NetworkClient.Initialize();
6161
g_TimerMan.Initialize();
62-
g_PerformanceMan.Initialize();
6362
g_WindowMan.Initialize();
6463
g_FrameMan.Initialize();
6564
g_PostProcessMan.Initialize();
65+
g_PerformanceMan.Initialize();
6666

6767
if (g_AudioMan.Initialize()) { g_GUISound.Initialize(); }
6868

Managers/PerformanceMan.cpp

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,13 @@ namespace RTE {
2626
m_MSPDs.clear();
2727
m_MSPDAverage = 0;
2828
m_CurrentPing = 0;
29-
m_IntermediateDrawBitmap = nullptr;
30-
m_ColorConversionBitmap = nullptr;
3129
}
3230

3331
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3432

3533
void PerformanceMan::Initialize() {
3634
m_SimUpdateTimer = std::make_unique<Timer>();
3735

38-
m_IntermediateDrawBitmap = create_bitmap_ex(8, 280, 380);
39-
m_ColorConversionBitmap = create_bitmap_ex(FrameMan::c_BPP, 280, 380);
40-
4136
for (int counter = 0; counter < PerformanceCounters::PerfCounterCount; ++counter) {
4237
m_PerfData[counter].fill(0);
4338
m_PerfPercentages[counter].fill(0);
@@ -46,14 +41,6 @@ namespace RTE {
4641
m_PerfMeasureStop.fill(0);
4742
}
4843

49-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50-
51-
void PerformanceMan::Destroy() {
52-
destroy_bitmap(m_IntermediateDrawBitmap);
53-
destroy_bitmap(m_ColorConversionBitmap);
54-
Clear();
55-
}
56-
5744
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5845

5946
void PerformanceMan::StartPerformanceMeasurement(PerformanceCounters counter) {
@@ -127,54 +114,51 @@ namespace RTE {
127114

128115
void PerformanceMan::Draw(BITMAP *bitmapToDrawTo) {
129116
if (m_ShowPerfStats) {
130-
clear_to_color(m_IntermediateDrawBitmap, ColorKeys::g_MaskColor);
131-
AllegroBitmap intermediateDrawBitmap(m_IntermediateDrawBitmap);
117+
AllegroBitmap drawBitmap(bitmapToDrawTo);
132118

133-
GUIFont *guiFont = g_FrameMan.GetLargeFont();
119+
GUIFont *guiFont = g_FrameMan.GetLargeFont(true);
134120
char str[128];
135121

136122
float fps = 1.0F / (m_MSPFAverage / 1000.0F);
137123
float ups = 1.0F / (m_MSPSUAverage / 1000.0F);
138124
std::snprintf(str, sizeof(str), "FPS: %.0f | UPS: %.0f", fps, ups);
139-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight, str, GUIFont::Left);
125+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight, str, GUIFont::Left);
140126

141127
std::snprintf(str, sizeof(str), "Frame: %.1fms | Update: %.1fms | Draw: %.1fms", m_MSPFAverage, m_MSPUAverage, m_MSPDAverage);
142-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 10, str, GUIFont::Left);
128+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 10, str, GUIFont::Left);
143129

144130
std::snprintf(str, sizeof(str), "Time Scale: x%.2f ([1]-, [2]+, [Ctrl+1]Rst)", g_TimerMan.IsOneSimUpdatePerFrame() ? g_TimerMan.GetSimSpeed() : g_TimerMan.GetTimeScale());
145-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 20, str, GUIFont::Left);
131+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 20, str, GUIFont::Left);
146132

147133
std::snprintf(str, sizeof(str), "Real to Sim Cap: %.2f ms ([3]-, [4]+, [Ctrl+3]Rst)", g_TimerMan.GetRealToSimCap() * 1000.0F);
148-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 30, str, GUIFont::Left);
134+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 30, str, GUIFont::Left);
149135

150136
float deltaTime = g_TimerMan.GetDeltaTimeMS();
151137
std::snprintf(str, sizeof(str), "DeltaTime: %.2f ms ([5]-, [6]+, [Ctrl+5]Rst)", deltaTime);
152-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 40, str, GUIFont::Left);
138+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 40, str, GUIFont::Left);
153139

154140
std::snprintf(str, sizeof(str), "Particles: %li", g_MovableMan.GetParticleCount());
155-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 50, str, GUIFont::Left);
141+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 50, str, GUIFont::Left);
156142

157143
std::snprintf(str, sizeof(str), "Objects: %i", g_MovableMan.GetKnownObjectsCount());
158-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 60, str, GUIFont::Left);
144+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 60, str, GUIFont::Left);
159145

160146
std::snprintf(str, sizeof(str), "MOIDs: %i", g_MovableMan.GetMOIDCount());
161-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 70, str, GUIFont::Left);
147+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 70, str, GUIFont::Left);
162148

163149
std::snprintf(str, sizeof(str), "Sim Updates Since Last Drawn: %i", g_TimerMan.SimUpdatesSinceDrawn());
164-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 80, str, GUIFont::Left);
150+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 80, str, GUIFont::Left);
165151

166-
if (g_TimerMan.IsOneSimUpdatePerFrame()) { guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 90, "ONE Sim Update Per Frame!", GUIFont::Left); }
152+
if (g_TimerMan.IsOneSimUpdatePerFrame()) { guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 90, "ONE Sim Update Per Frame!", GUIFont::Left); }
167153

168154
if (int totalPlayingChannelCount = 0, realPlayingChannelCount = 0; g_AudioMan.GetPlayingChannelCount(&totalPlayingChannelCount, &realPlayingChannelCount)) {
169155
std::snprintf(str, sizeof(str), "Sound Channels: %d / %d Real | %d / %d Virtual", realPlayingChannelCount, g_AudioMan.GetTotalRealChannelCount(), totalPlayingChannelCount - realPlayingChannelCount, g_AudioMan.GetTotalVirtualChannelCount());
170156
}
171-
guiFont->DrawAligned(&intermediateDrawBitmap, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
172-
173-
if (m_AdvancedPerfStats) { DrawPeformanceGraphs(intermediateDrawBitmap); }
157+
guiFont->DrawAligned(&drawBitmap, c_StatsOffsetX, c_StatsHeight + 100, str, GUIFont::Left);
174158

175-
// Regular blit performs color conversion from 8bpp to 32bpp, then the converted result is drawn masked to the 32bpp target bitmap.
176-
blit(m_IntermediateDrawBitmap, m_ColorConversionBitmap, 0, 0, 0, 0, m_IntermediateDrawBitmap->w, m_IntermediateDrawBitmap->h);
177-
masked_blit(m_ColorConversionBitmap, bitmapToDrawTo, 0, 0, 0, 0, m_ColorConversionBitmap->w, m_ColorConversionBitmap->h);
159+
if (m_AdvancedPerfStats) {
160+
DrawPeformanceGraphs(drawBitmap);
161+
}
178162
}
179163
}
180164

@@ -183,7 +167,7 @@ namespace RTE {
183167
void PerformanceMan::DrawPeformanceGraphs(AllegroBitmap &bitmapToDrawTo) {
184168
CalculateSamplePercentages();
185169

186-
GUIFont *guiFont = g_FrameMan.GetLargeFont();
170+
GUIFont *guiFont = g_FrameMan.GetLargeFont(true);
187171
char str[128];
188172

189173
for (int pc = 0; pc < PerformanceCounters::PerfCounterCount; ++pc) {
@@ -202,8 +186,8 @@ namespace RTE {
202186
int graphStart = blockStart + c_GraphsOffsetX;
203187

204188
// Draw graph backgrounds.
205-
bitmapToDrawTo.DrawRectangle(c_StatsOffsetX, graphStart, c_MaxSamples, c_GraphHeight, 240, true);
206-
bitmapToDrawTo.DrawLine(c_StatsOffsetX, graphStart + c_GraphHeight / 2, c_StatsOffsetX - 1 + c_MaxSamples, graphStart + c_GraphHeight / 2, 96);
189+
bitmapToDrawTo.DrawRectangle(c_StatsOffsetX, graphStart, c_MaxSamples, c_GraphHeight, makecol32(96, 19, 32), true); // Palette index 240.
190+
bitmapToDrawTo.DrawLine(c_StatsOffsetX, graphStart + c_GraphHeight / 2, c_StatsOffsetX - 1 + c_MaxSamples, graphStart + c_GraphHeight / 2, makecol32(200, 206, 140)); // Palette index 96.
207191

208192
// Draw sample dots.
209193
int peak = 0;
@@ -213,7 +197,7 @@ namespace RTE {
213197
int value = std::clamp(static_cast<int>(static_cast<float>(m_PerfData[pc][sample]) / (g_TimerMan.GetRealToSimCap() * 1000000.0F) * 100.0F), 0, 100);
214198
int dotHeight = static_cast<int>(static_cast<float>(c_GraphHeight) / 100.0F * static_cast<float>(value));
215199

216-
bitmapToDrawTo.SetPixel(c_StatsOffsetX - 1 + c_MaxSamples - i, graphStart + c_GraphHeight - dotHeight, 13);
200+
bitmapToDrawTo.SetPixel(c_StatsOffsetX - 1 + c_MaxSamples - i, graphStart + c_GraphHeight - dotHeight, makecol32(234, 21, 7)); // Palette index 13.
217201

218202
if (peak < m_PerfData[pc][sample]) { peak = static_cast<int>(m_PerfData[pc][sample]); }
219203

Managers/PerformanceMan.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace RTE {
5353
/// <summary>
5454
/// Destroys and resets (through Clear()) the PerformanceMan object.
5555
/// </summary>
56-
void Destroy();
56+
void Destroy() { Clear(); }
5757
#pragma endregion
5858

5959
#pragma region Getters and Setters
@@ -181,9 +181,6 @@ namespace RTE {
181181
std::array<uint64_t, PerformanceCounters::PerfCounterCount> m_PerfMeasureStart; //!< Current measurement start time in microseconds.
182182
std::array<uint64_t, PerformanceCounters::PerfCounterCount> m_PerfMeasureStop; //!< Current measurement stop time in microseconds.
183183

184-
BITMAP *m_IntermediateDrawBitmap; //!< BITMAP for drawing GUIFont in 8bpp mode (as it does not support 32bpp drawing) before drawing onto the 32bpp color conversion BITMAP.
185-
BITMAP *m_ColorConversionBitmap; //!< BITMAP for converting the 8bpp intermediate BITMAP to 32bpp for drawing onto the target BITMAP.
186-
187184
private:
188185

189186
#pragma region Performance Counter Handling

0 commit comments

Comments
 (0)