revert the changes to cl_demo.c as they are a serious (10%) speed hit in qw.

While lost in the noise for nq for the standard demos, it seems like a good
idea to revert it too.
This commit is contained in:
Bill Currie 2001-07-31 07:29:44 +00:00
parent aea1eda7ee
commit 368468dce0
3 changed files with 111 additions and 55 deletions

View file

@ -39,16 +39,15 @@
#include "QF/qendian.h" #include "QF/qendian.h"
#include "QF/va.h" #include "QF/va.h"
#include "host.h"
#include "QF/msg.h" #include "QF/msg.h"
#include "client.h"
#include "compat.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/console.h" #include "QF/console.h"
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/keys.h" #include "QF/keys.h"
#include "client.h"
#include "compat.h"
#include "host.h"
void CL_FinishTimeDemo (void); void CL_FinishTimeDemo (void);
/* /*
@ -91,11 +90,16 @@ CL_StopPlayback (void)
void void
CL_WriteDemoMessage (void) CL_WriteDemoMessage (void)
{ {
int len;
int i; int i;
float f;
WriteLong (cls.demofile, net_message->message->cursize); len = LittleLong (net_message->message->cursize);
for (i = 0; i < 3; i++) Qwrite (cls.demofile, &len, 4);
WriteFloat (cls.demofile, cl.viewangles[i]); for (i = 0; i < 3; i++) {
f = LittleFloat (cl.viewangles[i]);
Qwrite (cls.demofile, &f, 4);
}
Qwrite (cls.demofile, net_message->message->data, Qwrite (cls.demofile, net_message->message->data,
net_message->message->cursize); net_message->message->cursize);
Qflush (cls.demofile); Qflush (cls.demofile);
@ -111,6 +115,7 @@ int
CL_GetMessage (void) CL_GetMessage (void)
{ {
int r, i; int r, i;
float f;
if (cls.demoplayback) { if (cls.demoplayback) {
// decide if it is time to grab the next message // decide if it is time to grab the next message
@ -129,11 +134,15 @@ CL_GetMessage (void)
} }
} }
// get the next message // get the next message
Qread (cls.demofile, &net_message->message->cursize, 4);
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]); VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
net_message->message->cursize = ReadLong (cls.demofile); for (i = 0; i < 3; i++) {
for (i = 0; i < 3; i++) r = Qread (cls.demofile, &f, 4);
cl.mviewangles[0][i] = ReadFloat (cls.demofile); cl.mviewangles[0][i] = LittleFloat (f);
}
net_message->message->cursize =
LittleLong (net_message->message->cursize);
if (net_message->message->cursize > MAX_MSGLEN) if (net_message->message->cursize > MAX_MSGLEN)
Sys_Error ("Demo message > MAX_MSGLEN"); Sys_Error ("Demo message > MAX_MSGLEN");
r = r =

View file

@ -302,6 +302,7 @@ typedef struct
typedef struct usercmd_s typedef struct usercmd_s
{ {
byte msec; byte msec;
byte padding[3]; // make sure non-aligning compilers get it right
vec3_t angles; vec3_t angles;
short forwardmove, sidemove, upmove; short forwardmove, sidemove, upmove;
byte buttons; byte buttons;

View file

@ -99,26 +99,33 @@ void
CL_WriteDemoCmd (usercmd_t *pcmd) CL_WriteDemoCmd (usercmd_t *pcmd)
{ {
int i; int i;
float fl;
byte c;
usercmd_t cmd;
// Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); // Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime);
WriteFloat (cls.demofile, realtime); fl = LittleFloat ((float) realtime);
WriteByte (cls.demofile, dem_cmd); Qwrite (cls.demofile, &fl, sizeof (fl));
WriteByte (cls.demofile, pcmd->msec); c = dem_cmd;
WriteByte (cls.demofile, 0); // padding Qwrite (cls.demofile, &c, sizeof (c));
WriteByte (cls.demofile, 0); // padding
WriteByte (cls.demofile, 0); // padding // correct for byte order, bytes don't matter
for (i = 0; i < 3; i++) cmd = *pcmd;
WriteFloat (cls.demofile, pcmd->angles[i]);
WriteShort (cls.demofile, pcmd->forwardmove);
WriteShort (cls.demofile, pcmd->sidemove);
WriteShort (cls.demofile, pcmd->upmove);
WriteByte (cls.demofile, pcmd->buttons);
WriteByte (cls.demofile, pcmd->impulse);
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
WriteFloat (cls.demofile, cl.viewangles[i]); cmd.angles[i] = LittleFloat (cmd.angles[i]);
cmd.forwardmove = LittleShort (cmd.forwardmove);
cmd.sidemove = LittleShort (cmd.sidemove);
cmd.upmove = LittleShort (cmd.upmove);
Qwrite (cls.demofile, &cmd, sizeof (cmd));
for (i = 0; i < 3; i++) {
fl = LittleFloat (cl.viewangles[i]);
Qwrite (cls.demofile, &fl, 4);
}
Qflush (cls.demofile); Qflush (cls.demofile);
} }
@ -132,14 +139,23 @@ CL_WriteDemoCmd (usercmd_t *pcmd)
void void
CL_WriteDemoMessage (sizebuf_t *msg) CL_WriteDemoMessage (sizebuf_t *msg)
{ {
int len;
float fl;
byte c;
// Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); // Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime);
if (!cls.demorecording) if (!cls.demorecording)
return; return;
WriteFloat (cls.demofile, realtime); fl = LittleFloat ((float) realtime);
WriteByte (cls.demofile, dem_read); Qwrite (cls.demofile, &fl, sizeof (fl));
WriteLong (cls.demofile, msg->cursize);
c = dem_read;
Qwrite (cls.demofile, &c, sizeof (c));
len = LittleLong (msg->cursize);
Qwrite (cls.demofile, &len, 4);
Qwrite (cls.demofile, msg->data, msg->cursize); Qwrite (cls.demofile, msg->data, msg->cursize);
Qflush (cls.demofile); Qflush (cls.demofile);
@ -149,7 +165,8 @@ CL_WriteDemoMessage (sizebuf_t *msg)
qboolean qboolean
CL_GetDemoMessage (void) CL_GetDemoMessage (void)
{ {
int r, i; int r, i, j;
float f;
float demotime; float demotime;
byte c; byte c;
usercmd_t *pcmd; usercmd_t *pcmd;
@ -160,7 +177,8 @@ CL_GetDemoMessage (void)
demotime = cached_demotime; demotime = cached_demotime;
demotime_cached = 0; demotime_cached = 0;
} else { } else {
demotime = ReadFloat (cls.demofile); Qread (cls.demofile, &demotime, sizeof (demotime));
demotime = LittleFloat (demotime);
} }
// decide if it is time to grab the next message // decide if it is time to grab the next message
@ -202,34 +220,37 @@ CL_GetDemoMessage (void)
Host_Error ("CL_GetDemoMessage: cls.state != ca_active"); Host_Error ("CL_GetDemoMessage: cls.state != ca_active");
// get the msg type // get the msg type
c = ReadByte (cls.demofile); Qread (cls.demofile, &c, sizeof (c));
switch (c) { switch (c) {
case dem_cmd: case dem_cmd:
// user sent input // user sent input
i = cls.netchan.outgoing_sequence & UPDATE_MASK; i = cls.netchan.outgoing_sequence & UPDATE_MASK;
pcmd = &cl.frames[i].cmd; pcmd = &cl.frames[i].cmd;
pcmd->msec = ReadByte (cls.demofile); r = Qread (cls.demofile, pcmd, sizeof (*pcmd));
ReadByte (cls.demofile); // skip padding if (r != sizeof (*pcmd)) {
ReadByte (cls.demofile); // skip padding CL_StopPlayback ();
ReadByte (cls.demofile); // skip padding return 0;
for (i = 0; i < 3; i++) }
pcmd->angles[i] = ReadFloat (cls.demofile); // byte order stuff
pcmd->forwardmove = ReadShort (cls.demofile); for (j = 0; j < 3; j++)
pcmd->sidemove = ReadShort (cls.demofile); pcmd->angles[j] = LittleFloat (pcmd->angles[j]);
pcmd->upmove = ReadShort (cls.demofile); pcmd->forwardmove = LittleShort (pcmd->forwardmove);
pcmd->buttons = ReadByte (cls.demofile); pcmd->sidemove = LittleShort (pcmd->sidemove);
pcmd->impulse = ReadByte (cls.demofile); pcmd->upmove = LittleShort (pcmd->upmove);
cl.frames[i].senttime = demotime; cl.frames[i].senttime = 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++) {
cl.viewangles[i] = ReadFloat (cls.demofile); Qread (cls.demofile, &f, 4);
cl.viewangles[i] = LittleFloat (f);
}
break; break;
case dem_read: case dem_read:
// get the next message // get the next message
net_message->message->cursize = ReadLong (cls.demofile); Qread (cls.demofile, &net_message->message->cursize, 4);
net_message->message->cursize = LittleLong (net_message->message->cursize);
// Con_Printf("read: %ld bytes\n", net_message->message->cursize); // Con_Printf("read: %ld bytes\n", net_message->message->cursize);
if (net_message->message->cursize > MAX_MSGLEN) if (net_message->message->cursize > MAX_MSGLEN)
// Sys_Error ("Demo message > MAX_MSGLEN"); // Sys_Error ("Demo message > MAX_MSGLEN");
@ -242,8 +263,10 @@ CL_GetDemoMessage (void)
break; break;
case dem_set: case dem_set:
cls.netchan.outgoing_sequence = ReadLong (cls.demofile); Qread (cls.demofile, &i, 4);
cls.netchan.incoming_sequence = ReadLong (cls.demofile); cls.netchan.outgoing_sequence = LittleLong (i);
Qread (cls.demofile, &i, 4);
cls.netchan.incoming_sequence = LittleLong (i);
break; break;
default: default:
@ -311,16 +334,29 @@ CL_Stop_f (void)
void void
CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq) CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq)
{ {
int len;
int i;
float fl;
byte c;
// Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); // Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime);
if (!cls.demorecording) if (!cls.demorecording)
return; return;
WriteLong (cls.demofile, realtime); fl = LittleFloat ((float) realtime);
WriteByte (cls.demofile, dem_read); Qwrite (cls.demofile, &fl, sizeof (fl));
WriteLong (cls.demofile, msg->cursize + 8);
WriteLong (cls.demofile, seq); c = dem_read;
WriteLong (cls.demofile, seq); Qwrite (cls.demofile, &c, sizeof (c));
len = LittleLong (msg->cursize + 8);
Qwrite (cls.demofile, &len, 4);
i = LittleLong (seq);
Qwrite (cls.demofile, &i, 4);
Qwrite (cls.demofile, &i, 4);
Qwrite (cls.demofile, msg->data, msg->cursize); Qwrite (cls.demofile, msg->data, msg->cursize);
Qflush (cls.demofile); Qflush (cls.demofile);
@ -330,15 +366,25 @@ CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq)
void void
CL_WriteSetDemoMessage (void) CL_WriteSetDemoMessage (void)
{ {
int len;
float fl;
byte c;
//Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); //Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime);
if (!cls.demorecording) if (!cls.demorecording)
return; return;
WriteFloat (cls.demofile, realtime); fl = LittleFloat ((float) realtime);
WriteByte (cls.demofile, dem_set); Qwrite (cls.demofile, &fl, sizeof (fl));
WriteLong (cls.demofile, cls.netchan.outgoing_sequence);
WriteLong (cls.demofile, cls.netchan.incoming_sequence); c = dem_set;
Qwrite (cls.demofile, &c, sizeof (c));
len = LittleLong (cls.netchan.outgoing_sequence);
Qwrite (cls.demofile, &len, 4);
len = LittleLong (cls.netchan.incoming_sequence);
Qwrite (cls.demofile, &len, 4);
Qflush (cls.demofile); Qflush (cls.demofile);
} }