From 69f44d742dfaa5f36b1807c71308df334ed7ddd0 Mon Sep 17 00:00:00 2001 From: Andrey Nazarov Date: Tue, 1 Nov 2022 19:33:48 +0300 Subject: [PATCH] Change demo progress range to [0, 1]. --- inc/server/server.h | 4 ++-- src/client/client.h | 2 +- src/client/demo.c | 4 ++-- src/client/main.c | 4 ++-- src/client/screen.c | 16 ++++++++-------- src/server/mvd/client.c | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/inc/server/server.h b/inc/server/server.h index 5f79c49c6..293806d77 100644 --- a/inc/server/server.h +++ b/inc/server/server.h @@ -43,9 +43,9 @@ void SV_SetConsoleTitle(void); //void SV_ConsoleOutput(const char *msg); #if USE_MVD_CLIENT && USE_CLIENT -bool MVD_GetDemoPercent(float *percent, bool *paused, int *framenum); +bool MVD_GetDemoStatus(float *progress, bool *paused, int *framenum); #else -#define MVD_GetDemoPercent(percent, paused, framenum) false +#define MVD_GetDemoStatus(progress, paused, framenum) false #endif #if USE_SAVEGAMES diff --git a/src/client/client.h b/src/client/client.h index 444680311..63d669fb3 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -440,7 +440,7 @@ typedef struct client_static_s { int last_snapshot; // number of demo frame the last snapshot was saved int64_t file_size; int64_t file_offset; - float file_percent; + float file_progress; sizebuf_t buffer; demosnap_t **snapshots; int numsnapshots; diff --git a/src/client/demo.c b/src/client/demo.c index 9cfbc801a..eca6b6094 100644 --- a/src/client/demo.c +++ b/src/client/demo.c @@ -648,9 +648,9 @@ static void update_status(void) int64_t pos = FS_Tell(cls.demo.playback); if (pos > cls.demo.file_offset) - cls.demo.file_percent = (pos - cls.demo.file_offset) * 100.0f / cls.demo.file_size; + cls.demo.file_progress = (float)(pos - cls.demo.file_offset) / cls.demo.file_size; else - cls.demo.file_percent = 0.0f; + cls.demo.file_progress = 0.0f; } } diff --git a/src/client/main.c b/src/client/main.c index 1794951fd..8a503aa03 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -2216,7 +2216,7 @@ static size_t CL_DemoPos_m(char *buffer, size_t size) if (cls.demo.playback) framenum = cls.demo.frames_read; - else if (!MVD_GetDemoPercent(NULL, NULL, &framenum)) + else if (!MVD_GetDemoStatus(NULL, NULL, &framenum)) framenum = 0; sec = framenum / 10; framenum %= 10; @@ -2816,7 +2816,7 @@ bool CL_CheatsOK(void) return true; // can cheat when playing MVD - if (MVD_GetDemoPercent(NULL, NULL, NULL)) + if (MVD_GetDemoStatus(NULL, NULL, NULL)) return true; return false; diff --git a/src/client/screen.c b/src/client/screen.c index d65290bca..e910f0009 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -260,13 +260,13 @@ BAR GRAPHS =============================================================================== */ -static void draw_percent_bar(float percent, bool paused, int framenum) +static void draw_progress_bar(float progress, bool paused, int framenum) { char buffer[16]; int x, w, h; size_t len; - w = Q_rint(scr.hud_width * percent / 100); + w = Q_rint(scr.hud_width * progress); h = Q_rint(CHAR_HEIGHT / scr.hud_scale); scr.hud_height -= h; @@ -279,7 +279,7 @@ static void draw_percent_bar(float percent, bool paused, int framenum) w = Q_rint(scr.hud_width * scr.hud_scale); h = Q_rint(scr.hud_height * scr.hud_scale); - len = Q_scnprintf(buffer, sizeof(buffer), "%.f%%", percent); + len = Q_scnprintf(buffer, sizeof(buffer), "%.f%%", progress * 100); x = (w - len * CHAR_WIDTH) / 2; R_DrawString(x, h, 0, MAX_STRING_CHARS, buffer, scr.font_pic); @@ -301,7 +301,7 @@ static void draw_percent_bar(float percent, bool paused, int framenum) static void SCR_DrawDemo(void) { #if USE_MVD_CLIENT - float percent; + float progress; bool paused; int framenum; #endif @@ -312,8 +312,8 @@ static void SCR_DrawDemo(void) if (cls.demo.playback) { if (cls.demo.file_size) { - draw_percent_bar( - cls.demo.file_percent, + draw_progress_bar( + cls.demo.file_progress, sv_paused->integer && cl_paused->integer && scr_showpause->integer == 2, @@ -327,7 +327,7 @@ static void SCR_DrawDemo(void) return; } - if (!MVD_GetDemoPercent(&percent, &paused, &framenum)) { + if (!MVD_GetDemoStatus(&progress, &paused, &framenum)) { return; } @@ -335,7 +335,7 @@ static void SCR_DrawDemo(void) paused = true; } - draw_percent_bar(percent, paused, framenum); + draw_progress_bar(progress, paused, framenum); #endif } diff --git a/src/server/mvd/client.c b/src/server/mvd/client.c index 28867f73d..dc7455808 100644 --- a/src/server/mvd/client.c +++ b/src/server/mvd/client.c @@ -77,7 +77,7 @@ typedef struct gtv_s { int demoloop, demoskip; string_entry_t *demohead, *demoentry; int64_t demosize, demoofs; - float demopercent; + float demoprogress; bool demowait; } gtv_t; @@ -426,7 +426,7 @@ int MVD_Frame(void) } #if USE_CLIENT -bool MVD_GetDemoPercent(float *percent, bool *paused, int *framenum) +bool MVD_GetDemoStatus(float *progress, bool *paused, int *framenum) { mvd_t *mvd; gtv_t *gtv; @@ -443,8 +443,8 @@ bool MVD_GetDemoPercent(float *percent, bool *paused, int *framenum) if (!gtv->demosize) return false; - if (percent) - *percent = gtv->demopercent; + if (progress) + *progress = gtv->demoprogress; if (paused) *paused = mvd->state == MVD_WAITING; if (framenum) @@ -648,9 +648,9 @@ static void demo_update(gtv_t *gtv) int64_t pos = FS_Tell(gtv->demoplayback); if (pos > gtv->demoofs) - gtv->demopercent = (pos - gtv->demoofs) * 100.0f / gtv->demosize; + gtv->demoprogress = (float)(pos - gtv->demoofs) / gtv->demosize; else - gtv->demopercent = 0.0f; + gtv->demoprogress = 0.0f; } }