commit 4563ed521f1b80e9422093f3721cf5682da41af6
Author: mrfox <jens.se@icloud.com>
AuthorDate: Wed Nov 25 17:17:36 2026 +0100
Commit: mrfox <jens.se@icloud.com>
CommitDate: Wed Nov 25 17:17:36 2026 +0100
xex host: performance overlay fits the 640x480 border
The overlay needed 164 px left of the image; at 3x on 640x480 the border
is 128 px, so it never showed. It is 15 characters wide now and goes over
the image's top left corner when the border is narrower.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
platform/xex/source/XexHost.cpp | 44 ++++++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/platform/xex/source/XexHost.cpp b/platform/xex/source/XexHost.cpp
index 3367103..6e2571c 100644
--- a/platform/xex/source/XexHost.cpp
+++ b/platform/xex/source/XexHost.cpp
@@ -193,6 +193,8 @@ struct PerfAcc { uint64_t sum, max; void add(uint64_t v){ sum += v; if (v > max)
static PerfAcc accEmu = {0,0}, accBlit = {0,0}, accWait = {0,0};
static int perfFrames = 0, perfSlow = 0;
static char perfLines[5][24] = {"", "", "", "", ""};
+static int perfOverlayX = -1; // where it was drawn, -1 when not on screen
+static int perfOverlayCleared = 0;
static inline double tbToMs(uint64_t tb) { return (double)tb * 1000.0 / (double)tbFreq; }
@@ -209,18 +211,32 @@ static void drawText(uint32_t *pixels, int px, int py, const char *str) {
}
}
-// Drawn every frame: the two front buffers alternate.
+// Drawn every frame: the two front buffers alternate. In the border left
+// of the game image when it fits (15 characters = 120 px, the border is
+// 128 px at 3x on 640x480), else over the top left corner of the image.
+static const int PerfChars = 15;
+
static void drawPerfOverlay(uint32_t *pixels) {
- const int widthChars = 20, lines = 5;
- const int w = widthChars * 8;
- if (destX < w + 4) return; // no room beside the image
- const int x = (destX - w) / 2; // centred in the left border
+ const int lines = 5;
+ const int w = PerfChars * 8;
+ if (!perfOverlay && perfOverlayX < 0) return;
+ int x = destX >= w + 4 ? (destX - w) / 2 : 0;
const int y = 8;
- char blank[widthChars + 1];
- memset(blank, ' ', widthChars); blank[widthChars] = 0;
+ if (!perfOverlay) {
+ // turned off: blank where it was, once per front buffer
+ if (perfOverlayX >= 0) {
+ for (int py = y; py < y + lines * 16; py++)
+ for (int px = perfOverlayX; px < perfOverlayX + w; px++) pixels[tiledIndex(px, py)] = OpaqueBlack;
+ if (++perfOverlayCleared >= 2) { perfOverlayX = -1; perfOverlayCleared = 0; clearFrames = 2; }
+ }
+ return;
+ }
+ perfOverlayX = x;
+ perfOverlayCleared = 0;
+ char padded[PerfChars + 1];
for (int i = 0; i < lines; i++) {
- drawText(pixels, x, y + i * 16, blank);
- if (perfOverlay) drawText(pixels, x, y + i * 16, perfLines[i]);
+ snprintf(padded, sizeof(padded), "%-*.*s", PerfChars, PerfChars, perfLines[i]);
+ drawText(pixels, x, y + i * 16, padded);
}
}
@@ -233,11 +249,11 @@ static void perfFrameDone(uint64_t emuTb, uint64_t waitTb, uint64_t blitTb, uint
if (t - perfWindowStart >= tbFreq) {
int n = perfFrames ? perfFrames : 1;
- snprintf(perfLines[0], 24, "%s %dfps slow %d", vsyncMode ? "vsync" : "timer", perfFrames, perfSlow);
- snprintf(perfLines[1], 24, "emu %5.1f/%5.1f", tbToMs(accEmu.sum / n), tbToMs(accEmu.max));
- snprintf(perfLines[2], 24, "blit %5.1f/%5.1f", tbToMs(accBlit.sum / n), tbToMs(accBlit.max));
- snprintf(perfLines[3], 24, "wait %5.1f/%5.1f", tbToMs(accWait.sum / n), tbToMs(accWait.max));
- snprintf(perfLines[4], 24, "%dx%d %dx%d", fbWidth, fbHeight, destW, destH);
+ snprintf(perfLines[0], 24, "%s %dfps s%d", vsyncMode ? "vs" : "tm", perfFrames, perfSlow);
+ snprintf(perfLines[1], 24, "emu %4.1f/%4.1f", tbToMs(accEmu.sum / n), tbToMs(accEmu.max));
+ snprintf(perfLines[2], 24, "blit %4.1f/%4.1f", tbToMs(accBlit.sum / n), tbToMs(accBlit.max));
+ snprintf(perfLines[3], 24, "wait %4.1f/%4.1f", tbToMs(accWait.sum / n), tbToMs(accWait.max));
+ snprintf(perfLines[4], 24, "%dx%d %d", fbWidth, fbHeight, destW);
if (t - perfLogStart >= 5 * tbFreq) {
Logger_Write("perf: %s | %s | %s | %s | %s (avg/max ms)\n", perfLines[0], perfLines[1], perfLines[2], perfLines[3], perfLines[4]);
perfLogStart = t;