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 to play the next demo in the demo loop
45 void CL_NextDemo (void)
49 if (cls.demonum == -1)
50 return; // don't play demos
52 if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
55 if (!cls.demos[cls.demonum][0])
57 Con_Printf ("No demos listed with startdemos\n");
63 sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
64 Cbuf_InsertText (str);
72 Called when a demo file runs out, or the user starts a game
75 // LordHavoc: now called only by CL_Disconnect
76 void CL_StopPlayback (void)
78 if (!cls.demoplayback)
81 Qclose (cls.demofile);
82 cls.demoplayback = false;
93 Dumps the current net message, prefixed by the length and view angles
96 void CL_WriteDemoMessage (void)
102 if (cls.demopaused) // LordHavoc: pausedemo
105 len = LittleLong (net_message.cursize);
106 Qwrite (cls.demofile, &len, 4);
107 for (i=0 ; i<3 ; i++)
109 f = LittleFloat (cl.viewangles[i]);
110 Qwrite (cls.demofile, &f, 4);
112 Qwrite (cls.demofile, net_message.data, net_message.cursize);
113 Qflush (cls.demofile);
120 Handles recording and playback of demos, on top of NET_ code
123 int CL_GetMessage (void)
128 if (cls.demoplayback)
130 if (cls.demopaused) // LordHavoc: pausedemo
133 // decide if it is time to grab the next message
134 if (cls.signon == SIGNONS) // always grab until fully connected
138 if (host_framecount == cls.td_lastframe)
139 return 0; // already read this frame's message
140 cls.td_lastframe = host_framecount;
141 // if this is the second frame, grab the real td_starttime
142 // so the bogus time on the first frame doesn't count
143 if (host_framecount == cls.td_startframe + 1)
144 cls.td_starttime = realtime;
146 else if (cl.time <= cl.mtime[0])
148 return 0; // don't need another message yet
152 // get the next message
153 Qread (cls.demofile, &net_message.cursize, 4);
154 VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
155 for (i=0 ; i<3 ; i++)
157 r = Qread (cls.demofile, &f, 4);
158 cl.mviewangles[0][i] = LittleFloat (f);
161 net_message.cursize = LittleLong (net_message.cursize);
162 if (net_message.cursize > MAX_MSGLEN)
163 Host_Error ("Demo message > MAX_MSGLEN");
164 r = Qread (cls.demofile, net_message.data, net_message.cursize);
165 if (r != net_message.cursize)
176 r = NET_GetMessage (cls.netcon);
178 if (r != 1 && r != 2)
181 // discard nop keepalive message
182 if (net_message.cursize == 1 && net_message.data[0] == svc_nop)
183 Con_Printf ("<-- server to client keepalive\n");
188 if (cls.demorecording)
189 CL_WriteDemoMessage ();
199 stop recording a demo
202 void CL_Stop_f (void)
204 if (cmd_source != src_command)
207 if (!cls.demorecording)
209 Con_Printf ("Not recording a demo.\n");
213 // write a disconnect message to the demo file
214 SZ_Clear (&net_message);
215 MSG_WriteByte (&net_message, svc_disconnect);
216 CL_WriteDemoMessage ();
219 Qclose (cls.demofile);
221 cls.demorecording = false;
222 Con_Printf ("Completed demo\n");
229 record <demoname> <map> [cd track]
232 void CL_Record_f (void)
235 char name[MAX_OSPATH];
238 if (cmd_source != src_command)
242 if (c != 2 && c != 3 && c != 4)
244 Con_Printf ("record <demoname> [<map> [cd track]]\n");
248 if (strstr(Cmd_Argv(1), ".."))
250 Con_Printf ("Relative pathnames are not allowed.\n");
254 if (c == 2 && cls.state == ca_connected)
256 Con_Printf("Can not record - already connected to server\nClient demo recording must be started before connecting\n");
260 // write the forced cd track number, or -1
263 track = atoi(Cmd_Argv(3));
264 Con_Printf ("Forcing CD track to %i\n", cls.forcetrack);
269 sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
275 Cmd_ExecuteString ( va("map %s", Cmd_Argv(2)), src_command);
278 // open the demo file
280 COM_DefaultExtension (name, ".dem");
282 Con_Printf ("recording to %s.\n", name);
283 cls.demofile = Qopen (name, "wb");
286 Con_Printf ("ERROR: couldn't open.\n");
290 cls.forcetrack = track;
291 Qprintf (cls.demofile, "%i\n", cls.forcetrack);
293 cls.demorecording = true;
304 void CL_PlayDemo_f (void)
308 qboolean neg = false;
310 if (cmd_source != src_command)
315 Con_Printf ("play <demoname> : plays a demo\n");
320 // disconnect from server
325 // open the demo file
327 strcpy (name, Cmd_Argv(1));
328 COM_DefaultExtension (name, ".dem");
330 Con_Printf ("Playing demo from %s.\n", name);
331 COM_FOpenFile (name, &cls.demofile, false, true);
334 Con_Printf ("ERROR: couldn't open.\n");
335 cls.demonum = -1; // stop demo loop
339 SCR_BeginLoadingPlaque ();
341 cls.demoplayback = true;
342 cls.state = ca_connected;
345 while ((c = Qgetc(cls.demofile)) != '\n')
349 cls.forcetrack = cls.forcetrack * 10 + (c - '0');
352 cls.forcetrack = -cls.forcetrack;
361 void CL_FinishTimeDemo (void)
364 double time; // LordHavoc: changed timedemo accuracy to double
366 cls.timedemo = false;
368 // the first frame didn't count
369 frames = (host_framecount - cls.td_startframe) - 1;
370 time = realtime - cls.td_starttime;
373 // LordHavoc: timedemo now prints out 7 digits of fraction
374 Con_Printf ("%i frames %5.7f seconds %5.7f fps\n", frames, time, frames/time);
384 void CL_TimeDemo_f (void)
386 if (cmd_source != src_command)
391 Con_Printf ("timedemo <demoname> : gets demo speeds\n");
397 // cls.td_starttime will be grabbed at the second frame of the demo, so
398 // all the loading time doesn't get counted
400 // instantly hide console and deactivate it
406 cls.td_startframe = host_framecount;
407 cls.td_lastframe = -1; // get a new message this frame