mirror of
https://github.com/nzp-team/glquake.git
synced 2024-11-25 21:40:58 +00:00
dquakeplus' improved demo handling
This commit is contained in:
parent
868b15f68f
commit
16a3942676
1 changed files with 35 additions and 22 deletions
|
@ -47,9 +47,9 @@ void CL_StopPlayback (void)
|
||||||
if (!cls.demoplayback)
|
if (!cls.demoplayback)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fclose (cls.demofile);
|
Sys_FileClose(cls.demofile);
|
||||||
cls.demoplayback = false;
|
cls.demoplayback = false;
|
||||||
cls.demofile = NULL;
|
cls.demofile = -1;
|
||||||
cls.state = ca_disconnected;
|
cls.state = ca_disconnected;
|
||||||
|
|
||||||
if (cls.timedemo)
|
if (cls.timedemo)
|
||||||
|
@ -70,14 +70,13 @@ void CL_WriteDemoMessage (void)
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
len = LittleLong (net_message.cursize);
|
len = LittleLong (net_message.cursize);
|
||||||
fwrite (&len, 4, 1, cls.demofile);
|
Sys_FileWrite(cls.demofile, &len, 4);
|
||||||
for (i=0 ; i<3 ; i++)
|
for (i=0 ; i<3 ; i++)
|
||||||
{
|
{
|
||||||
f = LittleFloat (cl.viewangles[i]);
|
f = LittleFloat (cl.viewangles[i]);
|
||||||
fwrite (&f, 4, 1, cls.demofile);
|
Sys_FileWrite(cls.demofile, &f, 4);
|
||||||
}
|
}
|
||||||
fwrite (net_message.data, net_message.cursize, 1, cls.demofile);
|
Sys_FileWrite(cls.demofile, net_message.data, net_message.cursize);
|
||||||
fflush (cls.demofile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -114,18 +113,18 @@ int CL_GetMessage (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the next message
|
// get the next message
|
||||||
fread (&net_message.cursize, 4, 1, cls.demofile);
|
Sys_FileRead(cls.demofile, &net_message.cursize, 4);
|
||||||
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
|
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
|
||||||
for (i=0 ; i<3 ; i++)
|
for (i=0 ; i<3 ; i++)
|
||||||
{
|
{
|
||||||
r = fread (&f, 4, 1, cls.demofile);
|
r = Sys_FileRead(cls.demofile, &f, 4) / 4;
|
||||||
cl.mviewangles[0][i] = LittleFloat (f);
|
cl.mviewangles[0][i] = LittleFloat (f);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_message.cursize = LittleLong (net_message.cursize);
|
net_message.cursize = LittleLong (net_message.cursize);
|
||||||
if (net_message.cursize > MAX_MSGLEN)
|
if (net_message.cursize > MAX_MSGLEN)
|
||||||
Sys_Error ("Demo message > MAX_MSGLEN");
|
Sys_Error ("Demo message (0x%08x) > MAX_MSGLEN (%d)", net_message.cursize, MAX_MSGLEN);
|
||||||
r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
|
r = Sys_FileRead(cls.demofile, net_message.data, net_message.cursize) / net_message.cursize;
|
||||||
if (r != 1)
|
if (r != 1)
|
||||||
{
|
{
|
||||||
CL_StopPlayback ();
|
CL_StopPlayback ();
|
||||||
|
@ -180,8 +179,8 @@ void CL_Stop_f (void)
|
||||||
CL_WriteDemoMessage ();
|
CL_WriteDemoMessage ();
|
||||||
|
|
||||||
// finish up
|
// finish up
|
||||||
fclose (cls.demofile);
|
Sys_FileClose(cls.demofile);
|
||||||
cls.demofile = NULL;
|
cls.demofile = -1;
|
||||||
cls.demorecording = false;
|
cls.demorecording = false;
|
||||||
Con_Printf ("Completed demo\n");
|
Con_Printf ("Completed demo\n");
|
||||||
}
|
}
|
||||||
|
@ -198,6 +197,7 @@ void CL_Record_f (void)
|
||||||
int c;
|
int c;
|
||||||
char name[MAX_OSPATH];
|
char name[MAX_OSPATH];
|
||||||
int track;
|
int track;
|
||||||
|
char forcetrack[16];
|
||||||
|
|
||||||
if (cmd_source != src_command)
|
if (cmd_source != src_command)
|
||||||
return;
|
return;
|
||||||
|
@ -244,15 +244,16 @@ void CL_Record_f (void)
|
||||||
COM_DefaultExtension (name, ".dem");
|
COM_DefaultExtension (name, ".dem");
|
||||||
|
|
||||||
Con_Printf ("recording to %s.\n", name);
|
Con_Printf ("recording to %s.\n", name);
|
||||||
cls.demofile = fopen (name, "wb");
|
cls.demofile = Sys_FileOpenWrite(name);
|
||||||
if (!cls.demofile)
|
if (cls.demofile < 0)
|
||||||
{
|
{
|
||||||
Con_Printf ("ERROR: couldn't open.\n");
|
Con_Printf ("ERROR: couldn't open demo for writing.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cls.forcetrack = track;
|
cls.forcetrack = track;
|
||||||
fprintf (cls.demofile, "%i\n", cls.forcetrack);
|
sprintf(forcetrack, "%i\n", cls.forcetrack);
|
||||||
|
Sys_FileWrite(cls.demofile, forcetrack, strlen(forcetrack));
|
||||||
|
|
||||||
cls.demorecording = true;
|
cls.demorecording = true;
|
||||||
}
|
}
|
||||||
|
@ -265,6 +266,18 @@ CL_PlayDemo_f
|
||||||
play [demoname]
|
play [demoname]
|
||||||
====================
|
====================
|
||||||
*/
|
*/
|
||||||
|
static int CL_FileGetChar(int handle)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
if (Sys_FileRead(handle, &c, 1) != 1)
|
||||||
|
{
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
void CL_PlayDemo_f (void)
|
void CL_PlayDemo_f (void)
|
||||||
{
|
{
|
||||||
char name[256];
|
char name[256];
|
||||||
|
@ -293,9 +306,9 @@ void CL_PlayDemo_f (void)
|
||||||
|
|
||||||
Con_Printf ("Playing demo from %s.\n", name);
|
Con_Printf ("Playing demo from %s.\n", name);
|
||||||
COM_FOpenFile (name, &cls.demofile);
|
COM_FOpenFile (name, &cls.demofile);
|
||||||
if (!cls.demofile)
|
if (cls.demofile < 0)
|
||||||
{
|
{
|
||||||
Con_Printf ("ERROR: couldn't open.\n");
|
Con_Printf ("ERROR: couldn't open demo for reading.\n");
|
||||||
cls.demonum = -1; // stop demo loop
|
cls.demonum = -1; // stop demo loop
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -304,7 +317,7 @@ void CL_PlayDemo_f (void)
|
||||||
cls.state = ca_connected;
|
cls.state = ca_connected;
|
||||||
cls.forcetrack = 0;
|
cls.forcetrack = 0;
|
||||||
|
|
||||||
while ((c = getc(cls.demofile)) != '\n')
|
while ((c = CL_FileGetChar(cls.demofile)) != '\n')
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
neg = true;
|
neg = true;
|
||||||
else
|
else
|
||||||
|
@ -325,14 +338,14 @@ CL_FinishTimeDemo
|
||||||
void CL_FinishTimeDemo (void)
|
void CL_FinishTimeDemo (void)
|
||||||
{
|
{
|
||||||
int frames;
|
int frames;
|
||||||
float time;
|
double time;
|
||||||
|
|
||||||
cls.timedemo = false;
|
cls.timedemo = false;
|
||||||
|
|
||||||
// the first frame didn't count
|
// the first frame didn't count
|
||||||
frames = (host_framecount - cls.td_startframe) - 1;
|
frames = (host_framecount - cls.td_startframe) - 1;
|
||||||
time = realtime - cls.td_starttime;
|
time = realtime - cls.td_starttime;
|
||||||
if (!time)
|
if (time < 1)
|
||||||
time = 1;
|
time = 1;
|
||||||
Con_Printf ("%i frames %5.1f seconds %5.1f fps\n", frames, time, frames/time);
|
Con_Printf ("%i frames %5.1f seconds %5.1f fps\n", frames, time, frames/time);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue