forked from QW-Group/ezquake-source
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cl_nqdemo.c
1379 lines (1143 loc) · 31.6 KB
/
cl_nqdemo.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) 2011 tonik
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, see <http://www.gnu.org/licenses/>.
*/
#include "quakedef.h"
#include "gl_model.h"
#include "cdaudio.h"
#include "stats_grid.h"
#include "sbar.h"
#include "qsound.h"
#include "hud.h"
#include "hud_common.h"
#include "vx_stuff.h"
#include "settings.h"
#include "teamplay.h"
#ifdef _WIN32
#include "movie.h"
#endif
#define MAX_BIG_MSGLEN 8000
int CL_Demo_Read(void *buf, int size, qbool peek);
#define SCR_EndLoadingPlaque()
int cl_entframecount;
#define CL_EntityParticles(a)
extern cvar_t cl_rocket2grenade;
#define R_ModelFlags(model) model->flags
void CL_FindModelNumbers (void);
void TP_NewMap (void);
void CL_ParseBaseline (entity_state_t *es);
void CL_ParseStatic (qbool extended);
void CL_ParseStaticSound (void);
#define NQ_PROTOCOL_VERSION 15
#define NQ_MAX_CLIENTS 16
#define NQ_SIGNONS 4
#define NQ_MAX_EDICTS 600 // Must be <= MAX_CL_EDICTS!
// if the high bit of the servercmd is set, the low bits are fast update flags:
#define NQ_U_MOREBITS (1<<0)
#define NQ_U_ORIGIN1 (1<<1)
#define NQ_U_ORIGIN2 (1<<2)
#define NQ_U_ORIGIN3 (1<<3)
#define NQ_U_ANGLE2 (1<<4)
#define NQ_U_NOLERP (1<<5) // don't interpolate movement
#define NQ_U_FRAME (1<<6)
#define NQ_U_SIGNAL (1<<7) // just differentiates from other updates
#define NQ_U_ANGLE1 (1<<8)
#define NQ_U_ANGLE3 (1<<9)
#define NQ_U_MODEL (1<<10)
#define NQ_U_COLORMAP (1<<11)
#define NQ_U_SKIN (1<<12)
#define NQ_U_EFFECTS (1<<13)
#define NQ_U_LONGENTITY (1<<14)
#define SU_VIEWHEIGHT (1<<0)
#define SU_IDEALPITCH (1<<1)
#define SU_PUNCH1 (1<<2)
#define SU_PUNCH2 (1<<3)
#define SU_PUNCH3 (1<<4)
#define SU_VELOCITY1 (1<<5)
#define SU_VELOCITY2 (1<<6)
#define SU_VELOCITY3 (1<<7)
//define SU_AIMENT (1<<8) AVAILABLE BIT
#define SU_ITEMS (1<<9)
#define SU_ONGROUND (1<<10) // no data follows, the bit is it
#define SU_INWATER (1<<11) // no data follows, the bit is it
#define SU_WEAPONFRAME (1<<12)
#define SU_ARMOR (1<<13)
#define SU_WEAPON (1<<14)
// a sound with no channel is a local only sound
#define NQ_SND_VOLUME (1<<0) // a byte
#define NQ_SND_ATTENUATION (1<<1) // a byte
#define NQ_SND_LOOPING (1<<2) // a long
//=========================================================================================
qbool nq_drawpings; // for sbar code
static qbool nq_player_teleported; // hacky
static vec3_t nq_last_fixangle;
static int nq_num_entities;
static int nq_viewentity;
static int nq_forcecdtrack;
static int nq_signon;
static int nq_maxclients;
static float nq_mtime[2];
static vec3_t nq_mvelocity[2];
static vec3_t nq_mviewangles[2];
static vec3_t nq_mviewangles_temp;
static qbool standard_quake = true;
static demoseekingtype_t nq_lastseektype = DST_SEEKING_NONE;
static void CL_CheckForNQDSeekPointFound(void)
{
float demotime = nq_mtime[0];
// Check for rewind only the first time we want to seek through the demo
if (cls.demoseeking != nq_lastseektype)
CL_Demo_Check_For_Rewind(nq_mtime[0]);
nq_lastseektype = cls.demoseeking;
if (cls.demoseeking == DST_SEEKING_STATUS)
CL_Demo_Jump_Status_Check();
// If we found demomark, we should stop seeking, so reset time to the proper value.
if (cls.demoseeking == DST_SEEKING_FOUND)
{
extern cvar_t demo_jump_rewind;
cls.demotime = demotime; // this will trigger seeking stop
if (demo_jump_rewind.value < 0) {
CL_Demo_Jump (-demo_jump_rewind.value, -1, DST_SEEKING_NORMAL);
}
}
// If we've reached our seek goal, stop seeking.
if (cls.demoseeking && cls.demotime <= demotime && cls.state >= ca_active)
{
cls.demoseeking = DST_SEEKING_NONE;
cls.demotime = demotime;
if (cls.demorewinding)
{
CL_Demo_Stop_Rewinding();
}
}
}
static qbool CL_GetNQDemoMessage (void)
{
int i;
float f;
extern qbool pb_ensure(void);
if(!pb_ensure())
return false;
// decide if it is time to grab the next message
if (cls.state == ca_active // always grab until fully connected
&& !(cl.paused & PAUSED_SERVER)) // or if the game was paused by server
{
if (cls.timedemo)
{
if (cls.framecount == cls.td_lastframe)
return false; // already read this frame's message
cls.td_lastframe = cls.framecount;
// if this is the second frame, grab the real td_starttime
// so the bogus time on the first frame doesn't count
if (cls.framecount == cls.td_startframe + 1) {
cls.td_starttime = Sys_DoubleTime();
key_dest = key_game;
}
}
else if (cl.time <= nq_mtime[0] && ! cls.demoseeking)
return false; // don't need another message yet
}
// get the next message
CL_Demo_Read(&net_message.cursize, 4, false);
for (i=0 ; i<3 ; i++) {
CL_Demo_Read(&f, 4, false);
nq_mviewangles_temp[i] = LittleFloat (f);
}
net_message.cursize = LittleLong (net_message.cursize);
if (net_message.cursize > MAX_BIG_MSGLEN)
Host_Error ("Demo message > MAX_BIG_MSGLEN");
CL_Demo_Read(net_message.data, net_message.cursize, false);
return true;
}
static void NQD_BumpEntityCount (int num)
{
if (num >= nq_num_entities)
nq_num_entities = num + 1;
}
static void NQD_ParseClientdata (int bits)
{
int i, j;
extern player_state_t view_message;
if (bits & SU_VIEWHEIGHT)
cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
else
cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
if (bits & SU_IDEALPITCH)
MSG_ReadChar (); // ignore
VectorCopy (nq_mvelocity[0], nq_mvelocity[1]);
for (i=0 ; i<3 ; i++)
{
if (bits & (SU_PUNCH1<<i) ) {
if (i == 0)
cl.punchangle = MSG_ReadChar ();
else
MSG_ReadChar(); // ignore
}
if (bits & (SU_VELOCITY1<<i) )
nq_mvelocity[0][i] = MSG_ReadChar()*16;
else
nq_mvelocity[0][i] = 0;
}
// [always sent] if (bits & SU_ITEMS)
i = MSG_ReadLong (); // FIXME, check SU_ITEMS anyway? -- Tonik
if (cl.stats[STAT_ITEMS] != i)
{ // set flash times
Sbar_Changed ();
for (j=0 ; j<32 ; j++)
if ( (i & (1<<j)) && !(cl.stats[STAT_ITEMS] & (1<<j)))
cl.item_gettime[j] = cl.time;
cl.stats[STAT_ITEMS] = i;
}
cl.onground = (bits & SU_ONGROUND) != 0;
// cl.inwater = (bits & SU_INWATER) != 0;
if (bits & SU_WEAPONFRAME)
view_message.weaponframe = MSG_ReadByte ();
else
view_message.weaponframe = 0;
if (bits & SU_ARMOR)
i = MSG_ReadByte ();
else
i = 0;
if (cl.stats[STAT_ARMOR] != i)
{
cl.stats[STAT_ARMOR] = i;
Sbar_Changed ();
}
if (bits & SU_WEAPON)
i = MSG_ReadByte ();
else
i = 0;
if (cl.stats[STAT_WEAPON] != i)
{
cl.stats[STAT_WEAPON] = i;
Sbar_Changed ();
}
i = MSG_ReadShort ();
if (cl.stats[STAT_HEALTH] != i)
{
cl.stats[STAT_HEALTH] = i;
Sbar_Changed ();
}
i = MSG_ReadByte ();
if (cl.stats[STAT_AMMO] != i)
{
cl.stats[STAT_AMMO] = i;
Sbar_Changed ();
}
for (i=0 ; i<4 ; i++)
{
j = MSG_ReadByte ();
if (cl.stats[STAT_SHELLS+i] != j)
{
cl.stats[STAT_SHELLS+i] = j;
Sbar_Changed ();
}
}
i = MSG_ReadByte ();
if (standard_quake)
{
if (cl.stats[STAT_ACTIVEWEAPON] != i)
{
cl.stats[STAT_ACTIVEWEAPON] = i;
Sbar_Changed ();
}
}
else
{
if (cl.stats[STAT_ACTIVEWEAPON] != (1<<i))
{
cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
Sbar_Changed ();
}
}
}
static void NQD_SetSpectatorFlag(player_info_t* player)
{
player->spectator = (cl.teamplay && player->name[0] && player->real_topcolor == 0 && player->real_bottomcolor == 0 && player->frags <= -99);
}
void NQD_SetSpectatorFlags(void)
{
int i;
for (i = 0; i < sizeof(cl.players) / sizeof(cl.players[0]); ++i)
NQD_SetSpectatorFlag(&cl.players[i]);
}
/*
==================
NQD_ParseUpdatecolors
==================
*/
static void NQD_ParseUpdatecolors (void)
{
int i, colors;
int top, bottom;
qbool client_team_changed = false;
qbool player_skin_changed = false;
i = MSG_ReadByte ();
if (i >= nq_maxclients)
Host_Error ("CL_ParseServerMessage: svc_updatecolors > NQ_MAX_CLIENTS");
colors = MSG_ReadByte ();
// fill in userinfo values
top = min(colors & 15, 13);
bottom = min((colors >> 4) & 15, 13);
client_team_changed = (cl.playernum == i && bottom != cl.players[i].real_bottomcolor);
player_skin_changed = (top != cl.players[i].real_topcolor || bottom != cl.players[i].real_bottomcolor);
Info_SetValueForKey (cl.players[i].userinfo, "topcolor", va("%i", top), MAX_INFO_KEY);
Info_SetValueForKey (cl.players[i].userinfo, "bottomcolor", va("%i", bottom), MAX_INFO_KEY);
cl.players[i].real_topcolor = top;
cl.players[i].real_bottomcolor = bottom;
NQD_SetSpectatorFlag(&cl.players[i]);
// Update team (based on bottom colour)
if (cl.players[i].spectator)
{
Info_SetValueForKey (cl.players[i].userinfo, "team", "", MAX_INFO_KEY);
strlcpy(cl.players[i].team, "", sizeof(cl.players[i].team));
}
else
{
char* bottom_as_string = SettingColorName(bottom);
Info_SetValueForKey (cl.players[i].userinfo, "team", bottom_as_string, MAX_INFO_KEY);
strlcpy(cl.players[i].team, bottom_as_string, sizeof(cl.players[i].team));
}
// Update skins
if (TP_NeedRefreshSkins() && client_team_changed)
TP_RefreshSkins();
else if (player_skin_changed)
TP_RefreshSkin(i);
Sbar_Changed ();
}
/*
==================
NQD_ParsePrint
==================
*/
static void NQD_ParsePrint (void)
{
extern cvar_t cl_chatsound;
char *s = MSG_ReadString();
if (s[0] == 1) { // chat
if (cl_chatsound.value)
S_LocalSound ("misc/talk.wav");
}
Com_Printf ("%s", s);
}
// JPG's ProQuake hacks
static int ReadPQByte (void) {
int word;
word = MSG_ReadByte() * 16;
word += MSG_ReadByte() - 272;
return word;
}
static int ReadPQShort (void) {
int word;
word = ReadPQByte() * 256;
word += ReadPQByte();
return word;
}
/*
==================
NQD_ParseStufftext
==================
*/
static void NQD_ParseStufftext (void)
{
char *s;
byte *p;
if (msg_readcount + 7 <= net_message.cursize &&
net_message.data[msg_readcount] == 1 && net_message.data[msg_readcount + 1] == 7)
{
int num, ping;
MSG_ReadByte();
MSG_ReadByte();
while ((ping = ReadPQShort()) != 0)
{
num = ping / 4096;
if ((unsigned int)num >= nq_maxclients)
Host_Error ("Bad ProQuake message");
cl.players[num].ping = ping & 4095;
nq_drawpings = true;
}
// fall through to stufftext parsing (yes that's how it's intended by JPG)
}
s = MSG_ReadString ();
if (developer.integer > 1) {
Com_DPrintf("stufftext: %s\n", s);
}
for (p = (byte *)s; *p; p++) {
if (*p > 32 && *p < 128)
goto ok;
}
// ignore weird ProQuake stuff
return;
ok:
Cbuf_AddTextEx (&cbuf_svc, s);
}
/*
==================
NQD_ParseServerData
==================
*/
static void NQD_ParseServerData(void)
{
char *str;
int i;
int nummodels, numsounds;
char mapname[MAX_QPATH];
Com_DPrintf("Serverdata packet received.\n");
// wipe the client_state_t struct
CL_ClearState();
#ifdef PROTOCOL_VERSION_FTE
cls.fteprotocolextensions = 0;
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
cls.fteprotocolextensions2 = 0;
#endif // PROTOCOL_VERSION_FTE2
#ifdef PROTOCOL_VERSION_MVD1
cls.mvdprotocolextensions1 = 0;
#endif
#ifdef FTE_PEXT_FLOATCOORDS
msg_coordsize = 2;
msg_anglesize = 1;
#endif
// parse protocol version number
i = MSG_ReadLong();
if (i != NQ_PROTOCOL_VERSION)
Host_Error("Server returned version %i, not %i", i, NQ_PROTOCOL_VERSION);
// parse maxclients
nq_maxclients = MSG_ReadByte();
if (nq_maxclients < 1 || nq_maxclients > NQ_MAX_CLIENTS)
Host_Error("Bad maxclients (%u) from server", nq_maxclients);
// parse gametype
cl.gametype = MSG_ReadByte() ? GAME_DEATHMATCH : GAME_COOP;
// parse signon message
str = MSG_ReadString();
strlcpy(cl.levelname, str, sizeof(cl.levelname));
// separate the printfs so the server message can have a color
Com_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");
Com_Printf("%c%s\n", 2, str);
//
// first we go through and touch all of the precache data that still
// happens to be in the cache, so precaching something else doesn't
// needlessly purge it
//
// precache models
*mapname = 0;
for (nummodels = 1; ; nummodels++) {
str = MSG_ReadString();
if (!str[0]) {
break;
}
if (nummodels == MAX_MODELS) {
Host_Error("Server sent too many model precaches");
}
strlcpy(cl.model_name[nummodels], str, sizeof(cl.model_name[0]));
Mod_TouchModel(str);
if (nummodels == 1) {
COM_StripExtension(COM_SkipPath(cl.model_name[1]), mapname, sizeof(mapname));
}
}
// precache sounds
for (numsounds = 1; ; numsounds++) {
str = MSG_ReadString();
if (!str[0]) {
break;
}
if (numsounds == MAX_SOUNDS) {
Host_Error("Server sent too many sound precaches");
}
strlcpy(cl.sound_name[numsounds], str, sizeof(cl.sound_name[0]));
// S_TouchSound (str); @ZQ@
}
// now we try to load everything else until a cache allocation fails
cl.clipmodels[1] = CM_LoadMap(cl.model_name[1], true, NULL, &cl.map_checksum2);
if (!com_serveractive) {
Cvar_ForceSet(&host_mapname, mapname);
}
COM_StripExtension(COM_SkipPath(cl.model_name[1]), mapname, sizeof(mapname));
cl.map_checksum2 = Com_TranslateMapChecksum(mapname, cl.map_checksum2);
for (i = 1; i < nummodels; i++) {
cl.model_precache[i] = Mod_ForName(cl.model_name[i], false);
if (cl.model_precache[i] == NULL) {
Host_Error("Model %s not found", cl.model_name[i]);
}
if (cl.model_name[i][0] == '*') {
cl.clipmodels[i] = CM_InlineModel(cl.model_name[i]);
}
}
for (i = 1; i < numsounds; i++) {
cl.sound_precache[i] = S_PrecacheSound(cl.sound_name[i]);
}
// local state
cl.worldmodel = cl.model_precache[1];
if (!cl.model_precache[1]) {
Host_Error("NQD_ParseServerData: NULL worldmodel");
}
Classic_InitParticles();
CL_FindModelNumbers();
R_NewMap(false);
TP_NewMap();
MT_NewMap();
Stats_NewMap();
// Reset the status grid.
StatsGrid_Remove(&stats_grid);
StatsGrid_ResetHoldItems();
HUD_NewMap();
Hunk_Check(); // make sure nothing is hurt
nq_signon = 0;
nq_num_entities = 0;
nq_drawpings = false; // unless we have the ProQuake extension
cl.servertime_works = true;
// cl.allow_fbskins = true; @ZQ@
cls.state = ca_onserver;
CL_Demo_Check_For_Rewind(nq_mtime[0]);
// Demos don't store this so we set from user-defined option
cl.teamplay = cl_demoteamplay.integer;
nq_lastseektype = DST_SEEKING_NONE;
}
/*
==================
NQD_ParseStartSoundPacket
==================
*/
static void NQD_ParseStartSoundPacket(void)
{
vec3_t pos;
int channel, ent;
int sound_num;
int volume;
int field_mask;
float attenuation;
int i;
field_mask = MSG_ReadByte();
if (field_mask & NQ_SND_VOLUME)
volume = MSG_ReadByte ();
else
volume = DEFAULT_SOUND_PACKET_VOLUME;
if (field_mask & NQ_SND_ATTENUATION)
attenuation = MSG_ReadByte () / 64.0;
else
attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
channel = MSG_ReadShort ();
sound_num = MSG_ReadByte ();
ent = channel >> 3;
channel &= 7;
if (ent > NQ_MAX_EDICTS)
Host_Error ("NQD_ParseStartSoundPacket: ent = %i", ent);
for (i=0 ; i<3 ; i++)
pos[i] = MSG_ReadCoord ();
S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0, attenuation);
}
/*
===============
CL_ParseParticleEffect
Back from NetQuake
===============
*/
static void CL_ParseParticleEffect (void)
{
vec3_t org, dir;
int i, count, color;
for (i = 0; i < 3; i++)
org[i] = MSG_ReadCoord ();
for (i = 0; i < 3; i++)
dir[i] = MSG_ReadChar () * (1.0/16);
count = MSG_ReadByte ();
color = MSG_ReadByte ();
// now run the effect
if (count == 255)
Classic_ParticleExplosion (org);
else
R_RunParticleEffect (org, dir, color, count);
}
/*
==================
NQD_ParseUpdate
Parse an entity update message from the server
If an entities model or origin changes from frame to frame, it must be
relinked. Other attributes can change without relinking.
==================
*/
static void NQD_ParseUpdate (int bits)
{
int i;
// model_t *model;
int modnum;
qbool forcelink;
centity_t *ent;
entity_state_t *state;
int num;
int prev_frame;
if (nq_signon == NQ_SIGNONS - 1)
{ // first update is the final signon stage
nq_signon = NQ_SIGNONS;
Con_ClearNotify ();
//TP_ExecTrigger ("f_spawn");
SCR_EndLoadingPlaque ();
cls.state = ca_active;
CL_Demo_Check_For_Rewind(nq_mtime[0]);
}
if (bits & NQ_U_MOREBITS)
{
i = MSG_ReadByte ();
bits |= (i<<8);
}
if (bits & NQ_U_LONGENTITY)
num = MSG_ReadShort ();
else
num = MSG_ReadByte ();
if (num >= NQ_MAX_EDICTS)
Host_Error ("NQD_ParseUpdate: ent > MAX_EDICTS");
NQD_BumpEntityCount (num);
ent = &cl_entities[num];
//## ent->previous = ent->current;
VectorCopy (ent->current.origin, ent->old_origin); //##
VectorCopy (ent->current.angles, ent->old_angles); //##
prev_frame = ent->current.frame;
ent->current = ent->baseline;
state = &ent->current;
state->number = num;
if (ent->sequence != cl_entframecount - 1)
forcelink = true; // no previous frame to lerp from
else
forcelink = false;
ent->oldsequence = ent->sequence;
ent->sequence = cl_entframecount;
if (bits & NQ_U_MODEL)
{
modnum = MSG_ReadByte ();
if (modnum >= MAX_MODELS)
Host_Error ("CL_ParseModel: bad modnum");
}
else
modnum = ent->baseline.modelindex;
// model = cl.model_precache[modnum];
if (modnum != state->modelindex)
{
state->modelindex = modnum;
// automatic animation (torches, etc) can be either all together
// or randomized
if (modnum)
{
/*if (model->synctype == ST_RAND)
state->syncbase = (float)(rand()&0x7fff) / 0x7fff;
else
state->syncbase = 0.0;
*/
}
else
forcelink = true; // hack to make null model players work
}
if (bits & NQ_U_FRAME)
state->frame = MSG_ReadByte ();
else
state->frame = ent->baseline.frame;
if (bits & NQ_U_COLORMAP)
i = MSG_ReadByte();
else
i = ent->baseline.colormap;
state->colormap = i;
if (bits & NQ_U_SKIN)
state->skinnum = MSG_ReadByte();
else
state->skinnum = ent->baseline.skinnum;
if (bits & NQ_U_EFFECTS)
state->effects = MSG_ReadByte();
else
state->effects = 0;
if (bits & NQ_U_ORIGIN1)
state->origin[0] = MSG_ReadCoord ();
else
state->origin[0] = ent->baseline.origin[0];
if (bits & NQ_U_ANGLE1)
state->angles[0] = MSG_ReadAngle ();
else
state->angles[0] = ent->baseline.angles[0];
if (bits & NQ_U_ORIGIN2)
state->origin[1] = MSG_ReadCoord ();
else
state->origin[1] = ent->baseline.origin[1];
if (bits & NQ_U_ANGLE2)
state->angles[1] = MSG_ReadAngle ();
else
state->angles[1] = ent->baseline.angles[1];
if (bits & NQ_U_ORIGIN3)
state->origin[2] = MSG_ReadCoord ();
else
state->origin[2] = ent->baseline.origin[2];
if (bits & NQ_U_ANGLE3)
state->angles[2] = MSG_ReadAngle ();
else
state->angles[2] = ent->baseline.angles[2];
if ( bits & NQ_U_NOLERP )
forcelink = true;
if (state->frame != prev_frame) {
ent->frametime = cl.time;
ent->oldframe = prev_frame;
}
if ( forcelink )
{ // didn't have an update last message
VectorCopy (state->origin, ent->old_origin);
VectorCopy (state->origin, ent->lerp_origin);
VectorCopy (state->angles, ent->old_angles);
//we get U_NOLERP for monsters, but we want to lerp them ent->frametime = -1;
//ent->forcelink = true;
}
}
/*
===============
NQD_LerpPoint
Determines the fraction between the last two messages that the objects
should be put at.
===============
*/
static float NQD_LerpPoint (void)
{
float f, frac;
f = nq_mtime[0] - nq_mtime[1];
if (!f || /* cl_nolerp.value || */ cls.timedemo) {
cl.time = nq_mtime[0];
return 1;
}
if (f > 0.1)
{ // dropped packet, or start of demo
nq_mtime[1] = nq_mtime[0] - 0.1;
f = 0.1;
}
frac = (cl.time - nq_mtime[1]) / f;
if (frac < 0)
{
if (frac < -0.01)
cl.time = nq_mtime[1];
frac = 0;
}
else if (frac > 1)
{
if (frac > 1.01)
cl.time = nq_mtime[0];
frac = 1;
}
return frac;
}
static void NQD_LerpPlayerinfo (float f)
{
if (cl.intermission) {
// just stay there
return;
}
if (nq_player_teleported) {
VectorCopy (nq_mvelocity[0], cl.simvel);
VectorCopy (nq_mviewangles[0], cl.viewangles);
VectorCopy (nq_mviewangles[0], cl.simangles);
return;
}
VectorInterpolate (nq_mvelocity[1], f, nq_mvelocity[0], cl.simvel);
AngleInterpolate (nq_mviewangles[1], f, nq_mviewangles[0], cl.simangles);
VectorCopy (cl.simangles, cl.viewangles);
}
static int NQD_FirstPersonCamera(void)
{
extern cvar_t cam_thirdperson, cl_camera_tpp;
return !cam_thirdperson.integer && !cl_camera_tpp.integer;
}
void NQD_LinkEntities (void)
{
entity_t ent;
centity_t* cent;
entity_state_t* state;
float f;
struct model_s* model;
int modelflags;
vec3_t cur_origin;
float autorotate;
int i, num;
customlight_t cst_lt = { 0 };
float flicker = (r_lightflicker.integer ? rand() & 31 : 0);
f = NQD_LerpPoint ();
NQD_LerpPlayerinfo (f);
autorotate = anglemod (100*cl.time);
memset (&ent, 0, sizeof(ent));
for (num = 1; num < nq_num_entities; num++)
{
cent = &cl_entities[num];
state = ¢->current;
if (cent->sequence != cl_entframecount)
continue; // not present in this frame
VectorCopy (state->origin, cur_origin);
if (state->effects & EF_BRIGHTFIELD) {
CL_EntityParticles(cur_origin);
}
// spawn light flashes, even ones coming from invisible objects
if (state->effects & EF_MUZZLEFLASH) {
vec3_t angles, forward;
dlight_t *dl;
dl = CL_AllocDlight (-num);
VectorCopy (state->angles, angles);
AngleVectors (angles, forward, NULL, NULL);
VectorMA (cur_origin, 18, forward, dl->origin);
dl->origin[2] += 16;
dl->radius = 200 + flicker;
dl->minlight = 32;
dl->die = cl.time + 0.1;
dl->type = lt_muzzleflash;
}
if (state->effects & EF_BRIGHTLIGHT) {
if (state->modelindex != cl_modelindices[mi_player] || r_powerupglow.integer) {
vec3_t tmp;
VectorCopy (cur_origin, tmp);
tmp[2] += 16;
CL_NewDlight(state->number, cur_origin, 400 + flicker, 0.1, lt_default, 0);
}
}
if (state->effects & EF_DIMLIGHT) {
if (state->modelindex != cl_modelindices[mi_player] || r_powerupglow.integer) {
CL_NewDlight(state->number, cur_origin, 200 + flicker, 0.1, lt_default, 0);
}
}
// if set to invisible, skip
if (!state->modelindex) {
continue;
}
cent->current = *state;
ent.model = model = cl.model_precache[state->modelindex];
if (!model) {
Host_Error("CL_LinkPacketEntities: bad modelindex");
}
if (cl_rocket2grenade.value && cl_modelindices[mi_grenade] != -1) {
if (state->modelindex == cl_modelindices[mi_rocket]) {
ent.model = cl.model_precache[cl_modelindices[mi_grenade]];
}
}
modelflags = R_ModelFlags (model);
// rotate binary objects locally
if (modelflags & EF_ROTATE) {
ent.angles[0] = 0;
ent.angles[1] = autorotate;
ent.angles[2] = 0;
}
else {
AngleInterpolate(cent->old_angles, f, cent->current.angles, ent.angles);
}
// calculate origin
for (i = 0; i < 3; i++) {
if (fabs(cent->current.origin[i] - cent->old_origin[i]) > 128.0f) {
// teleport or something, don't lerp
VectorCopy(cur_origin, ent.origin);
if (num == nq_viewentity) {
nq_player_teleported = true;