Skip to content

Commit

Permalink
Change demo progress range to [0, 1].
Browse files Browse the repository at this point in the history
  • Loading branch information
skullernet committed Nov 1, 2022
1 parent daea9e7 commit 69f44d7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions inc/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/client/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/client/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -327,15 +327,15 @@ static void SCR_DrawDemo(void)
return;
}

if (!MVD_GetDemoPercent(&percent, &paused, &framenum)) {
if (!MVD_GetDemoStatus(&progress, &paused, &framenum)) {
return;
}

if (sv_paused->integer && cl_paused->integer && scr_showpause->integer == 2) {
paused = true;
}

draw_percent_bar(percent, paused, framenum);
draw_progress_bar(progress, paused, framenum);
#endif
}

Expand Down
12 changes: 6 additions & 6 deletions src/server/mvd/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 69f44d7

Please sign in to comment.