forked from QW-Group/ezquake-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl_demo.c
5173 lines (4326 loc) · 125 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.
Copyright (C) 2007-2015 ezQuake team
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 included (GNU.txt) 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.
*/
#include <time.h>
#include "quakedef.h"
#include "movie.h"
#include "menu_demo.h"
#include "qtv.h"
#include "gl_model.h"
#include "gl_local.h"
#include "tr_types.h"
#include "teamplay.h"
#include "pmove.h"
#include "fs.h"
#include "hash.h"
#include "vfs.h"
#include "utils.h"
#include "crc.h"
#include "logging.h"
#include "version.h"
#include "demo_controls.h"
#include "mvd_utils.h"
#ifndef CLIENTONLY
#include "server.h"
#endif
/* FIXME Move these to a proper header file and included that */
void Cam_Unlock(void);
// TODO: Create states for demo_recording, demo_playback, and so on and put all related vars into these.
// Right now with global vars for everything is a mess. Also renaming some of the time vars to be less
// confusing is probably good. demotime, olddemotime, nextdemotime, prevtime...
typedef struct demo_state_s
{
float olddemotime;
float nextdemotime;
double bufferingtime;
sizebuf_t democache;
qbool democache_available;
#ifdef _WIN32
qbool qwz_unpacking;
qbool qwz_playback;
qbool qwz_packing;
char tempqwd_name[256];
#endif // _WIN32
} demo_state_t;
double olddemotime, nextdemotime; // TODO: Put in a demo struct.
double bufferingtime; // if we stream from QTV, this is non zero when we trying fill our buffer
//
// Vars related to QIZMO compressed demos.
// (Only available in Win32 since we need to use an external app)
//
#ifdef _WIN32
static qbool qwz_unpacking = false;
static qbool qwz_playback = false;
static qbool qwz_packing = false;
#define QWZ_DECOMPRESSION_TIMEOUT_MS 10000
static void OnChange_demo_format(cvar_t*, char*, qbool*);
cvar_t demo_format = {"demo_format", "qwz", 0, OnChange_demo_format};
static HANDLE hQizmoProcess = NULL;
static char tempqwd_name[256] = {0}; // This file must be deleted after playback is finished.
int CL_Demo_Compress(char*);
#endif
static vfsfile_t *CL_Open_Demo_File(char *name, qbool searchpaks, char **fullpath);
static void OnChange_demo_dir(cvar_t *var, char *string, qbool *cancel);
cvar_t demo_dir = {"demo_dir", "", 0, OnChange_demo_dir};
cvar_t demo_benchmarkdumps = {"demo_benchmarkdumps", "1"};
cvar_t cl_startupdemo = {"cl_startupdemo", ""};
cvar_t demo_jump_rewind = { "demo_jump_rewind", "-10" };
// Used to save track status when rewinding.
static vec3_t rewind_angle;
static vec3_t rewind_pos;
static double qtv_demospeed = 1;
static int rewind_spec_track = 0;
char Demos_Get_Trackname(void);
static void CL_DemoPlaybackInit(void);
void CL_ProcessUserInfo(int slot, player_info_t *player, char *key);
char *CL_DemoDirectory(void);
void CL_Demo_Jump_Status_Check (void);
//=============================================================================
// DEMO WRITING
//=============================================================================
static FILE *recordfile = NULL; // File used for recording demos. // TODO: Put in a demo struct.
static float playback_recordtime; // Time when in demo playback and recording. // TODO: Put in a demo struct.
#define DEMORECORDTIME ((float) (cls.demoplayback ? playback_recordtime : cls.realtime))
#define DEMOCACHE_MINSIZE (2 * 1024 * 1024)
#define DEMOCACHE_FLUSHSIZE (1024 * 1024)
static sizebuf_t democache; // TODO: Put in a demo struct.
static qbool democache_available = false; // Has the user opted to use a demo cache? // TODO: Put in a demo struct.
//
// Opens a demo for writing.
//
static qbool CL_Demo_Open(char *name)
{
// Clear the demo cache and open the demo file for writing.
if (democache_available)
SZ_Clear(&democache);
recordfile = fopen (name, "wb");
return recordfile ? true : false;
}
//
// Closes a demo.
//
static void CL_Demo_Close(void)
{
// Flush the demo cache and close the demo file.
if (democache_available)
fwrite(democache.data, democache.cursize, 1, recordfile);
fclose(recordfile);
recordfile = NULL;
}
//
// Writes a chunk of data to the currently opened demo record file.
//
static void CL_Demo_Write(void *data, int size)
{
if (democache_available)
{
//
// Write to the demo cache.
//
if (size > democache.maxsize)
{
// The size of the data to be written is bigger than the demo cache, fatal error.
Sys_Error("CL_Demo_Write: size > democache.maxsize");
}
else if (size > democache.maxsize - democache.cursize)
{
//
// Flushes part of the demo cache (enough to fit the new data) if it has been overflowed.
//
int overflow_size = size - (democache.maxsize - democache.cursize);
Com_Printf("Warning: democache overflow...flushing\n");
if (overflow_size <= DEMOCACHE_FLUSHSIZE)
overflow_size = min(DEMOCACHE_FLUSHSIZE, democache.cursize);
// Write as much data as overflowed from the current
// contents of the demo cache to the demo file.
fwrite(democache.data, overflow_size, 1, recordfile);
// Shift the cache contents (remove what was just written).
memmove(democache.data, democache.data + overflow_size, democache.cursize - overflow_size);
democache.cursize -= overflow_size;
// Write the new data to the demo cache.
SZ_Write(&democache, data, size);
}
else
{
// Write to the demo cache.
SZ_Write(&democache, data, size);
}
}
else
{
//
// Write directly to the file.
//
fwrite (data, size, 1, recordfile);
}
}
//
// Flushes any pending write operations to the recording file.
//
static void CL_Demo_Flush(void)
{
fflush(recordfile);
}
//
// Writes a user cmd to the open demo file.
//
void CL_WriteDemoCmd (usercmd_t *pcmd)
{
int i;
float fl, t[3];
byte c;
usercmd_t cmd;
// Write the current time.
fl = LittleFloat(DEMORECORDTIME);
CL_Demo_Write(&fl, sizeof(fl));
// Write the message type. A user cmd (movement and such).
c = dem_cmd;
CL_Demo_Write(&c, sizeof(c));
// Correct for byte order, bytes don't matter.
cmd = *pcmd;
// Convert the movement angles / vectors to the correct byte order.
for (i = 0; i < 3; i++)
cmd.angles[i] = LittleFloat(cmd.angles[i]);
cmd.forwardmove = LittleShort(cmd.forwardmove);
cmd.sidemove = LittleShort(cmd.sidemove);
cmd.upmove = LittleShort(cmd.upmove);
// Write the actual user command to the demo.
CL_Demo_Write(&cmd, sizeof(cmd));
// Write the view angles with the correct byte order.
t[0] = LittleFloat (cl.viewangles[0]);
t[1] = LittleFloat (cl.viewangles[1]);
t[2] = LittleFloat (cl.viewangles[2]);
CL_Demo_Write(t, sizeof(t));
// Flush the changes to file.
CL_Demo_Flush();
}
//
// Dumps the current net message, prefixed by the length and view angles
//
void CL_WriteDemoMessage (sizebuf_t *msg)
{
int len;
float fl;
byte c;
// Write time of cmd.
fl = LittleFloat(DEMORECORDTIME);
CL_Demo_Write(&fl, sizeof(fl));
// Write the message type. Net message.
c = dem_read;
CL_Demo_Write(&c, sizeof(c));
// Write the length of the data.
len = LittleLong (msg->cursize);
CL_Demo_Write(&len, 4);
// Write the data.
CL_Demo_Write(msg->data, msg->cursize);
// Flush the changes to the recording file.
CL_Demo_Flush();
// Request pings from the net chan if the user has set it.
{
extern void Request_Pings(void);
extern cvar_t demo_getpings;
if (demo_getpings.value)
Request_Pings();
}
}
//
// Writes the entities list to a demo.
//
void CL_WriteDemoEntities (void)
{
int ent_index, ent_total;
entity_state_t *ent;
// Write the ID byte for a delta entity operation to the demo.
MSG_WriteByte (&cls.demomessage, svc_packetentities);
// Get the entities list from the frame.
ent = cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK].packet_entities.entities;
ent_total = cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK].packet_entities.num_entities;
// Write all the entity changes since last packet entity message.
for (ent_index = 0; ent_index < ent_total; ent_index++, ent++)
MSG_WriteDeltaEntity (&cl_entities[ent->number].baseline, ent, &cls.demomessage, true, cls.fteprotocolextensions);
// End of packetentities.
MSG_WriteShort (&cls.demomessage, 0);
}
//
// Writes a startup demo message to the demo being recorded.
//
static void CL_WriteStartupDemoMessage (sizebuf_t *msg, int seq)
{
int len, i;
float fl;
byte c;
// Don't write, we're not recording.
if (!cls.demorecording)
return;
// Write the time.
fl = LittleFloat(DEMORECORDTIME);
CL_Demo_Write(&fl, sizeof(fl));
// Message type = net message.
c = dem_read;
CL_Demo_Write(&c, sizeof(c));
// Write the length of the message.
len = LittleLong (msg->cursize + 8);
CL_Demo_Write(&len, 4);
// Write the sequence number twice. Why?
i = LittleLong(seq);
CL_Demo_Write(&i, 4);
CL_Demo_Write(&i, 4);
// Write the actual message data to the demo.
CL_Demo_Write(msg->data, msg->cursize);
// Flush the message to file.
CL_Demo_Flush();
}
//
// Writes a set demo message. The outgoing / incoming sequence at the start of the demo.
// This is only written once at startup.
//
static void CL_WriteSetDemoMessage (void)
{
int len;
float fl;
byte c;
// We're not recording.
if (!cls.demorecording)
return;
// Write the demo time.
fl = LittleFloat(DEMORECORDTIME);
CL_Demo_Write(&fl, sizeof(fl));
// Write the message type.
c = dem_set;
CL_Demo_Write(&c, sizeof(c));
// Write the outgoing / incoming sequence.
len = LittleLong(cls.netchan.outgoing_sequence);
CL_Demo_Write(&len, 4);
len = LittleLong(cls.netchan.incoming_sequence);
CL_Demo_Write(&len, 4);
// Flush the demo file to disk.
CL_Demo_Flush();
}
// FIXME: same as in sv_user.c. Move to common.c?
static char *TrimModelName (const char *full)
{
static char shortn[MAX_QPATH];
int len;
if (!strncmp(full, "progs/", 6) && !strchr(full + 6, '/'))
strlcpy (shortn, full + 6, sizeof(shortn)); // strip progs/
else
strlcpy (shortn, full, sizeof(shortn));
len = strlen(shortn);
if (len > 4 && !strcmp(shortn + len - 4, ".mdl")
&& strchr(shortn, '.') == shortn + len - 4)
{ // strip .mdl
shortn[len - 4] = '\0';
}
return shortn;
}
void CL_WriteServerdata (sizebuf_t *msg)
{
int ignore_extensions;
MSG_WriteByte (msg, svc_serverdata);
// Maintain demo compatibility.
ignore_extensions = 0;
#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
// this is OK, since download data skipped anyway
ignore_extensions |= FTE_PEXT_CHUNKEDDOWNLOADS;
#endif
#ifdef FTE_PEXT_256PACKETENTITIES
// this is probably OK, since engine should ignore more than 64 entities if not supported.
ignore_extensions |= FTE_PEXT_256PACKETENTITIES;
#endif
#ifdef PROTOCOL_VERSION_FTE
if (cls.fteprotocolextensions &~ ignore_extensions)
{
MSG_WriteLong (msg, PROTOCOL_VERSION_FTE);
MSG_WriteLong (msg, cls.fteprotocolextensions);
}
#endif // PROTOCOL_VERSION_FTE
// Maintain demo pseudo-compatibility,
ignore_extensions = 0;
#ifdef PROTOCOL_VERSION_FTE2
if (cls.fteprotocolextensions2 & ~ignore_extensions)
{
MSG_WriteLong (msg, PROTOCOL_VERSION_FTE2);
MSG_WriteLong (msg, cls.fteprotocolextensions2);
}
#endif // PROTOCOL_VERSION_FTE2
MSG_WriteLong (msg, PROTOCOL_VERSION);
MSG_WriteLong (msg, cl.servercount);
MSG_WriteString (msg, cls.gamedirfile);
// Write if we're a spectator or not.
if (cl.spectator)
MSG_WriteByte (msg, cl.playernum | 128);
else
MSG_WriteByte (msg, cl.playernum);
// Send full levelname.
MSG_WriteString (msg, cl.levelname);
// Send the movevars.
MSG_WriteFloat(msg, movevars.gravity);
MSG_WriteFloat(msg, movevars.stopspeed);
MSG_WriteFloat(msg, cl.maxspeed);
MSG_WriteFloat(msg, movevars.spectatormaxspeed);
MSG_WriteFloat(msg, movevars.accelerate);
MSG_WriteFloat(msg, movevars.airaccelerate);
MSG_WriteFloat(msg, movevars.wateraccelerate);
MSG_WriteFloat(msg, movevars.friction);
MSG_WriteFloat(msg, movevars.waterfriction);
MSG_WriteFloat(msg, cl.entgravity);
}
//
// Write startup data to demo (called when demo started and cls.state == ca_active)
//
static void CL_WriteStartupData (void)
{
sizebuf_t buf;
char buf_data[MAX_MSGLEN * 2], *s;
int n, i, j, seq = 1;
entity_t *ent;
entity_state_t *es, blankes;
player_info_t *player;
//
// Serverdata
// Send the info about the new client to all connected clients.
//
// Init a buffer that we write to before writing to the file.
SZ_Init (&buf, (byte *) buf_data, sizeof(buf_data));
//
// Send the serverdata.
//
CL_WriteServerdata (&buf);
// Send music.
MSG_WriteByte (&buf, svc_cdtrack);
MSG_WriteByte (&buf, 0); // None in demos
// Send server info string.
MSG_WriteByte (&buf, svc_stufftext);
MSG_WriteString (&buf, va("fullserverinfo \"%s\"\n", cl.serverinfo));
// Flush the buffer to the demo file and then clear it.
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
//
// Write the soundlist.
//
MSG_WriteByte (&buf, svc_soundlist);
MSG_WriteByte (&buf, 0);
// Loop through all sounds and write them to the demo.
n = 0;
s = cl.sound_name[n + 1];
while (*s)
{
// Write the sound name to the buffer.
MSG_WriteString (&buf, s);
// If the buffer is half full, flush it.
if (buf.cursize > MAX_MSGLEN / 2)
{
// End of the partial sound list.
MSG_WriteByte (&buf, 0);
// Write how many sounds we've listed so far.
MSG_WriteByte (&buf, n);
// Flush the buffer to the demo file and clear the buffer.
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
// Start on a new sound list and continue writing the
// remaining sounds.
MSG_WriteByte (&buf, svc_soundlist);
MSG_WriteByte (&buf, n + 1);
}
n++;
s = cl.sound_name[n+1];
}
// If the buffer isn't empty flush and clear it.
if (buf.cursize)
{
MSG_WriteByte (&buf, 0);
MSG_WriteByte (&buf, 0);
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
// Vwep modellist
if (cl.vwep_enabled && cl.vw_model_name[0][0])
{
// Send VWep precaches
// pray we don't overflow
char ss[1024] = "//vwep ";
for (i = 0; i < MAX_VWEP_MODELS; i++) {
s = cl.vw_model_name[i];
if (!*s)
break;
if (i > 0)
strlcat (ss, " ", sizeof(ss));
strlcat (ss, TrimModelName(s), sizeof(ss));
}
strlcat (ss, "\n", sizeof(ss));
if (strlen(ss) < sizeof(ss)-1) // Didn't overflow?
{
MSG_WriteByte (&buf, svc_stufftext);
MSG_WriteString (&buf, ss);
}
}
// Don't bother flushing, the vwep list is not that large (I hope).
//
// Modellist.
//
MSG_WriteByte (&buf, svc_modellist);
MSG_WriteByte (&buf, 0);
// Loop through the models
n = 0;
s = cl.model_name[n + 1];
while (*s)
{
// Write the model name to the buffer.
MSG_WriteString (&buf, s);
// If the buffer is half full, flush it.
if (buf.cursize > MAX_MSGLEN / 2)
{
// End of partial model list.
MSG_WriteByte (&buf, 0);
// Write how many models we've written so far.
MSG_WriteByte (&buf, n);
// Flush the model list to the demo file and clear the buffer.
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
// Start on a new partial model list and continue.
MSG_WriteByte (&buf, svc_modellist);
MSG_WriteByte (&buf, n + 1);
}
n++;
s = cl.model_name[n + 1];
}
// Flush the buffer if it's not empty.
if (buf.cursize)
{
MSG_WriteByte (&buf, 0);
MSG_WriteByte (&buf, 0);
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
//
// Write static entities.
//
for (i = 0; i < cl.num_statics; i++)
{
// Get the next static entity.
ent = cl_static_entities + i;
// Write ID for static entities.
MSG_WriteByte (&buf, svc_spawnstatic);
// Find if the model is precached or not.
for (j = 1; j < MAX_MODELS; j++)
{
if (ent->model == cl.model_precache[j])
break;
}
// Write if the model is precached.
if (j == MAX_MODELS)
MSG_WriteByte (&buf, 0);
else
MSG_WriteByte (&buf, j);
// Write the entities frame and skin number.
MSG_WriteByte (&buf, ent->frame);
MSG_WriteByte (&buf, 0);
MSG_WriteByte (&buf, ent->skinnum);
// Write the coordinate and angles.
for (j = 0; j < 3; j++)
{
MSG_WriteCoord (&buf, ent->origin[j]);
MSG_WriteAngle (&buf, ent->angles[j]);
}
// Flush the buffer if it's half full.
if (buf.cursize > MAX_MSGLEN / 2)
{
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
}
// spawnstaticsound
for (i = 0; i < cl.num_static_sounds; i++)
{
static_sound_t *ss = &cl.static_sounds[i];
MSG_WriteByte (&buf, svc_spawnstaticsound);
for (j = 0; j < 3; j++)
MSG_WriteCoord (&buf, ss->org[j]);
MSG_WriteByte (&buf, ss->sound_num);
MSG_WriteByte (&buf, ss->vol);
MSG_WriteByte (&buf, ss->atten);
if (buf.cursize > MAX_MSGLEN/2)
{
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
}
//
// Write entity baselines.
//
memset(&blankes, 0, sizeof(blankes));
for (i = 0; i < CL_MAX_EDICTS; i++)
{
es = &cl_entities[i].baseline;
//
// If the entity state isn't blank write it to the buffer.
//
if (memcmp(es, &blankes, sizeof(blankes)))
{
// Write ID.
MSG_WriteByte (&buf, svc_spawnbaseline);
MSG_WriteShort (&buf, i);
// Write model info.
MSG_WriteByte (&buf, es->modelindex);
MSG_WriteByte (&buf, es->frame);
MSG_WriteByte (&buf, es->colormap);
MSG_WriteByte (&buf, es->skinnum);
// Write coordinates and angles.
for (j = 0; j < 3; j++)
{
MSG_WriteCoord(&buf, es->origin[j]);
MSG_WriteAngle(&buf, es->angles[j]);
}
// Flush to demo file if buffer is half full.
if (buf.cursize > MAX_MSGLEN / 2)
{
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
}
}
// Write spawn information into the clients console buffer.
MSG_WriteByte (&buf, svc_stufftext);
MSG_WriteString (&buf, va("cmd spawn %i 0\n", cl.servercount));
// Flush buffer to demo file.
if (buf.cursize)
{
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
//
// Send current status of all other players.
//
for (i = 0; i < MAX_CLIENTS; i++)
{
player = cl.players + i;
// Frags.
MSG_WriteByte (&buf, svc_updatefrags);
MSG_WriteByte (&buf, i);
MSG_WriteShort (&buf, player->frags);
// Ping.
MSG_WriteByte (&buf, svc_updateping);
MSG_WriteByte (&buf, i);
MSG_WriteShort (&buf, player->ping);
// Packet loss.
MSG_WriteByte (&buf, svc_updatepl);
MSG_WriteByte (&buf, i);
MSG_WriteByte (&buf, player->pl);
// Entertime.
MSG_WriteByte (&buf, svc_updateentertime);
MSG_WriteByte (&buf, i);
MSG_WriteFloat (&buf, cls.realtime - player->entertime);
// User ID and user info.
MSG_WriteByte (&buf, svc_updateuserinfo);
MSG_WriteByte (&buf, i);
MSG_WriteLong (&buf, player->userid);
MSG_WriteString (&buf, player->userinfo);
// Flush buffer to demo file.
if (buf.cursize > MAX_MSGLEN / 2)
{
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
}
// Send all current light styles.
for (i = 0; i < MAX_LIGHTSTYLES; i++)
{
// Don't send empty lightstyle strings.
if (!cl_lightstyle[i].length)
continue;
MSG_WriteByte (&buf, svc_lightstyle);
MSG_WriteByte (&buf, (char)i);
MSG_WriteString (&buf, cl_lightstyle[i].map);
}
for (i = 0; i < MAX_CL_STATS; i++)
{
// No need to send zero values.
if (!cl.stats[i])
continue;
// Write the current players user stats.
if (cl.stats[i] >= 0 && cl.stats[i] <= 255)
{
MSG_WriteByte (&buf, svc_updatestat);
MSG_WriteByte (&buf, i);
MSG_WriteByte (&buf, cl.stats[i]);
}
else
{
MSG_WriteByte (&buf, svc_updatestatlong);
MSG_WriteByte (&buf, i);
MSG_WriteLong (&buf, cl.stats[i]);
}
// Flush buffer to demo file.
if (buf.cursize > MAX_MSGLEN / 2)
{
CL_WriteStartupDemoMessage (&buf, seq++);
SZ_Clear (&buf);
}
}
// Get the client to check and download skins
// when that is completed, a begin command will be issued.
MSG_WriteByte (&buf, svc_stufftext);
MSG_WriteString (&buf, va("skins\n"));
CL_WriteStartupDemoMessage (&buf, seq++);
CL_WriteSetDemoMessage();
}
//=========================================================
// MVD demo writing
//=========================================================
static FILE *mvdrecordfile = NULL;
static char mvddemoname[2 * MAX_OSPATH] = {0};
static void CL_MVD_DemoWrite (void *data, int len)
{
if (!mvdrecordfile)
return;
fwrite(data, len, 1, mvdrecordfile);
}
// ====================
// CL_WriteRecordMVDMessage
// ====================
static void CL_WriteRecordMVDMessage (sizebuf_t *msg)
{
int len;
byte c;
if (!cls.mvdrecording)
return;
if (!msg->cursize)
return;
c = 0;
CL_MVD_DemoWrite (&c, sizeof(c));
c = dem_all;
CL_MVD_DemoWrite (&c, sizeof(c));
len = LittleLong (msg->cursize);
CL_MVD_DemoWrite (&len, 4);
CL_MVD_DemoWrite (msg->data, msg->cursize);
}
// ====================
// CL_WriteRecordMVDStatsMessage
// ====================
static void CL_WriteRecordMVDStatsMessage (sizebuf_t *msg, int client)
{
int len;
byte c;
if (!cls.mvdrecording)
return;
if (!msg->cursize)
return;
if (client < 0 || client >= MAX_CLIENTS)
return;
c = 0;
CL_MVD_DemoWrite (&c, sizeof(c));
c = dem_stats | (client << 3) ; // msg "type" and "to" incapsulated in one byte
CL_MVD_DemoWrite (&c, sizeof(c));
len = LittleLong (msg->cursize);
CL_MVD_DemoWrite (&len, 4);
CL_MVD_DemoWrite (msg->data, msg->cursize);
}
// TODO: Split this up?
void CL_WriteMVDStartupData(void)
{
sizebuf_t buf;
unsigned char buf_data[MAX_MSGLEN * 4];
player_info_t *player;
entity_state_t *es, blankes;
entity_t *ent;
int i, j, n;
char *s;
// Serverdata
// send the info about the new client to all connected clients
SZ_Init (&buf, buf_data, sizeof(buf_data));
// send the serverdata
MSG_WriteByte (&buf, svc_serverdata);
#ifdef PROTOCOL_VERSION_FTE
if (cls.fteprotocolextensions)
{
MSG_WriteLong (&buf, PROTOCOL_VERSION_FTE);
MSG_WriteLong (&buf, cls.fteprotocolextensions);
}
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
if (cls.fteprotocolextensions2)
{
MSG_WriteLong (&buf, PROTOCOL_VERSION_FTE2);
MSG_WriteLong (&buf, cls.fteprotocolextensions2);
}
#endif // PROTOCOL_VERSION_FTE2
MSG_WriteLong (&buf, PROTOCOL_VERSION);
MSG_WriteLong (&buf, cl.servercount);
//
// Gamedir.
//
s = cls.gamedirfile; // FIXME: or do we need to take a look in serverinfo?
if (!s[0])
s = "qw"; // If empty use "qw" gamedir
MSG_WriteString (&buf, s);
MSG_WriteFloat (&buf, cls.demotime); // FIXME: not sure
// Send full levelname.
MSG_WriteString (&buf, cl.levelname);
// Send the movevars.
MSG_WriteFloat(&buf, movevars.gravity);
MSG_WriteFloat(&buf, movevars.stopspeed);
MSG_WriteFloat(&buf, movevars.maxspeed);
MSG_WriteFloat(&buf, movevars.spectatormaxspeed);
MSG_WriteFloat(&buf, movevars.accelerate);
MSG_WriteFloat(&buf, movevars.airaccelerate);
MSG_WriteFloat(&buf, movevars.wateraccelerate);
MSG_WriteFloat(&buf, movevars.friction);
MSG_WriteFloat(&buf, movevars.waterfriction);
MSG_WriteFloat(&buf, movevars.entgravity);
// Send music.
MSG_WriteByte (&buf, svc_cdtrack);
MSG_WriteByte (&buf, 0); // None in demos.
// Send server info string.
MSG_WriteByte (&buf, svc_stufftext);
MSG_WriteString (&buf, va("fullserverinfo \"%s\"\n", cl.serverinfo));
// Flush packet.
CL_WriteRecordMVDMessage (&buf);
SZ_Clear (&buf);
//
// Soundlist.
//
MSG_WriteByte (&buf, svc_soundlist);
MSG_WriteByte (&buf, 0);
n = 0;
s = cl.sound_name[n + 1];
while (*s)
{
MSG_WriteString (&buf, s);
if (buf.cursize > MAX_MSGLEN/2)
{
MSG_WriteByte (&buf, 0);
MSG_WriteByte (&buf, n);
CL_WriteRecordMVDMessage (&buf);
SZ_Clear (&buf);
MSG_WriteByte (&buf, svc_soundlist);
MSG_WriteByte (&buf, n + 1);
}
n++;
s = cl.sound_name[n + 1];
}
if (buf.cursize)
{
MSG_WriteByte (&buf, 0);
MSG_WriteByte (&buf, 0);
CL_WriteRecordMVDMessage (&buf);
SZ_Clear (&buf);
}
//
// Modellist.
//