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
CL_GetDemoMessage (void)
read_demopacket (void)
{
int i, r;
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);
net_message->message->cursize =
LittleLong (net_message->message->cursize);
@ -188,10 +173,30 @@ CL_GetDemoMessage (void)
CL_StopPlayback ();
return 0;
}
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
CL_GetPacket (void)
{

View File

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