-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcl_demo.c
2370 lines (2014 loc) · 51.6 KB
/
cl_demo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cl_demo.c
#include "quakedef.h"
#ifndef RQM_SV_ONLY
#define OLDSEEK
#include "winquake.h"
#include "dzip.h"
#include "movie.h"
#include <time.h> // easyrecord stats
#ifndef _WIN32
#include <sys/wait.h>
#include <unistd.h>
#endif
// JDH: I took Joe's idea of a framepos stack, and reduced the overhead of
// doing a malloc/free for each framepos. I did this by allocating
// large blocks, then chaining them together as a linked list.
// 8000 frames is good for ~2-10 minutes of recorded demo (depending on demo's framerate)
#define FRAMEPOS_BLOCKSIZE 8000
typedef struct framepos_entry_s
{
long inpos/*, outpos*/;
} framepos_entry_t;
// added by joe
typedef struct framepos_s
{
struct framepos_s *next;
framepos_entry_t entries[FRAMEPOS_BLOCKSIZE];
} framepos_t;
framepos_t *dem_framepos = NULL;
int dem_framecount = 0;
long cl_demo_filestart, cl_demo_filesize;
double cl_demo_starttime, cl_demo_endtime; // JDH: during playback, cl.time at beginning and end
qboolean cl_demoseek; // JDH: true if jumping to new position in demo
cvar_t cl_demorewind = {"cl_demorewind", "0"};
// .dz playback
#define DZ_APP_NOERR 0
#define DZ_APP_ERROR 1
typedef enum {DZ_OP_NONE, DZ_OP_EXTRACT, DZ_OP_COMPRESS, DZ_OP_VERIFY} dz_op_t;
#ifdef _WIN32
#define DZIP_APPNAME "dzip.exe"
static HANDLE hDZipProcess = NULL;
static HANDLE hDZipThread = NULL; // just so we can CloseHandle when done
#else
#define DZIP_APPNAME "dzip-linux"
static qboolean hDZipProcess = false;
#endif
static qboolean dz_playback = false;
static dz_op_t dz_app_op = DZ_OP_NONE; // what operation dzip app is currently doing
static int dz_exitcode = DZ_APP_ERROR;
static char dz_filename[MAX_OSPATH]; // used when compressing; doesn't include path
static char cl_demo_filepath[MAX_OSPATH] = ""; // full path of demo currently being played/recorded
//static char dem_basedir[256] = "";
static void CheckDZipCompletion ();
static void StopDZPlayback ();
#define DZ_APPEXISTS() (COM_FileExists(va("%s/"DZIP_APPNAME, com_basedir)))
// joe: support for recording demos after connecting to the server
byte demo_head[3][NET_MAXMESSAGE];
int demo_head_size[2];
#ifdef HEXEN2_SUPPORT
extern qboolean intro_playing;
#endif
extern qboolean dzlib_loaded;
void CL_FinishTimeDemo (void);
// JDH: added overlay, QWD support, quickjump navigation, demo compression
extern double scr_demo_overlay_time;
extern cvar_t cl_demo_compress, cl_demo_compress_fmt;
extern qboolean dz_canzip;
qboolean is_qwd = false;
/*
// JDH: struct used to record the state of several client vars
// once signon is complete
typedef struct demo_state_s
{
int stats[MAX_CL_STATS];
int viewentity;
int viewheight; // for QWD
#ifdef HEXEN2_SUPPORT
entvars_t entvars;
long info_mask;
long info_mask2;
#endif
} demo_state_t;
demo_state_t demo_state_orig;
*/
/*
==============================================================================
DEMO CODE
When a demo is playing back, all NET_SendMessages are skipped, and
NET_GetMessages are read from the demo file.
Whenever cl.time gets past the last received message, another message is
read from the demo file.
==============================================================================
*/
void PushFrameposEntry (long inpos)
{
framepos_t *newf;
#ifdef _DEBUG
if (inpos == 0x04a112a8)
inpos *= 1;
#endif
if (!dem_framepos)
{
dem_framepos = Q_malloc (sizeof(framepos_t));
dem_framepos->next = NULL;
dem_framecount = 0;
}
else if (dem_framecount >= FRAMEPOS_BLOCKSIZE)
{
newf = Q_malloc (sizeof(framepos_t));
newf->next = dem_framepos;
dem_framepos = newf;
dem_framecount = 0;
}
dem_framepos->entries[dem_framecount].inpos = inpos;
dem_framecount++;
}
void EraseTopEntry (void)
{
framepos_t *next;
if (dem_framepos)
{
if (dem_framecount > 1)
dem_framecount--;
else
{
next = dem_framepos->next;
free (dem_framepos);
dem_framepos = next;
dem_framecount = (dem_framepos ? FRAMEPOS_BLOCKSIZE : 0);
}
}
}
long ClearFrameposStack (void)
{
framepos_t *next;
long startpos = 0;
while (dem_framepos)
{
startpos = dem_framepos->entries[0].inpos;
next = dem_framepos->next;
free (dem_framepos);
dem_framepos = next;
}
dem_framecount = 0;
return startpos;
}
const char * CL_GetDemoFilepath (void)
{
return cl_demo_filepath;
}
/*
==============
CL_StopPlayback
Called when a demo file runs out, or the user starts a game
==============
*/
void CL_StopPlayback (void)
{
if (!cls.demoplayback)
return;
#ifdef HEXEN2_SUPPORT
if (hexen2 && intro_playing)
{
M_ToggleMenu_f (SRC_COMMAND);
intro_playing = false;
}
#endif
fclose (cls.demofile);
cls.demofile = NULL;
cls.demoplayback = false;
cl_demo_filepath[0] = 0;
cls.state = ca_disconnected;
ClearFrameposStack ();
if (dz_playback)
StopDZPlayback ();
if (cls.timedemo)
CL_FinishTimeDemo ();
Movie_StopDemoCapture ();
}
/*
====================
CL_WriteDemoMessage
Dumps the current net message, prefixed by the length and view angles
====================
*/
void CL_WriteDemoMessage (FILE *demofile, const vec3_t viewangles)
{
int i, len;
float f;
len = LittleLong (net_message.cursize);
fwrite (&len, 4, 1, demofile);
for (i=0 ; i<3 ; i++)
{
f = LittleFloat (viewangles[i]);
fwrite (&f, 4, 1, demofile);
}
fwrite (net_message.data, net_message.cursize, 1, demofile);
fflush (demofile);
}
/*
=================
CL_DemoSaveState
used during demo playback to record the initial state of some variables
=================
*/
void CL_DemoSaveState (void)
{
/* int i;
for (i = 0; i < MAX_CL_STATS; i++)
demo_state_orig.stats[i] = cl.stats[i];
demo_state_orig.viewentity = cl.viewentity;
demo_state_orig.viewheight = cl.viewheight;
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
demo_state_orig.entvars = cl.v;
demo_state_orig.info_mask = cl.info_mask;
demo_state_orig.info_mask2 = cl.info_mask2;
}
#endif
*/
}
// QW demo message types:
#define dem_cmd 0
#define dem_read 1
#define dem_set 2
/*
#define dem_multiple 3 // MVD ONLY. This message is directed to several clients.
#define dem_single 4 // MVD ONLY. This message is directed to a single client.
#define dem_stats 5 // MVD ONLY. Stats update for a player.
#define dem_all 6 // MVD ONLY. This message is directed to all clients.
*/
/*
====================
CL_GetDemoMessage
JDH: split off from CL_GetMessage
====================
*/
int CL_GetDemoMessage (void)
{
int r, i;
float f;
double demotime;
byte c;
qboolean connectionless = false;
// if (start_of_demo && cl_demorewind.value)
if (!dem_framepos && cl_demorewind.value)
return 0;
// if there are pending commands, run them now
// (this is needed so Hexen II demos can switch maps properly)
if (!Cbuf_IsEmpty()) // --> 2011/05/18: moved from below, execute directly
{
Cbuf_Execute ();
if (!cls.demoplayback) // in case command in cbuf caused demo to stop
return 0;
}
if ((cls.signon < SIGNONS) && dem_framepos) // clear stack if new demo (or new run within same demo)
ClearFrameposStack ();
#if 0 // --> changed 2011/05/18 (fixes speed issues in Rubicon2 demos)
if (!Cbuf_IsEmpty()) // if there are pending commands, return 0 so they can be run
return 0; // (this is needed so Hexen II demos can switch maps properly)
#endif
/*if (is_qwd && !cl_demorewind.value) --> removed 2010/01/20
{
// read the time from the packet
fread(&f, sizeof(f), 1, cls.demofile);
demotime = LittleFloat(f);
fseek (cls.demofile, ftell(cls.demofile)-4, SEEK_SET); // 'undo' read
}
else*/ demotime = cl.mtime;
// decide if it is time to grab the next message
if (cls.signon == SIGNONS) // only after fully connected
{
#ifndef OLDSEEK
if (!cl_demoseek)
#endif
{
if (cls.timedemo)
{
if (host_framecount == cls.td_lastframe)
return 0; // already read this frame's message
cls.td_lastframe = host_framecount;
// if this is the second frame, grab the real td_starttime
// so the bogus time on the first frame doesn't count
if (host_framecount == cls.td_startframe + 1)
cls.td_starttime = realtime;
}
// modified by joe to handle rewind playing
else if (!cl_demorewind.value && (cl.ctime <= demotime))
{
#ifdef _DEBUG
// Con_Printf("delaying before next message (ctime = %.3lf, demotime = %.3lf)\n", cl.ctime, demotime);
#endif
return 0; // don't need another message yet
}
else if (cl_demorewind.value && (cl.ctime >= demotime))
{
#ifdef _DEBUG
// Con_Printf("delaying before next message (ctime = %.3lf, demotime = %.3lf)\n", cl.ctime, demotime);
#endif
return 0;
}
}
#ifdef _DEBUG
// Con_Printf("grabbing next message (ctime = %.3lf, demotime = %.3lf). realtime = %.3lf\n",
// cl.ctime, demotime, realtime);
#endif
// JDH: show OSD at start of demo, for 1sec longer than usual
// (have to do it here because realtime is halted until
// the 2nd frame)
if (scr_demo_overlay_time == 0)
scr_demo_overlay_time = realtime+1;
// joe: fill in the stack of frames' positions
// enable on intermission or not...?
// NOTE: it can't handle fixed intermission views!
if (!cl_demorewind.value /*&& !cl.intermission*/)
{
if (!cl_demo_starttime)
{
cl_demo_starttime = cl.mtime; // store time of first message once connected
CL_DemoSaveState ();
}
PushFrameposEntry (ftell(cls.demofile));
}
}
if (is_qwd)
{
while (1)
{
fread (&demotime, 4, 1, cls.demofile); // packet time
demotime = LittleFloat(demotime);
//cl.mtime_prev = cl.mtime; --> moved below 2010/01/20
//cl.mtime = demotime;
fread (&c, 1, 1, cls.demofile); // packet type
#ifdef _DEBUG
// Con_DPrintf ("Packet type %d; time = %f\n", c, demotime);
#endif
if (c == dem_set)
{
// JDH: just skip next 8 bytes & read next packet (FIXME?)
fread (&r, 4, 1, cls.demofile); // outgoing_sequence
fread (&r, 4, 1, cls.demofile); // incoming_sequence
}
else if (c == dem_cmd)
{
fseek (cls.demofile, 24, SEEK_CUR); // sizeof(qw's usercmd_t) - is this info needed??
VectorCopy (cl.mviewangles, cl.mviewangles_prev);
for (i=0 ; i<3 ; i++)
{
fread (&f, 4, 1, cls.demofile);
cl.mviewangles[i] = LittleFloat (f);
}
/*
i = ftell (cls.demofile);
fseek (cls.demofile, 4, SEEK_CUR);
VectorCopy (cl.mviewangles, cl.mviewangles_prev);
for (i=0 ; i<3 ; i++)
{
fread (&f, 4, 1, cls.demofile);
cl.mviewangles[i] = LittleFloat (f);
}
fseek (cls.demofile, 20, SEEK_CUR); // remainder of usercmd_t + viewangles
*/
}
else if (c == dem_read)
{
if (demotime != cl.mtime)
{
// if it's not a single update spread over multiple packets
cl.mtime_prev = cl.mtime;
cl.mtime = demotime;
}
break;
}
else
{
// Host_Error ("QuakeWorld Demo ERROR");
Con_Printf ("ERROR: invalid message type %d\n", c);
CL_StopPlayback ();
return 0;
}
}
}
// get the next message's size
fread (&net_message.cursize, 4, 1, cls.demofile);
net_message.cursize = LittleLong (net_message.cursize);
#ifdef _DEBUG
if (net_message.cursize == 1)
i = 0;
#endif
if (net_message.cursize > MAX_MSGLEN)
{
// JDH: try ignoring top 2 bytes
if ((net_message.cursize & 0xFFFF) > MAX_MSGLEN)
Host_Error ("Demo message > MAX_MSGLEN"); // JDH: was Sys_Error
Con_DPrintf ("\x02""Warning: invalid message length %u\n", net_message.cursize);
net_message.cursize &= 0xFFFF;
}
if (is_qwd)
{
fread (&r, 4, 1, cls.demofile); // sequence
net_message.cursize -= 4;
if (r == -1)
{
// -1 signals a "connectionless packet" (no ACK)
fread (&c, 1, 1, cls.demofile); // message id
fseek (cls.demofile, -1, SEEK_CUR); // 'undo' read
if (c != svc_disconnect) // disconnect gets handled normally (in CL_ParseServerMessage)
{
// Host_EndGame ("======== End of demo ========");
connectionless = true;
}
}
else
{
fread (&r, 4, 1, cls.demofile); // sequence ACK
net_message.cursize -= 4;
}
}
else
{
VectorCopy (cl.mviewangles, cl.mviewangles_prev);
for (i=0 ; i<3 ; i++)
{
r = fread (&f, 4, 1, cls.demofile);
cl.mviewangles[i] = LittleFloat (f);
}
}
r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
if (r != 1)
{
CL_StopPlayback ();
return 0;
}
#ifdef _DEBUG
if (hexen2 && !Q_strcasecmp(COM_SkipPath(cl_demo_filepath), "walk1.dem"))
if (ftell(cls.demofile) == 189819) // message with "reconnect" cmd
r = 1;
#endif
// joe: get out framestack's top entry
if (cl_demorewind.value && dem_framepos && dem_framecount/*&& !cl.intermission*/)
{
//fseek (cls.demofile, dem_framepos->inpos, SEEK_SET);
fseek (cls.demofile, dem_framepos->entries[dem_framecount-1].inpos, SEEK_SET);
EraseTopEntry ();
//if (!dem_framepos)
// start_of_demo = true;
}
if (connectionless) // **** UNTESTED (never encountered) ****
{
// TODO: handle various commands
return CL_GetDemoMessage ();
}
return 1;
}
/*
====================
CL_GetMessage
Handles recording and playback of demos, on top of NET_ code
====================
*/
int CL_GetMessage (void)
{
int r;
// JDH: pause if in menu/console when capturing a demo to movie
if (cls.capturedemo)
{
if ((cls.signon == SIGNONS) && !Movie_IsActive())
return 0;
}
// by joe: pause during demo
if (cl.paused & 2)
return 0;
CheckDZipCompletion ();
if (dz_app_op)
return 0;
if (cls.demoplayback)
return CL_GetDemoMessage ();
while (1)
{
r = NET_GetMessage (cls.netcon);
if (r != 1 && r != 2)
return r;
// discard nop keepalive message
if (net_message.cursize == 1 && net_message.data[0] == svc_nop)
Con_Print ("<-- server to client keepalive\n");
else
break;
}
// JDH: moved to after CL_ParseServerMessage
// if (cls.demorecording)
// CL_WriteDemoMessage (cls.demofile, cl.viewangles);
// joe: support for recording demos after connecting
if (cls.signon < 2)
{
memcpy (demo_head[cls.signon], net_message.data, net_message.cursize);
demo_head_size[cls.signon] = net_message.cursize;
}
return r;
}
/*
void CL_SkipEntityUpdate (int bits)
{
int i, num, count = 0;
if (bits & U_MOREBITS)
bits |= (MSG_ReadByte() << 8);
count += (bits & U_LONGENTITY) ? 2 : 1;
if (bits & U_FRAME)
count++;
for (i = 0; i < 3; i++)
{
if (bits & (U_ORIGIN1 << i))
count += 2;
num = (i == 0) ? U_ANGLE1 : (i == 1) ? U_ANGLE2 : U_ANGLE3;
if (bits & num)
count++;
}
#ifdef HEXEN2_SUPPORT
if (hexen2)
{
if (bits & U_MOREBITS2)
bits |= (MSG_ReadByte () << 16);
if (bits & U_MODEL)
count += 2;
if (bits & U_COLORMAP_H2)
count++;
if (bits & U_SKIN_H2)
count += 2; // skinnum & drawflags
if (bits & U_EFFECTS_H2)
count++;
if (bits & U_SCALE)
count += 2; // scale & abslight
msg_readcount += count;
return;
}
#endif
if (bits & U_MODEL)
count += ((cl.protocol == PROTOCOL_VERSION_STD) ? 1 : 2);
if (bits & U_COLORMAP)
count++;
if (bits & U_SKIN)
count++;
if (bits & U_EFFECTS)
count++;
msg_readcount += count;
if (bits & U_TRANS)
{
i = MSG_ReadFloat ();
MSG_ReadFloat ();
if (i == 2)
MSG_ReadFloat ();
}
}
// size of messages using standard protocol (-1 means special handling is needed, -9 means bad code)
int cl_msgsizes[53] =
{
0, 0, 0, 5, 4, 2, -1, -1, -1, -1, 3, -1, -1, -1, 3, -1, 2, 2, // svc_bad to svc_updatecolors (0 to 17)
11, 8, -1, -1, -1, -1, 1, 1, -1, 0, 0, -1, 0, -1, 2, 0, -1, // svc_particle to svc_cutscene (18 to 34)
-1, -1, -1, -9, -9, -9, 6, -9, -9, -9, -9, -9, -9, -9, -9, 2, -1 // svc_showlmp to svc_fog_neh (35 to 51)
};
#define MSG_SKIPSTRING() \
while (1) { \
if (msg_readcount >= net_message.cursize) \
{ \
msg_badread = true; \
break; \
} \
if (!net_message.data[msg_readcount++]) \
break; \
}
#define MSG_SKIPSTRINGLIST() \
do { \
MSG_SKIPSTRING(); \
if (!net_message.data[msg_readcount++]) \
break; \
} while (!msg_badread);
*/
/*
====================
CL_ParseDemoMessage (JDH)
====================
*/
/*qboolean CL_ParseDemoMessage (void)
{
int cmd, val;
entity_state_t entstate;
float time;
MSG_BeginReading ();
while (1)
{
if (msg_badread)
break;
cmd = MSG_ReadByte ();
if (cmd == -1)
break; // end of message
if (cmd & U_SIGNAL)
{
CL_SkipEntityUpdate (cmd & 127);
continue;
}
if ((cmd > 51) || (cmd == svc_bad) || (cmd == svc_disconnect))
return false;
val = cl_msgsizes[cmd];
if (val == -9)
return false; // unknown command
if (val >= 0)
{
msg_readcount += val;
continue;
}
switch (cmd)
{
case svc_time:
// time doesn't always increase (eg. map restarted in same demo)
time = MSG_ReadFloat ();
if (time < cl_demo_endtime)
return false; // restart of level, or new level
cl_demo_endtime = time;
return true; // assume only 1 svc_time per message
case svc_sound:
CL_ParseStartSoundPacket (true);
break;
case svc_spawnstaticsound:
CL_ParseStaticSound (true);
break;
case svc_serverinfo:
val = MSG_ReadLong ();
if (!CL_IsKnownProtocol (&val))
return false;
msg_readcount += 2;
MSG_SKIPSTRING(); // server greeting
MSG_SKIPSTRINGLIST(); // model precache
MSG_SKIPSTRINGLIST(); // sound precache
break;
case svc_lightstyle:
case svc_updatename:
MSG_ReadByte (); // (and follow through to MSG_ReadString)
case svc_print:
case svc_stufftext:
case svc_centerprint:
case svc_finale:
case svc_cutscene:
case svc_hidelmp:
case svc_skybox:
MSG_SKIPSTRING ();
break;
case svc_spawnbaseline:
MSG_ReadShort (); // (and follow through to CL_ParseBaseline)
case svc_spawnstatic:
CL_ParseBaseline (&entstate);
break;
case svc_clientdata:
msg_readcount += CL_ClientdataSize (MSG_ReadShort ());
break;
case svc_temp_entity:
CL_ParseTEnt (true);
break;
case svc_showlmp:
MSG_SKIPSTRING ();
MSG_SKIPSTRING ();
msg_readcount += 2;
break;
case svc_fog_fitz:
msg_readcount += 6;
break;
case svc_fog_neh:
if (MSG_ReadByte ())
msg_readcount += 7;
break;
}
}
return true;
}
*/
/*
====================
CL_FindDemoLength (JDH)
- parses all the demo messages from the current point forward,
and records the largest svc_time value
====================
*/
/*void CL_FindDemoEndTime (void)
{
long orig_pos, orig_protocol;
int r;
float time;
orig_pos = ftell (cls.demofile);
orig_protocol = cl.protocol;
while (1)
{
r = fread (&net_message.cursize, 4, 1, cls.demofile);
if (r != 1)
break;
if (fseek (cls.demofile, 12, SEEK_CUR)) // viewangles
break;
net_message.cursize = LittleLong (net_message.cursize);
if (net_message.cursize <= MAX_MSGLEN)
{
if (net_message.cursize >= 5)
{
// messages usually start with time command, so try that first:
r = fread (net_message.data, 5, 1, cls.demofile);
if (r != 1)
break;
if (net_message.data[0] == svc_time)
{
time = LittleFloat (*(float *) (net_message.data + 1));
//if (time > cl_demo_endtime)
// cl_demo_endtime = time;
if (time < cl_demo_endtime)
break; // restart of level, or new level
cl_demo_endtime = time;
fseek (cls.demofile, net_message.cursize-5, SEEK_CUR);
}
else
{
if (net_message.cursize > 5)
{
r = fread (net_message.data+5, net_message.cursize-5, 1, cls.demofile);
if (r != 1)
break;
}
if (!CL_ParseDemoMessage ())
break;
}
continue;
}
}
if (fseek (cls.demofile, net_message.cursize, SEEK_CUR))
break;
}
fseek (cls.demofile, orig_pos, SEEK_SET);
cl.protocol = orig_protocol;
}
*/
/*
====================
CL_FindDemoEndTime (JDH)
- parses all the demo messages from the current point forward,
and records the largest svc_time value
(FIXME? - uses svc_time only if it's the first command in a message
====================
*/
void CL_FindDemoEndTime (void)
{
long orig_pos, /*orig_protocol,*/ bytes_read = 0;
int size;
size_t read_size;
float time;
byte buf[24];
orig_pos = ftell (cls.demofile);
// orig_protocol = cl.protocol;
if (is_qwd)
read_size = 5; // packet time (4) + packet type (1)
else
read_size = 21; // msg size (4) + viewangles (12) + first 5 bytes of message
while (1)
{
// (bounds is checked before doing fread, since a demo in a pak
// may give a successful fread even though eof has been reached)
if (orig_pos + bytes_read + read_size > cl_demo_filestart + cl_demo_filesize)
break;
if (fread (buf, read_size, 1, cls.demofile) != 1)
break;
bytes_read += read_size;
if (is_qwd)
{
time = LittleFloat(*(float *) buf);
if (time < cl_demo_endtime)
break; // restarting level, or new level
cl_demo_endtime = time;
if (buf[4] == dem_set)
{
if (fseek (cls.demofile, 8, SEEK_CUR)) // sequence numbers
break;
bytes_read += 8;
continue;
}
else if (buf[4] == dem_cmd)
{
if (fseek (cls.demofile, 36, SEEK_CUR)) // usercmd_t (qw) + viewangles
break;
bytes_read += 36;
continue;
}
else if (buf[4] == dem_read)
{
if (fread (&size, 4, 1, cls.demofile) != 1) // message size
break;
bytes_read += 4;
size = LittleLong (size) & 0xFFFF;
}
else break;
}
else
{
size = LittleLong (*(int *) buf) & 0xFFFF;
if (size >= 5)
{
// messages usually start with time command:
if (buf[16] == svc_time)
{
time = LittleFloat (*(float *) (buf + 17));
//if (time > cl_demo_endtime)
// cl_demo_endtime = time;
if (time < cl_demo_endtime)
break; // restarting level, or new level
cl_demo_endtime = time;
}
}
size -= 5;
}
if (fseek (cls.demofile, size, SEEK_CUR))
break;
bytes_read += size;
#ifdef _DEBUG
if (orig_pos + bytes_read != ftell(cls.demofile))
bytes_read *= 1;
#endif
}
fseek (cls.demofile, orig_pos, SEEK_SET);
// cl.protocol = orig_protocol;
}
extern float scr_centertime_off;
/*
====================
CL_DemoSeek (JDH)
jumps to given position [0..1] in demo
====================
*/
void CL_DemoSeek (float pos)