cl_demo.c: Several tidy-ups and message corrections

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@493 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2011-10-09 08:51:29 +00:00
parent df47a63810
commit 981eab5eba

View file

@ -1,6 +1,5 @@
/* /*
Copyright (C) 1996-2001 Id Software, Inc. Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
@ -21,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h" #include "quakedef.h"
void CL_FinishTimeDemo (void); static void CL_FinishTimeDemo (void);
/* /*
============================================================================== ==============================================================================
@ -64,7 +63,7 @@ CL_WriteDemoMessage
Dumps the current net message, prefixed by the length and view angles Dumps the current net message, prefixed by the length and view angles
==================== ====================
*/ */
void CL_WriteDemoMessage (void) static void CL_WriteDemoMessage (void)
{ {
int len; int len;
int i; int i;
@ -72,7 +71,7 @@ void CL_WriteDemoMessage (void)
len = LittleLong (net_message.cursize); len = LittleLong (net_message.cursize);
fwrite (&len, 4, 1, cls.demofile); fwrite (&len, 4, 1, cls.demofile);
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); fwrite (&f, 4, 1, cls.demofile);
@ -81,43 +80,34 @@ void CL_WriteDemoMessage (void)
fflush (cls.demofile); fflush (cls.demofile);
} }
/* static int CL_GetDemoMessage (void)
====================
CL_GetMessage
Handles recording and playback of demos, on top of NET_ code
====================
*/
int CL_GetMessage (void)
{ {
int r, i; int r, i;
float f; float f;
if (cls.demoplayback)
{
// decide if it is time to grab the next message // decide if it is time to grab the next message
if (cls.signon == SIGNONS) // allways grab until fully connected if (cls.signon == SIGNONS) // always grab until fully connected
{ {
if (cls.timedemo) if (cls.timedemo)
{ {
if (host_framecount == cls.td_lastframe) if (host_framecount == cls.td_lastframe)
return 0; // allready read this frame's message return 0; // already read this frame's message
cls.td_lastframe = host_framecount; cls.td_lastframe = host_framecount;
// if this is the second frame, grab the real td_starttime // if this is the second frame, grab the real td_starttime
// so the bogus time on the first frame doesn't count // so the bogus time on the first frame doesn't count
if (host_framecount == cls.td_startframe + 1) if (host_framecount == cls.td_startframe + 1)
cls.td_starttime = realtime; cls.td_starttime = realtime;
} }
else if ( /* cl.time > 0 && */ cl.time <= cl.mtime[0]) else if (/* cl.time > 0 && */ cl.time <= cl.mtime[0])
{ {
return 0; // don't need another message yet return 0; // don't need another message yet
} }
} }
// get the next message // get the next message
fread (&net_message.cursize, 4, 1, cls.demofile); fread (&net_message.cursize, 4, 1, cls.demofile);
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 = fread (&f, 4, 1, cls.demofile);
cl.mviewangles[0][i] = LittleFloat (f); cl.mviewangles[0][i] = LittleFloat (f);
@ -134,7 +124,21 @@ int CL_GetMessage (void)
} }
return 1; return 1;
} }
/*
====================
CL_GetMessage
Handles recording and playback of demos, on top of NET_ code
====================
*/
int CL_GetMessage (void)
{
int r;
if (cls.demoplayback)
return CL_GetDemoMessage ();
while (1) while (1)
{ {
@ -203,6 +207,9 @@ void CL_Record_f (void)
if (cmd_source != src_command) if (cmd_source != src_command)
return; return;
if (cls.demorecording)
CL_Stop_f();
c = Cmd_Argc(); c = Cmd_Argc();
if (c != 2 && c != 3 && c != 4) if (c != 2 && c != 3 && c != 4)
{ {
@ -229,9 +236,11 @@ void CL_Record_f (void)
Con_Printf ("Forcing CD track to %i\n", cls.forcetrack); Con_Printf ("Forcing CD track to %i\n", cls.forcetrack);
} }
else else
{
track = -1; track = -1;
}
sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1)); q_snprintf (name, sizeof(name), "%s/%s", com_gamedir, Cmd_Argv(1));
// //
// start the map up // start the map up
@ -248,7 +257,7 @@ void CL_Record_f (void)
cls.demofile = fopen (name, "wb"); cls.demofile = fopen (name, "wb");
if (!cls.demofile) if (!cls.demofile)
{ {
Con_Printf ("ERROR: couldn't open.\n"); Con_Printf ("ERROR: couldn't create %s\n", name);
return; return;
} }
@ -268,21 +277,20 @@ play [demoname]
*/ */
void CL_PlayDemo_f (void) void CL_PlayDemo_f (void)
{ {
char name[256]; char name[MAX_OSPATH];
int c; int c;
qboolean neg = false; qboolean neg;
if (cmd_source != src_command) if (cmd_source != src_command)
return; return;
if (Cmd_Argc() != 2) if (Cmd_Argc() != 2)
{ {
Con_Printf ("play <demoname> : plays a demo\n"); Con_Printf ("playdemo <demoname> : plays a demo\n");
return; return;
} }
// withdraw console/menu // get rid of the menu and/or console
if (key_dest == key_console)
key_dest = key_game; key_dest = key_game;
// //
@ -297,28 +305,30 @@ void CL_PlayDemo_f (void)
COM_DefaultExtension (name, ".dem"); COM_DefaultExtension (name, ".dem");
Con_Printf ("Playing demo from %s.\n", name); Con_Printf ("Playing demo from %s.\n", name);
COM_FOpenFile (name, &cls.demofile, NULL); COM_FOpenFile (name, &cls.demofile, NULL);
if (!cls.demofile) if (!cls.demofile)
{ {
Con_Printf ("ERROR: couldn't open.\n"); Con_Printf ("ERROR: couldn't open %s\n", name);
cls.demonum = -1; // stop demo loop cls.demonum = -1; // stop demo loop
return; return;
} }
cls.demoplayback = true; cls.demoplayback = true;
cls.state = ca_connected; cls.state = ca_connected;
// ZOID, fscanf is evil
// fscanf (cls.demofile, "%i\n", &cls.forcetrack);
cls.forcetrack = 0; cls.forcetrack = 0;
neg = false;
while ((c = getc(cls.demofile)) != '\n') while ((c = getc(cls.demofile)) != '\n')
{
if (c == '-') if (c == '-')
neg = true; neg = true;
else else
cls.forcetrack = cls.forcetrack * 10 + (c - '0'); cls.forcetrack = cls.forcetrack * 10 + (c - '0');
}
if (neg) if (neg)
cls.forcetrack = -cls.forcetrack; cls.forcetrack = -cls.forcetrack;
// ZOID, fscanf is evil
// fscanf (cls.demofile, "%i\n", &cls.forcetrack);
} }
/* /*
@ -327,7 +337,7 @@ CL_FinishTimeDemo
==================== ====================
*/ */
void CL_FinishTimeDemo (void) static void CL_FinishTimeDemo (void)
{ {
int frames; int frames;
float time; float time;