Factor out the demo packet reading.

This commit is contained in:
Bill Currie 2012-06-06 22:34:17 +09:00
parent cc1bf68d1f
commit e04777571d
2 changed files with 43 additions and 31 deletions

View file

@ -151,26 +151,11 @@ CL_StopRecording (void)
} }
static int static int
CL_GetDemoMessage (void) read_demopacket (void)
{ {
int i, r; int i, r;
float f; float f;
// decide if it is time to grab the next message
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
}
}
// get the next message
Qread (cls.demofile, &net_message->message->cursize, 4); Qread (cls.demofile, &net_message->message->cursize, 4);
net_message->message->cursize = net_message->message->cursize =
LittleLong (net_message->message->cursize); LittleLong (net_message->message->cursize);
@ -188,10 +173,30 @@ CL_GetDemoMessage (void)
CL_StopPlayback (); CL_StopPlayback ();
return 0; return 0;
} }
return 1; return 1;
} }
static int
CL_GetDemoMessage (void)
{
// decide if it is time to grab the next message
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
}
}
// get the next message
return read_demopacket ();
}
static int static int
CL_GetPacket (void) CL_GetPacket (void)
{ {

View file

@ -218,6 +218,26 @@ push_demotime (float demotime, byte newtime)
cached_newtime = newtime; cached_newtime = newtime;
} }
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 static int
CL_GetDemoMessage (void) CL_GetDemoMessage (void)
{ {
@ -310,20 +330,7 @@ nextdemomessage:
case dem_read: case dem_read:
readit: readit:
// get the next message // get the next message
Qread (cls.demofile, &net_message->message->cursize, 4); if (read_demopacket () && cls.demoplayback2) {
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;
}
if (cls.demoplayback2) {
tracknum = Cam_TrackNum (); tracknum = Cam_TrackNum ();
if (cls.lasttype == dem_multiple) { if (cls.lasttype == dem_multiple) {