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 committed by NepDisk
parent 747c94e774
commit 7449c15eba
5 changed files with 36 additions and 1 deletions

View file

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

View file

@ -2013,7 +2013,7 @@ void G_RecordDemo(const char *name)
demobuf.p = NULL;
demo.recording = true;
//demo.buffer = &demobuf;
demo.buffer = &demobuf;
/* FIXME: This whole file is in a wretched state. Take a
look at G_WriteAllGhostTics and G_WriteDemoTiccmd, they
@ -2925,6 +2925,7 @@ void G_DoPlayDemo(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 SRB2Kart replay file.\n"), pdemoname);

View file

@ -58,6 +58,7 @@ struct demovars_s {
boolean freecam;
const savebuffer_t *buffer; // debug, valid only if recording or playback
};
extern struct demovars_s demo;

View file

@ -759,6 +759,8 @@ struct debugFlagNames_s const debug_flag_names[] =
{"Lua", DBG_LUA},
{"RNG", DBG_RNG},
{"Randomizer", DBG_RNG}, // alt name
{"Demo", DBG_DEMO},
{"Replay", DBG_DEMO}, // alt name
{NULL, 0}
};

View file

@ -438,6 +438,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"));
}
static void ST_drawDebugInfo(void)
{
INT32 height = 192;
@ -508,6 +533,11 @@ static 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)));
}