-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathsv_ents.c
784 lines (634 loc) · 19.1 KB
/
sv_ents.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
/*
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.
$Id: sv_ents.c 766 2008-02-28 13:57:25Z qqshka $
*/
#include "qwsvdef.h"
//=============================================================================
// because there can be a lot of nails, there is a special
// network protocol for them
#define MAX_NAILS 32
static edict_t *nails[MAX_NAILS];
static int numnails;
static int nailcount = 0;
extern int sv_nailmodel, sv_supernailmodel, sv_playermodel;
cvar_t sv_nailhack = {"sv_nailhack", "1"};
static qbool SV_AddNailUpdate (edict_t *ent)
{
if ((int)sv_nailhack.value)
return false;
if (ent->v.modelindex != sv_nailmodel && ent->v.modelindex != sv_supernailmodel)
return false;
if (msg_coordsize != 2)
return false; // Do not allow nailhack in case of sv_bigcoords.
if (numnails == MAX_NAILS)
return true;
nails[numnails] = ent;
numnails++;
return true;
}
static void SV_EmitNailUpdate (sizebuf_t *msg, qbool recorder)
{
int x, y, z, p, yaw, n, i;
byte bits[6]; // [48 bits] xyzpy 12 12 12 4 8
edict_t *ent;
if (!numnails)
return;
if (recorder)
MSG_WriteByte (msg, svc_nails2);
else
MSG_WriteByte (msg, svc_nails);
MSG_WriteByte (msg, numnails);
for (n=0 ; n<numnails ; n++)
{
ent = nails[n];
if (recorder)
{
if (!ent->v.colormap)
{
if (!((++nailcount)&255)) nailcount++;
ent->v.colormap = nailcount&255;
}
MSG_WriteByte (msg, (byte)ent->v.colormap);
}
x = ((int)(ent->v.origin[0] + 4096 + 1) >> 1) & 4095;
y = ((int)(ent->v.origin[1] + 4096 + 1) >> 1) & 4095;
z = ((int)(ent->v.origin[2] + 4096 + 1) >> 1) & 4095;
p = Q_rint(ent->v.angles[0]*(16.0/360.0)) & 15;
yaw = Q_rint(ent->v.angles[1]*(256.0/360.0)) & 255;
bits[0] = x;
bits[1] = (x>>8) | (y<<4);
bits[2] = (y>>4);
bits[3] = z;
bits[4] = (z>>8) | (p<<4);
bits[5] = yaw;
for (i=0 ; i<6 ; i++)
MSG_WriteByte (msg, bits[i]);
}
}
//=============================================================================
/*
==================
SV_WriteDelta
Writes part of a packetentities message.
Can delta from either a baseline or a previous packet_entity
==================
*/
static void SV_WriteDelta (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qbool force)
{
int bits, i;
// send an update
bits = 0;
for (i=0 ; i<3 ; i++)
if ( to->origin[i] != from->origin[i] )
bits |= U_ORIGIN1<<i;
if ( to->angles[0] != from->angles[0] )
bits |= U_ANGLE1;
if ( to->angles[1] != from->angles[1] )
bits |= U_ANGLE2;
if ( to->angles[2] != from->angles[2] )
bits |= U_ANGLE3;
if ( to->colormap != from->colormap )
bits |= U_COLORMAP;
if ( to->skinnum != from->skinnum )
bits |= U_SKIN;
if ( to->frame != from->frame )
bits |= U_FRAME;
if ( to->effects != from->effects )
bits |= U_EFFECTS;
if ( to->modelindex != from->modelindex )
bits |= U_MODEL;
if (bits & U_CHECKMOREBITS)
bits |= U_MOREBITS;
if (to->flags & U_SOLID)
bits |= U_SOLID;
//
// write the message
//
if (!to->number)
SV_Error ("Unset entity number");
if (to->number >= MAX_EDICTS)
{
/*SV_Error*/
Con_Printf ("Entity number >= MAX_EDICTS (%d), set to MAX_EDICTS - 1\n", MAX_EDICTS);
to->number = MAX_EDICTS - 1;
}
if (!bits && !force)
return; // nothing to send!
i = to->number | (bits&~U_CHECKMOREBITS);
if (i & U_REMOVE)
Sys_Error ("U_REMOVE");
MSG_WriteShort (msg, i);
if (bits & U_MOREBITS)
MSG_WriteByte (msg, bits&255);
if (bits & U_MODEL)
MSG_WriteByte (msg, to->modelindex);
if (bits & U_FRAME)
MSG_WriteByte (msg, to->frame);
if (bits & U_COLORMAP)
MSG_WriteByte (msg, to->colormap);
if (bits & U_SKIN)
MSG_WriteByte (msg, to->skinnum);
if (bits & U_EFFECTS)
MSG_WriteByte (msg, to->effects);
if (bits & U_ORIGIN1)
MSG_WriteCoord (msg, to->origin[0]);
if (bits & U_ANGLE1)
MSG_WriteAngle(msg, to->angles[0]);
if (bits & U_ORIGIN2)
MSG_WriteCoord (msg, to->origin[1]);
if (bits & U_ANGLE2)
MSG_WriteAngle(msg, to->angles[1]);
if (bits & U_ORIGIN3)
MSG_WriteCoord (msg, to->origin[2]);
if (bits & U_ANGLE3)
MSG_WriteAngle(msg, to->angles[2]);
}
/*
=============
SV_EmitPacketEntities
Writes a delta update of a packet_entities_t to the message.
=============
*/
static void SV_EmitPacketEntities (client_t *client, packet_entities_t *to, sizebuf_t *msg)
{
int oldindex, newindex, oldnum, newnum, oldmax;
client_frame_t *fromframe;
packet_entities_t *from1;
edict_t *ent;
// this is the frame that we are going to delta update from
if (client->delta_sequence != -1)
{
fromframe = &client->frames[client->delta_sequence & UPDATE_MASK];
from1 = &fromframe->entities;
oldmax = from1->num_entities;
MSG_WriteByte (msg, svc_deltapacketentities);
MSG_WriteByte (msg, client->delta_sequence);
}
else
{
oldmax = 0; // no delta update
from1 = NULL;
MSG_WriteByte (msg, svc_packetentities);
}
newindex = 0;
oldindex = 0;
//Con_Printf ("---%i to %i ----\n", client->delta_sequence & UPDATE_MASK
// , client->netchan.outgoing_sequence & UPDATE_MASK);
while (newindex < to->num_entities || oldindex < oldmax)
{
newnum = newindex >= to->num_entities ? 9999 : to->entities[newindex].number;
oldnum = oldindex >= oldmax ? 9999 : from1->entities[oldindex].number;
if (newnum == oldnum)
{ // delta update from old position
//Con_Printf ("delta %i\n", newnum);
SV_WriteDelta (&from1->entities[oldindex], &to->entities[newindex], msg, false);
oldindex++;
newindex++;
continue;
}
if (newnum < oldnum)
{ // this is a new entity, send it from the baseline
if (newnum == 9999)
{
Sys_Printf("LOL, %d, %d, %d, %d %d %d\n", // nice message
newnum, oldnum, to->num_entities, oldmax,
client->netchan.incoming_sequence & UPDATE_MASK,
client->delta_sequence & UPDATE_MASK);
if (client->edict == NULL)
Sys_Printf("demo\n");
}
ent = EDICT_NUM(newnum);
//Con_Printf ("baseline %i\n", newnum);
SV_WriteDelta (&ent->e->baseline, &to->entities[newindex], msg, true);
newindex++;
continue;
}
if (newnum > oldnum)
{ // the old entity isn't present in the new message
//Con_Printf ("remove %i\n", oldnum);
MSG_WriteShort (msg, oldnum | U_REMOVE);
oldindex++;
continue;
}
}
MSG_WriteShort (msg, 0); // end of packetentities
}
static int TranslateEffects (edict_t *ent)
{
int fx = (int)ent->v.effects;
if (pr_nqprogs)
fx &= ~EF_MUZZLEFLASH;
if (pr_nqprogs && (fx & EF_DIMLIGHT)) {
if ((int)ent->v.items & IT_QUAD)
fx |= EF_BLUE;
if ((int)ent->v.items & IT_INVULNERABILITY)
fx |= EF_RED;
}
return fx;
}
/*
=============
SV_WritePlayersToClient
=============
*/
#define TruePointContents(p) CM_HullPointContents(&sv.worldmodel->hulls[0], 0, p)
#define ISUNDERWATER(x) ((x) == CONTENTS_WATER || (x) == CONTENTS_SLIME || (x) == CONTENTS_LAVA)
static qbool disable_updates; // disables sending entities to the client
int SV_PMTypeForClient (client_t *cl);
static void SV_WritePlayersToClient (client_t *client, edict_t *clent, byte *pvs, sizebuf_t *msg)
{
int msec, pflags, pm_type = 0, pm_code = 0, i, j;
demo_frame_t *demo_frame;
demo_client_t *dcl;
usercmd_t cmd;
client_t *cl;
edict_t *ent;
int hideent;
if (clent && fofs_hideentity)
hideent = ((eval_t *)((byte *)&(clent)->v + fofs_hideentity))->_int / pr_edict_size;
else
hideent = 0;
demo_frame = &demo.frames[demo.parsecount&UPDATE_MASK];
for (j=0,cl=svs.clients, dcl = demo_frame->clients; j<MAX_CLIENTS ; j++,cl++, dcl++)
{
if (cl->state != cs_spawned)
continue;
ent = cl->edict;
if (clent == NULL)
{
if (cl->spectator)
continue;
dcl->parsecount = demo.parsecount;
VectorCopy(ent->v.origin, dcl->origin);
VectorCopy(ent->v.angles, dcl->angles);
dcl->angles[0] *= -3;
#ifdef USE_PR2
if( cl->isBot )
VectorCopy(ent->v.v_angle, dcl->angles);
#endif
dcl->angles[2] = 0; // no roll angle
if (ent->v.health <= 0)
{ // don't show the corpse looking around...
dcl->angles[0] = 0;
dcl->angles[1] = ent->v.angles[1];
dcl->angles[2] = 0;
}
dcl->weaponframe = ent->v.weaponframe;
dcl->frame = ent->v.frame;
dcl->skinnum = ent->v.skin;
dcl->model = ent->v.modelindex;
dcl->effects = TranslateEffects(ent);
dcl->flags = 0;
dcl->fixangle = demo.fixangle[j];
demo.fixangle[j] = 0;
dcl->cmdtime = cl->localtime;
dcl->sec = sv.time - cl->localtime;
if (ent->v.health <= 0)
dcl->flags |= DF_DEAD;
if (ent->v.mins[2] != -24)
dcl->flags |= DF_GIB;
continue;
}
// ZOID visibility tracking
if (ent != clent &&
!(client->spec_track && client->spec_track - 1 == j))
{
if (cl->spectator)
continue;
if (cl - svs.clients == hideent - 1)
continue;
// ignore if not touching a PV leaf
for (i=0 ; i < ent->e->num_leafs ; i++)
if (pvs[ent->e->leafnums[i] >> 3] & (1 << (ent->e->leafnums[i]&7) ))
break;
if (i == ent->e->num_leafs)
continue; // not visable
}
if (disable_updates && client != cl)
{ // Vladis
continue;
}
pflags = PF_MSEC | PF_COMMAND;
if (ent->v.modelindex != sv_playermodel)
pflags |= PF_MODEL;
for (i=0 ; i<3 ; i++)
if (ent->v.velocity[i])
pflags |= PF_VELOCITY1<<i;
if (ent->v.effects)
pflags |= PF_EFFECTS;
if (ent->v.skin)
pflags |= PF_SKINNUM;
if (ent->v.health <= 0)
pflags |= PF_DEAD;
if (ent->v.mins[2] != -24)
pflags |= PF_GIB;
if (cl->spectator)
{ // only sent origin and velocity to spectators
pflags &= PF_VELOCITY1 | PF_VELOCITY2 | PF_VELOCITY3;
}
else if (ent == clent)
{ // don't send a lot of data on personal entity
pflags &= ~(PF_MSEC|PF_COMMAND);
if (ent->v.weaponframe)
pflags |= PF_WEAPONFRAME;
}
// Z_EXT_PM_TYPE protocol extension
// encode pm_type and jump_held into pm_code
pm_type = SV_PMTypeForClient (cl);
switch (pm_type)
{
case PM_DEAD:
pm_code = PMC_NORMAL; // plus PF_DEAD
break;
case PM_NORMAL:
pm_code = PMC_NORMAL;
if (cl->jump_held)
pm_code = PMC_NORMAL_JUMP_HELD;
break;
case PM_OLD_SPECTATOR:
pm_code = PMC_OLD_SPECTATOR;
break;
case PM_SPECTATOR:
pm_code = PMC_SPECTATOR;
break;
case PM_FLY:
pm_code = PMC_FLY;
break;
case PM_NONE:
pm_code = PMC_NONE;
break;
case PM_LOCK:
pm_code = PMC_LOCK;
break;
default:
assert (false);
}
pflags |= pm_code << PF_PMC_SHIFT;
// Z_EXT_PF_ONGROUND protocol extension
if ((int)ent->v.flags & FL_ONGROUND)
pflags |= PF_ONGROUND;
// Z_EXT_PF_SOLID protocol extension
if (ent->v.solid == SOLID_BBOX || ent->v.solid == SOLID_SLIDEBOX)
pflags |= PF_SOLID;
if (pm_type == PM_LOCK && ent == clent)
pflags |= PF_COMMAND; // send forced view angles
if (client->spec_track && client->spec_track - 1 == j &&
ent->v.weaponframe)
pflags |= PF_WEAPONFRAME;
MSG_WriteByte (msg, svc_playerinfo);
MSG_WriteByte (msg, j);
MSG_WriteShort (msg, pflags);
for (i=0 ; i<3 ; i++)
MSG_WriteCoord (msg, ent->v.origin[i]);
MSG_WriteByte (msg, ent->v.frame);
if (pflags & PF_MSEC)
{
msec = 1000*(sv.time - cl->localtime);
if (msec > 255)
msec = 255;
MSG_WriteByte (msg, msec);
}
if (pflags & PF_COMMAND)
{
cmd = cl->lastcmd;
if (ent->v.health <= 0)
{ // don't show the corpse looking around...
cmd.angles[0] = 0;
cmd.angles[1] = ent->v.angles[1];
cmd.angles[0] = 0;
}
cmd.buttons = 0; // never send buttons
cmd.impulse = 0; // never send impulses
if (ent == clent) {
// this is PM_LOCK, we only want to send view angles
VectorCopy(ent->v.v_angle, cmd.angles);
cmd.forwardmove = 0;
cmd.sidemove = 0;
cmd.upmove = 0;
}
if ((client->extensions & Z_EXT_VWEP) && sv.vw_model_name[0]
&& fofs_vw_index && ent != clent) {
cmd.impulse = EdictFieldFloat (ent, fofs_vw_index);
}
MSG_WriteDeltaUsercmd (msg, &nullcmd, &cmd);
}
for (i=0 ; i<3 ; i++)
if (pflags & (PF_VELOCITY1<<i) )
MSG_WriteShort (msg, ent->v.velocity[i]);
if (pflags & PF_MODEL)
MSG_WriteByte (msg, ent->v.modelindex);
if (pflags & PF_SKINNUM)
MSG_WriteByte (msg, ent->v.skin);
if (pflags & PF_EFFECTS)
MSG_WriteByte (msg, TranslateEffects(ent));
if (pflags & PF_WEAPONFRAME)
MSG_WriteByte (msg, ent->v.weaponframe);
}
}
#define offsetrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN))
extern cvar_t sv_cullentities;
extern trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);
qbool SV_InvisibleToClient(edict_t *viewer, edict_t *seen)
{
int i;
trace_t tr;
vec3_t start;
vec3_t end;
qbool player;
if (seen->v.movetype == MOVETYPE_PUSH ) //dont cull doors and plats :(
return false;
i = NUM_FOR_EDICT(seen);
player = (i >= 1 && i <= MAX_CLIENTS);
//1 = only check player models, 2 = check all ents
if (sv_cullentities.value == 1 && !player)
return false;
memset (&tr, 0, sizeof(tr));
tr.fraction = 1;
start[0] = viewer->v.origin[0];
start[1] = viewer->v.origin[1];
start[2] = viewer->v.origin[2] + viewer->v.view_ofs[2];
//aim straight at the center of "seen" from our eyes
end[0] = 0.5 * (seen->v.mins[0] + seen->v.maxs[0]);
end[1] = 0.5 * (seen->v.mins[1] + seen->v.maxs[1]);
end[2] = 0.5 * (seen->v.mins[2] + seen->v.maxs[2]);
tr = SV_ClipMoveToEntity (sv.edicts, start, vec3_origin, vec3_origin, end);
if (tr.fraction == 1)// line hit the ent
return false;
//last attempt to eliminate any flaws...
if (player || sv_cullentities.value != 1)
{
for (i = 0; i < 64; i++)
{
end[0] = seen->v.origin[0] + offsetrandom(seen->v.mins[0], seen->v.maxs[0]);
end[1] = seen->v.origin[1] + offsetrandom(seen->v.mins[1], seen->v.maxs[1]);
end[2] = seen->v.origin[2] + offsetrandom(seen->v.mins[2], seen->v.maxs[2]);
tr = SV_ClipMoveToEntity (sv.edicts, start, vec3_origin, vec3_origin, end);
if (tr.fraction == 1)// line hit the ent
{
// Com_DPrintf (va("found ent in %i hits\n", i));
return false;
}
}
}
return true;
}
/*
=============
SV_WriteEntitiesToClient
Encodes the current state of the world as
a svc_packetentities messages and possibly
a svc_nails message and
svc_playerinfo messages
=============
*/
void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg, qbool recorder)
{
int e, i, max_packet_entities;
packet_entities_t *pack;
client_frame_t *frame;
entity_state_t *state;
edict_t *clent;
client_t *cl;
edict_t *ent;
vec3_t org;
byte *pvs;
int hideent;
// this is the frame we are creating
frame = &client->frames[client->netchan.incoming_sequence & UPDATE_MASK];
// find the client's PVS
clent = client->edict;
pvs = NULL;
if (!recorder)
{
VectorAdd (clent->v.origin, clent->v.view_ofs, org);
pvs = CM_FatPVS (org);
if (client->fteprotocolextensions & FTE_PEXT_256PACKETENTITIES)
max_packet_entities = 256;
else
max_packet_entities = MAX_PACKET_ENTITIES;
}
else
{
max_packet_entities = MAX_MVD_PACKET_ENTITIES;
for (i=0, cl=svs.clients ; i<MAX_CLIENTS ; i++,cl++)
{
if (cl->state != cs_spawned)
continue;
if (cl->spectator)
continue;
VectorAdd (cl->edict->v.origin, cl->edict->v.view_ofs, org);
// disconnect --> "is it correct?"
//if (pvs == NULL)
pvs = CM_FatPVS (org);
//else
// SV_AddToFatPVS (org, sv.worldmodel->nodes, false);
// <-- disconnect
}
}
if (clent && client->disable_updates_stop > realtime)
{ // Vladis
int where = TruePointContents(clent->v.origin); // server flash should not work underwater
disable_updates = !ISUNDERWATER(where);
}
else
{
disable_updates = false;
}
// send over the players in the PVS
SV_WritePlayersToClient (client, clent, pvs, msg);
// put other visible entities into either a packet_entities or a nails message
pack = &frame->entities;
pack->num_entities = 0;
numnails = 0;
if (fofs_hideentity)
hideent = ((eval_t *)((byte *)&(clent)->v + fofs_hideentity))->_int / pr_edict_size;
else
hideent = 0;
if (!disable_updates)
{// Vladis, server flash
// QW protocol can only handle 512 entities. Any entity with number >= 512 will be invisible
// From ZQuake.
// max_edicts = min(sv.num_edicts, MAX_EDICTS);
for (e = pr_nqprogs ? 1 : MAX_CLIENTS+1, ent=EDICT_NUM(e);
e < sv.num_edicts/*max_edicts*/;
e++, ent = NEXT_EDICT(ent))
{
if (pr_nqprogs) {
// don't send the player's model to himself
if (e < MAX_CLIENTS + 1 && svs.clients[e-1].state != cs_free)
continue;
}
// ignore ents without visible models
if (!ent->v.modelindex || !*
#ifdef USE_PR2
PR2_GetString(ent->v.model)
#else
PR_GetString(ent->v.model)
#endif
)
continue;
if (e == hideent)
continue;
if (!(int)sv_demoNoVis.value || !recorder)
{
// ignore if not touching a PV leaf
for (i=0 ; i < ent->e->num_leafs ; i++)
if (pvs[ent->e->leafnums[i] >> 3] & (1 << (ent->e->leafnums[i]&7) ))
break;
if (i == ent->e->num_leafs)
continue; // not visible
if (sv_cullentities.value && SV_InvisibleToClient(clent, ent))
continue;
}
if (SV_AddNailUpdate (ent))
continue; // added to the special update list
// add to the packetentities
if (pack->num_entities == max_packet_entities)
continue; // all full
state = &pack->entities[pack->num_entities];
pack->num_entities++;
state->number = e;
state->flags = 0;
VectorCopy (ent->v.origin, state->origin);
VectorCopy (ent->v.angles, state->angles);
state->modelindex = ent->v.modelindex;
state->frame = ent->v.frame;
state->colormap = ent->v.colormap;
state->skinnum = ent->v.skin;
state->effects = TranslateEffects(ent);
}
} // server flash
// encode the packet entities as a delta from the
// last packetentities acknowledged by the client
SV_EmitPacketEntities (client, pack, msg);
// now add the specialized nail update
SV_EmitNailUpdate (msg, recorder);
// Translate NQ progs' EF_MUZZLEFLASH to svc_muzzleflash
if (pr_nqprogs)
for (e=1, ent=EDICT_NUM(e) ; e < sv.num_edicts ; e++, ent = NEXT_EDICT(ent))
{
// ignore ents without visible models
if (!ent->v.modelindex || !*PR_GetString(ent->v.model))
continue;
// ignore if not touching a PV leaf
for (i=0 ; i < ent->e->num_leafs ; i++)
if (pvs[ent->e->leafnums[i] >> 3] & (1 << (ent->e->leafnums[i]&7) ))
break;
if ((int)ent->v.effects & EF_MUZZLEFLASH) {
ent->v.effects = (int)ent->v.effects & ~EF_MUZZLEFLASH;
MSG_WriteByte (msg, svc_muzzleflash);
MSG_WriteShort (msg, e);
}
}
}