Factor out the next packet check code.

This commit is contained in:
Bill Currie 2012-06-07 08:14:47 +09:00
parent e04777571d
commit 01466e4e43
2 changed files with 67 additions and 48 deletions

View file

@ -150,6 +150,27 @@ CL_StopRecording (void)
Sys_Printf ("Completed demo\n"); Sys_Printf ("Completed demo\n");
} }
// decide if it is time to grab the next message
static int
check_next_demopacket (void)
{
if (cls.state == ca_active) { // always grab until fully connected
if (cls.timedemo) {
if (host_framecount == cls.td_lastframe)
return 0; // already read this frame's message
cls.td_lastframe = host_framecount;
// if this is the second frame, grab the real td_starttime
// so the bogus time on the first frame doesn't count
if (host_framecount == cls.td_startframe + 1)
cls.td_starttime = realtime;
} else if (cl.time <= cl.mtime[0]) {
return 0; // don't need another message yet
}
}
return 1;
}
// get the next message
static int static int
read_demopacket (void) read_demopacket (void)
{ {
@ -179,21 +200,8 @@ read_demopacket (void)
static int static int
CL_GetDemoMessage (void) CL_GetDemoMessage (void)
{ {
// decide if it is time to grab the next message if (!check_next_demopacket ())
if (cls.state == ca_active) { // always grab until fully connected return 0;
if (cls.timedemo) {
if (host_framecount == cls.td_lastframe)
return 0; // already read this frame's message
cls.td_lastframe = host_framecount;
// if this is the second frame, grab the real td_starttime
// so the bogus time on the first frame doesn't count
if (host_framecount == cls.td_startframe + 1)
cls.td_starttime = realtime;
} else if (cl.time <= cl.mtime[0]) {
return 0; // don't need another message yet
}
}
// get the next message
return read_demopacket (); return read_demopacket ();
} }

View file

@ -218,43 +218,15 @@ push_demotime (float demotime, byte newtime)
cached_newtime = newtime; cached_newtime = newtime;
} }
// decide if it is time to grab the next message
static int static int
read_demopacket (void) check_next_demopacket (void)
{ {
int r; byte newtime;
float demotime;
Qread (cls.demofile, &net_message->message->cursize, 4);
net_message->message->cursize =
LittleLong (net_message->message->cursize);
if (net_message->message->cursize > MAX_DEMMSG)
Host_Error ("Demo message > MAX_DEMMSG: %d/%d",
net_message->message->cursize, MAX_DEMMSG);
r = Qread (cls.demofile, net_message->message->data,
net_message->message->cursize);
if (r != net_message->message->cursize) {
CL_StopPlayback ();
return 0;
}
return 1;
}
static int
CL_GetDemoMessage (void)
{
byte c, newtime;
float demotime, f;
int r, i, j, tracknum;
usercmd_t *pcmd;
if (!cls.demoplayback2)
nextdemotime = realtime;
if (realtime + 1.0 < nextdemotime)
realtime = nextdemotime - 1.0;
nextdemomessage:
get_demotime (&demotime, &newtime); get_demotime (&demotime, &newtime);
// decide if it is time to grab the next message
if (cls.timedemo) { if (cls.timedemo) {
if (cls.td_lastframe < 0) if (cls.td_lastframe < 0)
cls.td_lastframe = demotime; cls.td_lastframe = demotime;
@ -294,6 +266,45 @@ nextdemomessage:
nextdemotime = demotime; nextdemotime = demotime;
cls.prevtime += newtime; cls.prevtime += newtime;
return 1;
}
static int
read_demopacket (void)
{
int r;
Qread (cls.demofile, &net_message->message->cursize, 4);
net_message->message->cursize =
LittleLong (net_message->message->cursize);
if (net_message->message->cursize > MAX_DEMMSG)
Host_Error ("Demo message > MAX_DEMMSG: %d/%d",
net_message->message->cursize, MAX_DEMMSG);
r = Qread (cls.demofile, net_message->message->data,
net_message->message->cursize);
if (r != net_message->message->cursize) {
CL_StopPlayback ();
return 0;
}
return 1;
}
static int
CL_GetDemoMessage (void)
{
byte c;
float f;
int r, i, j, tracknum;
usercmd_t *pcmd;
if (!cls.demoplayback2)
nextdemotime = realtime;
if (realtime + 1.0 < nextdemotime)
realtime = nextdemotime - 1.0;
nextdemomessage:
if (!check_next_demopacket ())
return 0;
if (cls.state < ca_demostart) if (cls.state < ca_demostart)
Host_Error ("CL_GetDemoMessage: cls.state != ca_active"); Host_Error ("CL_GetDemoMessage: cls.state != ca_active");
@ -318,7 +329,7 @@ nextdemomessage:
pcmd->forwardmove = LittleShort (pcmd->forwardmove); pcmd->forwardmove = LittleShort (pcmd->forwardmove);
pcmd->sidemove = LittleShort (pcmd->sidemove); pcmd->sidemove = LittleShort (pcmd->sidemove);
pcmd->upmove = LittleShort (pcmd->upmove); pcmd->upmove = LittleShort (pcmd->upmove);
cl.frames[i].senttime = demotime; cl.frames[i].senttime = nextdemotime; //FIXME was demotime
cl.frames[i].receivedtime = -1; // we haven't gotten a reply yet cl.frames[i].receivedtime = -1; // we haven't gotten a reply yet
cls.netchan.outgoing_sequence++; cls.netchan.outgoing_sequence++;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {