2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 void CL_FinishTimeDemo (void);
26 ==============================================================================
30 When a demo is playing back, all NET_SendMessages are skipped, and
31 NET_GetMessages are read from the demo file.
33 Whenever cl.time gets past the last received message, another message is
34 read from the demo file.
35 ==============================================================================
42 Called when a demo file runs out, or the user starts a game
45 void CL_StopPlayback (void)
47 if (!cls.demoplayback)
50 Qclose (cls.demofile);
51 cls.demoplayback = false;
53 cls.state = ca_disconnected;
63 Dumps the current net message, prefixed by the length and view angles
66 void CL_WriteDemoMessage (void)
72 if (cls.demopaused) // LordHavoc: pausedemo
75 len = LittleLong (net_message.cursize);
76 Qwrite (cls.demofile, &len, 4);
79 f = LittleFloat (cl.viewangles[i]);
80 Qwrite (cls.demofile, &f, 4);
82 Qwrite (cls.demofile, net_message.data, net_message.cursize);
83 Qflush (cls.demofile);
90 Handles recording and playback of demos, on top of NET_ code
93 int CL_GetMessage (void)
100 if (cls.demopaused) // LordHavoc: pausedemo
103 // decide if it is time to grab the next message
104 if (cls.signon == SIGNONS) // always grab until fully connected
108 if (host_framecount == cls.td_lastframe)
109 return 0; // already read this frame's message
110 cls.td_lastframe = host_framecount;
111 // if this is the second frame, grab the real td_starttime
112 // so the bogus time on the first frame doesn't count
113 if (host_framecount == cls.td_startframe + 1)
114 cls.td_starttime = realtime;
116 else if ( /* cl.time > 0 && */ cl.time <= cl.mtime[0])
118 return 0; // don't need another message yet
122 // get the next message
123 Qread (cls.demofile, &net_message.cursize, 4);
124 VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
125 for (i=0 ; i<3 ; i++)
127 r = Qread (cls.demofile, &f, 4);
128 cl.mviewangles[0][i] = LittleFloat (f);
131 net_message.cursize = LittleLong (net_message.cursize);
132 if (net_message.cursize > MAX_MSGLEN)
133 Host_Error ("Demo message > MAX_MSGLEN");
134 r = Qread (cls.demofile, net_message.data, net_message.cursize);
135 if (r != net_message.cursize)
146 r = NET_GetMessage (cls.netcon);
148 if (r != 1 && r != 2)
151 // discard nop keepalive message
152 if (net_message.cursize == 1 && net_message.data[0] == svc_nop)
153 Con_Printf ("<-- server to client keepalive\n");
158 if (cls.demorecording)
159 CL_WriteDemoMessage ();
169 stop recording a demo
172 void CL_Stop_f (void)
174 if (cmd_source != src_command)
177 if (!cls.demorecording)
179 Con_Printf ("Not recording a demo.\n");
183 // write a disconnect message to the demo file
184 SZ_Clear (&net_message);
185 MSG_WriteByte (&net_message, svc_disconnect);
186 CL_WriteDemoMessage ();
189 Qclose (cls.demofile);
191 cls.demorecording = false;
192 Con_Printf ("Completed demo\n");
199 record <demoname> <map> [cd track]
202 void CL_Record_f (void)
205 char name[MAX_OSPATH];
208 if (cmd_source != src_command)
212 if (c != 2 && c != 3 && c != 4)
214 Con_Printf ("record <demoname> [<map> [cd track]]\n");
218 if (strstr(Cmd_Argv(1), ".."))
220 Con_Printf ("Relative pathnames are not allowed.\n");
224 if (c == 2 && cls.state == ca_connected)
226 Con_Printf("Can not record - already connected to server\nClient demo recording must be started before connecting\n");
230 // write the forced cd track number, or -1
233 track = atoi(Cmd_Argv(3));
234 Con_Printf ("Forcing CD track to %i\n", cls.forcetrack);
239 sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
245 Cmd_ExecuteString ( va("map %s", Cmd_Argv(2)), src_command);
248 // open the demo file
250 COM_DefaultExtension (name, ".dem");
252 Con_Printf ("recording to %s.\n", name);
253 cls.demofile = Qopen (name, "wb");
256 Con_Printf ("ERROR: couldn't open.\n");
260 cls.forcetrack = track;
261 Qprintf (cls.demofile, "%i\n", cls.forcetrack);
263 cls.demorecording = true;
274 void CL_PlayDemo_f (void)
278 qboolean neg = false;
280 if (cmd_source != src_command)
285 Con_Printf ("play <demoname> : plays a demo\n");
289 // SCR_BeginLoadingPlaque();
292 // disconnect from server
297 // open the demo file
299 strcpy (name, Cmd_Argv(1));
300 COM_DefaultExtension (name, ".dem");
302 Con_Printf ("Playing demo from %s.\n", name);
303 COM_FOpenFile (name, &cls.demofile, false, true);
306 Con_Printf ("ERROR: couldn't open.\n");
307 cls.demonum = -1; // stop demo loop
311 cls.demoplayback = true;
312 cls.state = ca_connected;
315 while ((c = Qgetc(cls.demofile)) != '\n')
319 cls.forcetrack = cls.forcetrack * 10 + (c - '0');
322 cls.forcetrack = -cls.forcetrack;
323 // ZOID, fscanf is evil
324 // fscanf (cls.demofile, "%i\n", &cls.forcetrack);
333 void CL_FinishTimeDemo (void)
336 double time; // LordHavoc: changed timedemo accuracy to double
338 cls.timedemo = false;
340 // the first frame didn't count
341 frames = (host_framecount - cls.td_startframe) - 1;
342 time = realtime - cls.td_starttime;
345 // LordHavoc: timedemo now prints out 7 digits of fraction
346 Con_Printf ("%i frames %5.7f seconds %5.7f fps\n", frames, time, frames/time);
356 void CL_TimeDemo_f (void)
358 if (cmd_source != src_command)
363 Con_Printf ("timedemo <demoname> : gets demo speeds\n");
369 // cls.td_starttime will be grabbed at the second frame of the demo, so
370 // all the loading time doesn't get counted
373 cls.td_startframe = host_framecount;
374 cls.td_lastframe = -1; // get a new message this frame