Lerping fixes and preperation for mvd streaming for client side playback.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@649 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
649e60e1cb
commit
b6fd491d44
1 changed files with 59 additions and 40 deletions
|
@ -142,6 +142,29 @@ void CL_WriteDemoMessage (sizebuf_t *msg)
|
||||||
fflush (cls.demofile);
|
fflush (cls.demofile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int unreaddata;
|
||||||
|
int unreadbytes;
|
||||||
|
int readdemobytes(void *data, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (unreadbytes)
|
||||||
|
{
|
||||||
|
if (len != unreadbytes)
|
||||||
|
Sys_Error("Demo playback unread the wrong number of bytes\n");
|
||||||
|
memcpy(data, &unreaddata, len);
|
||||||
|
|
||||||
|
unreadbytes=0;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = fread(data, 1, len, cls.demofile);
|
||||||
|
|
||||||
|
memcpy(&unreaddata, data, 4);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
====================
|
====================
|
||||||
CL_GetDemoMessage
|
CL_GetDemoMessage
|
||||||
|
@ -149,6 +172,9 @@ CL_GetDemoMessage
|
||||||
FIXME...
|
FIXME...
|
||||||
====================
|
====================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
float olddemotime = 0;
|
||||||
|
extern float nextdemotime;
|
||||||
qboolean CL_GetDemoMessage (void)
|
qboolean CL_GetDemoMessage (void)
|
||||||
{
|
{
|
||||||
int r, i, j, tracknum;
|
int r, i, j, tracknum;
|
||||||
|
@ -158,9 +184,6 @@ qboolean CL_GetDemoMessage (void)
|
||||||
usercmd_t *pcmd;
|
usercmd_t *pcmd;
|
||||||
q1usercmd_t q1cmd;
|
q1usercmd_t q1cmd;
|
||||||
|
|
||||||
static float prevtime = 0;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef NQPROT
|
#ifdef NQPROT
|
||||||
if (cls.demoplayback == DPB_NETQUAKE || cls.demoplayback == DPB_QUAKE2)
|
if (cls.demoplayback == DPB_NETQUAKE || cls.demoplayback == DPB_QUAKE2)
|
||||||
{ //read the nq demo
|
{ //read the nq demo
|
||||||
|
@ -173,7 +196,7 @@ qboolean CL_GetDemoMessage (void)
|
||||||
{
|
{
|
||||||
cl.gametime = 0;
|
cl.gametime = 0;
|
||||||
cl.gametimemark = realtime;
|
cl.gametimemark = realtime;
|
||||||
prevtime = 0;
|
olddemotime = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (realtime<= cl.gametime && cl.gametime)// > dem_lasttime+realtime)
|
if (realtime<= cl.gametime && cl.gametime)// > dem_lasttime+realtime)
|
||||||
|
@ -185,7 +208,7 @@ qboolean CL_GetDemoMessage (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
float f = (cl.gametime-realtime)/(cl.gametime-prevtime);
|
float f = (cl.gametime-realtime)/(cl.gametime-olddemotime);
|
||||||
float a1;
|
float a1;
|
||||||
float a2;
|
float a2;
|
||||||
|
|
||||||
|
@ -204,20 +227,20 @@ qboolean CL_GetDemoMessage (void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fread (&net_message.cursize, 4, 1, cls.demofile);
|
readdemobytes(&net_message.cursize, 4);
|
||||||
// VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
|
// VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
|
||||||
if (cls.demoplayback == DPB_NETQUAKE)
|
if (cls.demoplayback == DPB_NETQUAKE)
|
||||||
{
|
{
|
||||||
VectorCopy (cl.viewangles[1], cl.viewangles[2]);
|
VectorCopy (cl.viewangles[1], cl.viewangles[2]);
|
||||||
for (i=0 ; i<3 ; i++)
|
for (i=0 ; i<3 ; i++)
|
||||||
{
|
{
|
||||||
r = fread (&f, 4, 1, cls.demofile);
|
readdemobytes(&f, 4);
|
||||||
cl.simangles[0][i] = cl.viewangles[1][i] = LittleFloat (f);
|
cl.simangles[0][i] = cl.viewangles[1][i] = LittleFloat (f);
|
||||||
}
|
}
|
||||||
VectorCopy (cl.viewangles[1], cl.viewangles[0]);
|
VectorCopy (cl.viewangles[1], cl.viewangles[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
prevtime = realtime;
|
olddemotime = realtime;
|
||||||
|
|
||||||
net_message.cursize = LittleLong (net_message.cursize);
|
net_message.cursize = LittleLong (net_message.cursize);
|
||||||
if (net_message.cursize > MAX_NQMSGLEN)
|
if (net_message.cursize > MAX_NQMSGLEN)
|
||||||
|
@ -232,8 +255,8 @@ qboolean CL_GetDemoMessage (void)
|
||||||
CL_StopPlayback ();
|
CL_StopPlayback ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
|
r = readdemobytes(net_message.data, net_message.cursize);
|
||||||
if (r != 1)
|
if (r != net_message.cursize)
|
||||||
{
|
{
|
||||||
CL_StopPlayback ();
|
CL_StopPlayback ();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -246,17 +269,18 @@ readnext:
|
||||||
// read the time from the packet
|
// read the time from the packet
|
||||||
if (cls.demoplayback == DPB_MVD)
|
if (cls.demoplayback == DPB_MVD)
|
||||||
{
|
{
|
||||||
if (prevtime > realtime)
|
if (olddemotime > realtime)
|
||||||
prevtime = realtime;
|
olddemotime = realtime;
|
||||||
if (realtime + 1.0 < prevtime)
|
if (realtime + 1.0 < olddemotime)
|
||||||
realtime = prevtime - 1.0;
|
realtime = olddemotime - 1.0;
|
||||||
|
|
||||||
fread(&msecsadded, sizeof(msecsadded), 1, cls.demofile);
|
readdemobytes(&msecsadded, sizeof(msecsadded));
|
||||||
demotime = prevtime + msecsadded*(1.0f/1000);
|
demotime = olddemotime + msecsadded*(1.0f/1000);
|
||||||
|
nextdemotime = demotime;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fread(&demotime, sizeof(demotime), 1, cls.demofile);
|
readdemobytes(&demotime, sizeof(demotime));
|
||||||
demotime = LittleFloat(demotime);
|
demotime = LittleFloat(demotime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,11 +294,9 @@ readnext:
|
||||||
cls.td_lastframe = demotime;
|
cls.td_lastframe = demotime;
|
||||||
// rewind back to time
|
// rewind back to time
|
||||||
if (cls.demoplayback == DPB_MVD)
|
if (cls.demoplayback == DPB_MVD)
|
||||||
fseek(cls.demofile, ftell(cls.demofile) - sizeof(msecsadded),
|
unreadbytes = sizeof(msecsadded);
|
||||||
SEEK_SET);
|
|
||||||
else
|
else
|
||||||
fseek(cls.demofile, ftell(cls.demofile) - sizeof(demotime),
|
unreadbytes = sizeof(demotime);
|
||||||
SEEK_SET);
|
|
||||||
return 0; // allready read this frame's message
|
return 0; // allready read this frame's message
|
||||||
}
|
}
|
||||||
if (!cls.td_starttime && cls.state == ca_active)
|
if (!cls.td_starttime && cls.state == ca_active)
|
||||||
|
@ -292,22 +314,18 @@ readnext:
|
||||||
realtime = demotime - 1.0;
|
realtime = demotime - 1.0;
|
||||||
// rewind back to time
|
// rewind back to time
|
||||||
if (cls.demoplayback == DPB_MVD)
|
if (cls.demoplayback == DPB_MVD)
|
||||||
fseek(cls.demofile, ftell(cls.demofile) - sizeof(msecsadded),
|
unreadbytes = sizeof(msecsadded);
|
||||||
SEEK_SET);
|
|
||||||
else
|
else
|
||||||
fseek(cls.demofile, ftell(cls.demofile) - sizeof(demotime),
|
unreadbytes = sizeof(demotime);
|
||||||
SEEK_SET);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (realtime < demotime)
|
else if (realtime < demotime)
|
||||||
{
|
{
|
||||||
// rewind back to time
|
// rewind back to time
|
||||||
if (cls.demoplayback == DPB_MVD)
|
if (cls.demoplayback == DPB_MVD)
|
||||||
fseek(cls.demofile, ftell(cls.demofile) - sizeof(msecsadded),
|
unreadbytes = sizeof(msecsadded);
|
||||||
SEEK_SET);
|
|
||||||
else
|
else
|
||||||
fseek(cls.demofile, ftell(cls.demofile) - sizeof(demotime),
|
unreadbytes = sizeof(demotime);
|
||||||
SEEK_SET);
|
|
||||||
return 0; // don't need another message yet
|
return 0; // don't need another message yet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +343,7 @@ readnext:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prevtime = demotime;
|
olddemotime = demotime;
|
||||||
|
|
||||||
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");
|
||||||
|
@ -339,8 +357,8 @@ readnext:
|
||||||
// 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[0];
|
pcmd = &cl.frames[i].cmd[0];
|
||||||
r = fread (&q1cmd, sizeof(q1cmd), 1, cls.demofile);
|
r = readdemobytes (&q1cmd, sizeof(q1cmd));
|
||||||
if (r != 1)
|
if (r != sizeof(q1cmd))
|
||||||
{
|
{
|
||||||
CL_StopPlayback ();
|
CL_StopPlayback ();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -363,7 +381,7 @@ readnext:
|
||||||
cls.netchan.outgoing_sequence++;
|
cls.netchan.outgoing_sequence++;
|
||||||
for (i=0 ; i<3 ; i++)
|
for (i=0 ; i<3 ; i++)
|
||||||
{
|
{
|
||||||
r = fread (&f, 4, 1, cls.demofile);
|
readdemobytes (&f, 4);
|
||||||
cl.viewangles[0][i] = LittleFloat (f);
|
cl.viewangles[0][i] = LittleFloat (f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -371,13 +389,13 @@ readnext:
|
||||||
case dem_read:
|
case dem_read:
|
||||||
readit:
|
readit:
|
||||||
// get the next message
|
// get the next message
|
||||||
fread (&net_message.cursize, 4, 1, cls.demofile);
|
readdemobytes (&net_message.cursize, 4);
|
||||||
net_message.cursize = LittleLong (net_message.cursize);
|
net_message.cursize = LittleLong (net_message.cursize);
|
||||||
//Con_Printf("read: %ld bytes\n", net_message.cursize);
|
//Con_Printf("read: %ld bytes\n", net_message.cursize);
|
||||||
if (net_message.cursize > MAX_OVERALLMSGLEN)
|
if (net_message.cursize > MAX_OVERALLMSGLEN)
|
||||||
Sys_Error ("Demo message > MAX_OVERALLMSGLEN");
|
Sys_Error ("Demo message > MAX_OVERALLMSGLEN");
|
||||||
r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
|
r = readdemobytes (net_message.data, net_message.cursize);
|
||||||
if (r != 1)
|
if (r != net_message.cursize)
|
||||||
{
|
{
|
||||||
CL_StopPlayback ();
|
CL_StopPlayback ();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -406,9 +424,9 @@ readit:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case dem_set :
|
case dem_set :
|
||||||
fread (&i, 4, 1, cls.demofile);
|
readdemobytes (&i, 4);
|
||||||
cls.netchan.outgoing_sequence = LittleLong(i);
|
cls.netchan.outgoing_sequence = LittleLong(i);
|
||||||
fread (&i, 4, 1, cls.demofile);
|
readdemobytes (&i, 4);
|
||||||
cls.netchan.incoming_sequence = LittleLong(i);
|
cls.netchan.incoming_sequence = LittleLong(i);
|
||||||
|
|
||||||
if (cls.demoplayback == DPB_MVD)
|
if (cls.demoplayback == DPB_MVD)
|
||||||
|
@ -416,7 +434,7 @@ readit:
|
||||||
goto readnext;
|
goto readnext;
|
||||||
|
|
||||||
case dem_multiple:
|
case dem_multiple:
|
||||||
fread (&i, sizeof(i), 1, cls.demofile);
|
readdemobytes (&i, sizeof(i));
|
||||||
cls_lastto = LittleLong(i);
|
cls_lastto = LittleLong(i);
|
||||||
cls_lasttype = dem_multiple;
|
cls_lasttype = dem_multiple;
|
||||||
goto readit;
|
goto readit;
|
||||||
|
@ -1108,6 +1126,7 @@ void CL_PlayDemo_f (void)
|
||||||
//
|
//
|
||||||
CL_Disconnect_f ();
|
CL_Disconnect_f ();
|
||||||
|
|
||||||
|
unreadbytes = 0; //just in case
|
||||||
//
|
//
|
||||||
// open the demo file
|
// open the demo file
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue