Skip to content

Commit

Permalink
Add ‘cl_demowait’ cvar.
Browse files Browse the repository at this point in the history
Allow waiting at the last demo frame instead of dropping to console.
  • Loading branch information
skullernet committed Jan 1, 2013
1 parent 7b98b49 commit 3cc4f0a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
8 changes: 6 additions & 2 deletions doc/client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,13 @@ cl_demomsglen::
value is 1390. See ‘record’ command description for more information on
demo packet sizes.

cl_demowait::
Specifies if demo playback is automatically paused at the last frame in
demo file. Default value is 0 (finish playback).

cl_autopause::
Specifies if single player game or demo playback is automaticlly paused once
client console or menu is opened. Default value is 1 (pause game).
Specifies if single player game or demo playback is automatically paused
once client console or menu is opened. Default value is 1 (pause game).

ui_open::
Specifies if menu is automatically opened on startup, instead of full
Expand Down
1 change: 1 addition & 0 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ typedef struct client_static_s {
list_t snapshots;
qboolean paused;
qboolean seeking;
qboolean eof;
} demo;
} client_static_t;

Expand Down
51 changes: 40 additions & 11 deletions src/client/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static byte demo_buffer[MAX_PACKETLEN];

static cvar_t *cl_demosnaps;
static cvar_t *cl_demomsglen;
static cvar_t *cl_demowait;

// =========================================================================

Expand Down Expand Up @@ -660,19 +661,25 @@ static void update_status(void)
}
}

static void parse_next_message(void)
static int parse_next_message(int wait)
{
int ret;

ret = read_next_message(cls.demo.playback);
if (ret <= 0) {
if (ret < 0 || (ret == 0 && wait == 0)) {
finish_demo(ret);
return;
return -1;
}

CL_ParseServerMessage();

update_status();

if (ret == 0) {
cls.demo.eof = qtrue;
return -1;
}

CL_ParseServerMessage();
return 0;
}

/*
Expand Down Expand Up @@ -727,10 +734,13 @@ static void CL_PlayDemo_f(void)
Con_Popup();
SCR_UpdateScreen();

// parse the first message just read
CL_ParseServerMessage();

// read and parse messages util `precache' command
while (cls.state == ca_connected) {
Cbuf_Execute(&cl_cmdbuf);
parse_next_message();
parse_next_message(0);
}
}

Expand Down Expand Up @@ -934,6 +944,10 @@ static void CL_Seek_f(void)
// already there
return;

if (frames > 0 && cls.demo.eof && cl_demowait->integer)
// already at end
return;

// disable effects processing
cls.demo.seeking = qtrue;

Expand All @@ -960,6 +974,9 @@ static void CL_Seek_f(void)
goto done;
}

// clear end-of-file flag
cls.demo.eof = qfalse;

// reset configstrings
for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = cl.baseconfigstrings[i];
Expand Down Expand Up @@ -987,6 +1004,10 @@ static void CL_Seek_f(void)
// skip forward to destination frame
while (cls.demo.frames_read < dest) {
ret = read_next_message(cls.demo.playback);
if (ret == 0 && cl_demowait->integer) {
cls.demo.eof = qtrue;
break;
}
if (ret <= 0) {
finish_demo(ret);
return;
Expand Down Expand Up @@ -1203,24 +1224,31 @@ void CL_DemoFrame(int msec)
}

if (cls.state != ca_active) {
parse_next_message();
parse_next_message(0);
return;
}

if (com_timedemo->integer) {
parse_next_message();
parse_next_message(0);
cl.time = cl.servertime;
cls.demo.time_frames++;
return;
}

// wait at the end of demo
if (cls.demo.eof) {
if (!cl_demowait->integer)
finish_demo(0);
return;
}

// cl.time has already been advanced for this client frame
// read the next frame to start lerp cycle again
while (cl.servertime < cl.time) {
parse_next_message();
if (cls.state != ca_active) {
if (parse_next_message(cl_demowait->integer))
break;
if (cls.state != ca_active)
break;
}
}
}

Expand All @@ -1243,6 +1271,7 @@ void CL_InitDemos(void)
{
cl_demosnaps = Cvar_Get("cl_demosnaps", "10", 0);
cl_demomsglen = Cvar_Get("cl_demomsglen", va("%d", MAX_PACKETLEN_WRITABLE_DEFAULT), 0);
cl_demowait = Cvar_Get("cl_demowait", "0", 0);

Cmd_Register(c_demo);
List_Init(&cls.demo.snapshots);
Expand Down

0 comments on commit 3cc4f0a

Please sign in to comment.