devmode DEMO: replay buffer usage displayed in real-time on the HUD

- Buffer usage in megabytes, bytes and percentage
- Approximate usage per second
- Estimated time until buffer runs out and replay is stopped
This commit is contained in:
James R 2024-01-29 02:20:23 -08:00
parent 09b90c3cf1
commit a879975e83
5 changed files with 37 additions and 0 deletions

View file

@ -548,6 +548,7 @@ typedef enum
DBG_SETUP = 0x00000400,
DBG_LUA = 0x00000800,
DBG_RNG = 0x00001000,
DBG_DEMO = 0x00002000,
} debugFlags_t;
struct debugFlagNames_s

View file

@ -2106,6 +2106,7 @@ void G_RecordDemo(const char *name)
demobuf.p = NULL;
demo.recording = true;
demo.buffer = &demobuf;
}
void G_RecordMetal(void)
@ -3243,6 +3244,7 @@ void G_DoPlayDemo(const char *defdemoname)
// read demo header
gameaction = ga_nothing;
demo.playback = true;
demo.buffer = &demobuf;
if (memcmp(demobuf.p, DEMOHEADER, 12))
{
snprintf(msg, 1024, M_GetText("%s is not a Ring Racers replay file.\n"), pdemoname);

View file

@ -65,6 +65,8 @@ struct demovars_s {
UINT8 numskins;
democharlist_t *skinlist;
UINT8 currentskinid[MAXPLAYERS];
const savebuffer_t *buffer; // debug, valid only if recording or playback
};
extern struct demovars_s demo;

View file

@ -605,6 +605,8 @@ struct debugFlagNames_s const debug_flag_names[] =
{"Music", DBG_MUSIC},
{"PwrLv", DBG_PWRLV},
{"PowerLevel", DBG_PWRLV}, // alt name
{"Demo", DBG_DEMO},
{"Replay", DBG_DEMO}, // alt name
{NULL, 0}
};

View file

@ -448,6 +448,31 @@ static void ST_drawRenderDebug(INT32 *height)
ST_pushDebugString(height, va("Skybox Portals: %4s", sizeu1(i->skybox_portals)));
}
static void ST_drawDemoDebug(INT32 *height)
{
if (!demo.recording && !demo.playback)
return;
size_t needle = demo.buffer->p - demo.buffer->buffer;
size_t size = demo.buffer->size;
double percent = (double)needle / size * 100.0;
double avg = (double)needle / leveltime;
ST_pushDebugString(height, va("%s/%s bytes", sizeu1(needle), sizeu2(size)));
ST_pushDebugString(height, va(
"%.2f/%.2f MB %5.2f%%",
needle / (1024.0 * 1024.0),
size / (1024.0 * 1024.0),
percent
));
ST_pushDebugString(height, va(
"%.2f KB/s (ETA %.2f minutes)",
avg * TICRATE / 1024.0,
(size - needle) / (avg * TICRATE * 60.0)
));
ST_pushDebugString(height, va("Demo (%s)", demo.recording ? "recording" : "playback"));
}
void ST_drawDebugInfo(void)
{
INT32 height = 192;
@ -547,6 +572,11 @@ void ST_drawDebugInfo(void)
ST_drawRenderDebug(&height);
}
if (cht_debug & DBG_DEMO)
{
ST_drawDemoDebug(&height);
}
if (cht_debug & DBG_MEMORY)
V_DrawRightAlignedString(320, height, V_MONOSPACE, va("Heap used: %7sKB", sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)));
}