2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
sv_ents.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-04 02:29:03 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
2021-07-26 02:15:51 +00:00
|
|
|
#include "QF/set.h"
|
2001-08-28 02:43:24 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2004-02-21 05:09:02 +00:00
|
|
|
#include "qw/msg_ucmd.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "qw/include/server.h"
|
|
|
|
#include "qw/include/sv_progs.h"
|
2001-08-28 02:43:24 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
The PVS must include a small area around the client to allow head
|
|
|
|
bobbing or other small motion on the client side. Otherwise, a bob
|
|
|
|
might cause an entity that should be visible to not show up, especially
|
|
|
|
when the bob crosses a waterline.
|
|
|
|
*/
|
|
|
|
|
2021-07-26 02:15:51 +00:00
|
|
|
static set_t *fatpvs;
|
2001-08-28 02:43:24 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_AddToFatPVS (vec3_t org, mnode_t *node)
|
|
|
|
{
|
2021-07-26 02:15:51 +00:00
|
|
|
float d;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *plane;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// if this is a leaf, accumulate the pvs bits
|
|
|
|
if (node->contents < 0) {
|
|
|
|
if (node->contents != CONTENTS_SOLID) {
|
2021-07-26 02:15:51 +00:00
|
|
|
set_union (fatpvs, Mod_LeafPVS ((mleaf_t *) node,
|
|
|
|
sv.worldmodel));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
plane = node->plane;
|
|
|
|
d = DotProduct (org, plane->normal) - plane->dist;
|
|
|
|
if (d > 8)
|
|
|
|
node = node->children[0];
|
|
|
|
else if (d < -8)
|
|
|
|
node = node->children[1];
|
|
|
|
else { // go down both
|
|
|
|
SV_AddToFatPVS (org, node->children[0]);
|
|
|
|
node = node->children[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_FatPVS
|
|
|
|
|
|
|
|
Calculates a PVS that is the inclusive or of all leafs within 8 pixels
|
|
|
|
of the given point.
|
|
|
|
*/
|
2021-07-26 02:15:51 +00:00
|
|
|
static set_t *
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_FatPVS (vec3_t org)
|
|
|
|
{
|
2021-07-26 02:15:51 +00:00
|
|
|
if (!fatpvs) {
|
2021-07-27 03:32:40 +00:00
|
|
|
fatpvs = set_new_size (sv.worldmodel->brush.visleafs);
|
2021-07-26 02:15:51 +00:00
|
|
|
}
|
2021-07-27 03:32:40 +00:00
|
|
|
set_expand (fatpvs, sv.worldmodel->brush.visleafs);
|
2021-07-26 02:15:51 +00:00
|
|
|
set_empty (fatpvs);
|
2021-02-01 10:31:11 +00:00
|
|
|
SV_AddToFatPVS (org, sv.worldmodel->brush.nodes);
|
2001-02-19 21:15:25 +00:00
|
|
|
return fatpvs;
|
|
|
|
}
|
|
|
|
|
2001-08-28 02:43:24 +00:00
|
|
|
// nails are plentiful, so there is a special network protocol for them
|
2001-02-19 21:15:25 +00:00
|
|
|
#define MAX_NAILS 32
|
2002-06-28 02:11:13 +00:00
|
|
|
edict_t *nails[MAX_NAILS];
|
|
|
|
int numnails;
|
2002-10-04 02:29:03 +00:00
|
|
|
int nailcount;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static qboolean
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_AddNailUpdate (edict_t *ent)
|
|
|
|
{
|
2001-08-08 20:28:53 +00:00
|
|
|
if (SVfloat (ent, modelindex) != sv_nailmodel
|
2002-06-28 02:11:13 +00:00
|
|
|
&& SVfloat (ent, modelindex) != sv_supernailmodel)
|
|
|
|
return false;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (numnails == MAX_NAILS)
|
|
|
|
return true;
|
|
|
|
nails[numnails] = ent;
|
|
|
|
numnails++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-10-04 02:29:03 +00:00
|
|
|
SV_EmitNailUpdate (sizebuf_t *msg, qboolean recorder)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2012-05-21 23:23:22 +00:00
|
|
|
byte *buf; // [48 bits] xyzpy 12 12 12 4 8
|
2002-06-29 18:28:32 +00:00
|
|
|
int n, p, x, y, z, yaw;
|
2002-10-06 04:30:50 +00:00
|
|
|
int bpn = recorder ? 7 : 6; // bytes per nail
|
2002-06-28 02:11:13 +00:00
|
|
|
edict_t *ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!numnails)
|
|
|
|
return;
|
|
|
|
|
2002-10-06 04:30:50 +00:00
|
|
|
buf = SZ_GetSpace (msg, numnails * bpn + 2);
|
2002-10-04 02:29:03 +00:00
|
|
|
*buf++ = recorder ? svc_nails2 : svc_nails;
|
2002-06-29 18:28:32 +00:00
|
|
|
*buf++ = numnails;
|
2001-11-07 08:24:56 +00:00
|
|
|
|
|
|
|
for (n = 0; n < numnails; n++) {
|
|
|
|
ent = nails[n];
|
2002-10-04 02:29:03 +00:00
|
|
|
if (recorder) {
|
|
|
|
if (!SVfloat (ent, colormap)) {
|
|
|
|
if (!((++nailcount) & 255))
|
|
|
|
nailcount++;
|
|
|
|
SVfloat (ent, colormap) = nailcount&255;
|
|
|
|
}
|
|
|
|
*buf++ = (byte)SVfloat (ent, colormap);
|
|
|
|
}
|
|
|
|
|
2005-04-30 03:59:23 +00:00
|
|
|
x = ((int) (SVvector (ent, origin)[0] + 4096 + 1) >> 1) & 0xfff;
|
|
|
|
y = ((int) (SVvector (ent, origin)[1] + 4096 + 1) >> 1) & 0xfff;
|
|
|
|
z = ((int) (SVvector (ent, origin)[2] + 4096 + 1) >> 1) & 0xfff;
|
|
|
|
p = (int) (SVvector (ent, angles)[0] * (16.0 / 360.0)) & 0x00f;
|
|
|
|
yaw = (int) (SVvector (ent, angles)[1] * (256.0 / 360.0)) & 0x0ff;
|
2001-11-07 08:24:56 +00:00
|
|
|
|
2002-06-29 18:28:32 +00:00
|
|
|
*buf++ = x;
|
|
|
|
*buf++ = (x >> 8) | (y << 4);
|
|
|
|
*buf++ = (y >> 4);
|
|
|
|
*buf++ = z;
|
|
|
|
*buf++ = (z >> 8) | (p << 4);
|
|
|
|
*buf++ = yaw;
|
2001-11-07 08:24:56 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
/*
|
|
|
|
SV_WriteDelta
|
|
|
|
|
|
|
|
Writes part of a packetentities message.
|
|
|
|
Can delta from either a baseline or a previous packet_entity
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-11-07 08:24:56 +00:00
|
|
|
SV_WriteDelta (entity_state_t *from, entity_state_t *to, sizebuf_t *msg,
|
|
|
|
qboolean force, int stdver)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-06-28 02:11:13 +00:00
|
|
|
int bits, i;
|
|
|
|
float miss;
|
2001-11-07 08:24:56 +00:00
|
|
|
|
|
|
|
// send an update
|
|
|
|
bits = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
miss = to->origin[i] - from->origin[i];
|
|
|
|
if (miss < -0.1 || miss > 0.1)
|
|
|
|
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;
|
|
|
|
|
2005-04-30 03:59:23 +00:00
|
|
|
if ((to->effects & 0xff) != (from->effects & 0xff))
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= U_EFFECTS;
|
|
|
|
|
|
|
|
if (to->modelindex != from->modelindex)
|
|
|
|
bits |= U_MODEL;
|
|
|
|
|
|
|
|
// LordHavoc: cleaned up Endy's coding style, and added missing effects
|
|
|
|
// Ender (QSG - Begin)
|
2001-11-07 08:24:56 +00:00
|
|
|
if (stdver > 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (to->alpha != from->alpha)
|
|
|
|
bits |= U_ALPHA;
|
|
|
|
|
|
|
|
if (to->scale != from->scale)
|
|
|
|
bits |= U_SCALE;
|
|
|
|
|
2005-04-30 03:59:23 +00:00
|
|
|
if ((to->effects & 0xff00) != (from->effects & 0xff00))
|
2002-06-19 02:55:57 +00:00
|
|
|
bits |= U_EFFECTS2;
|
|
|
|
|
2001-03-27 03:57:17 +00:00
|
|
|
if (to->glow_size != from->glow_size)
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= U_GLOWSIZE;
|
|
|
|
|
2001-03-27 03:57:17 +00:00
|
|
|
if (to->glow_color != from->glow_color)
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= U_GLOWCOLOR;
|
|
|
|
|
|
|
|
if (to->colormod != from->colormod)
|
|
|
|
bits |= U_COLORMOD;
|
2002-06-19 02:55:57 +00:00
|
|
|
|
|
|
|
if (to->frame > 255)
|
|
|
|
bits |= U_EFFECTS2;
|
2001-11-07 08:24:56 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
if (bits >= 16777216)
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= U_EXTEND2;
|
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
if (bits >= 65536)
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= U_EXTEND1;
|
|
|
|
// Ender (QSG - End)
|
2001-11-07 08:24:56 +00:00
|
|
|
if (bits & 511)
|
2001-02-19 21:15:25 +00:00
|
|
|
bits |= U_MOREBITS;
|
|
|
|
|
|
|
|
if (to->flags & U_SOLID)
|
|
|
|
bits |= U_SOLID;
|
|
|
|
|
|
|
|
// write the message
|
|
|
|
if (!to->number)
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("Unset entity number");
|
2001-02-19 21:15:25 +00:00
|
|
|
if (to->number >= 512)
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_Error ("Entity number >= 512");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!bits && !force)
|
|
|
|
return; // nothing to send!
|
2001-11-07 08:24:56 +00:00
|
|
|
i = to->number | (bits & ~511);
|
|
|
|
if (i & U_REMOVE)
|
|
|
|
Sys_Error ("U_REMOVE");
|
|
|
|
MSG_WriteShort (msg, i);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (bits & U_MOREBITS)
|
|
|
|
MSG_WriteByte (msg, bits & 255);
|
|
|
|
|
|
|
|
// LordHavoc: cleaned up Endy's tabs
|
|
|
|
// Ender (QSG - Begin)
|
|
|
|
if (bits & U_EXTEND1)
|
|
|
|
MSG_WriteByte (msg, bits >> 16);
|
|
|
|
if (bits & U_EXTEND2)
|
|
|
|
MSG_WriteByte (msg, bits >> 24);
|
|
|
|
// Ender (QSG - End)
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
// LordHavoc: cleaned up Endy's tabs, rearranged bytes, and implemented
|
|
|
|
// missing effects
|
|
|
|
// Ender (QSG - Begin)
|
|
|
|
if (bits & U_ALPHA)
|
|
|
|
MSG_WriteByte (msg, to->alpha);
|
|
|
|
if (bits & U_SCALE)
|
|
|
|
MSG_WriteByte (msg, to->scale);
|
|
|
|
if (bits & U_EFFECTS2)
|
|
|
|
MSG_WriteByte (msg, (to->effects >> 8));
|
|
|
|
if (bits & U_GLOWSIZE)
|
2001-03-27 03:57:17 +00:00
|
|
|
MSG_WriteByte (msg, to->glow_size);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (bits & U_GLOWCOLOR)
|
2001-03-27 03:57:17 +00:00
|
|
|
MSG_WriteByte (msg, to->glow_color);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (bits & U_COLORMOD)
|
|
|
|
MSG_WriteByte (msg, to->colormod);
|
|
|
|
if (bits & U_FRAME2)
|
|
|
|
MSG_WriteByte (msg, (to->frame >> 8));
|
|
|
|
// Ender (QSG - End)
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
SV_EmitPacketEntities
|
|
|
|
|
2001-11-04 21:23:22 +00:00
|
|
|
Writes a delta update of a packet_entities_t to the message.
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2005-04-30 08:45:17 +00:00
|
|
|
SV_EmitPacketEntities (delta_t *delta, packet_entities_t *to, sizebuf_t *msg,
|
|
|
|
int stdver)
|
2001-11-04 21:23:22 +00:00
|
|
|
{
|
2002-06-28 02:11:13 +00:00
|
|
|
int newindex, oldindex, newnum, oldnum, oldmax;
|
|
|
|
edict_t *ent;
|
2001-11-07 08:24:56 +00:00
|
|
|
client_frame_t *fromframe;
|
2001-02-19 21:15:25 +00:00
|
|
|
packet_entities_t *from;
|
|
|
|
|
|
|
|
// this is the frame that we are going to delta update from
|
2005-04-30 08:45:17 +00:00
|
|
|
if (delta->delta_sequence != -1) {
|
2005-05-07 00:48:19 +00:00
|
|
|
fromframe = &delta->frames[delta->delta_sequence & UPDATE_MASK];
|
2001-11-07 08:24:56 +00:00
|
|
|
from = &fromframe->entities;
|
|
|
|
oldmax = from->num_entities;
|
|
|
|
|
|
|
|
MSG_WriteByte (msg, svc_deltapacketentities);
|
2005-04-30 08:45:17 +00:00
|
|
|
MSG_WriteByte (msg, delta->delta_sequence);
|
2001-11-07 08:24:56 +00:00
|
|
|
} else {
|
|
|
|
oldmax = 0; // no delta update
|
|
|
|
from = NULL;
|
|
|
|
|
|
|
|
MSG_WriteByte (msg, svc_packetentities);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
newindex = 0;
|
|
|
|
oldindex = 0;
|
2005-04-30 08:45:17 +00:00
|
|
|
// SV_Printf ("---%i to %i ----\n", delta->delta_sequence & UPDATE_MASK,
|
|
|
|
// delta->netchan.outgoing_sequence & UPDATE_MASK);
|
2001-11-07 08:24:56 +00:00
|
|
|
while (newindex < to->num_entities || oldindex < oldmax) {
|
2002-06-28 02:11:13 +00:00
|
|
|
newnum = newindex >= to->num_entities ? 9999 :
|
2001-11-07 08:24:56 +00:00
|
|
|
to->entities[newindex].number;
|
|
|
|
oldnum = oldindex >= oldmax ? 9999 : from->entities[oldindex].number;
|
2001-11-04 21:23:22 +00:00
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
if (newnum == oldnum) { // delta update from old position
|
|
|
|
// SV_Printf ("delta %i\n", newnum);
|
|
|
|
SV_WriteDelta (&from->entities[oldindex], &to->entities[newindex],
|
2005-04-30 08:45:17 +00:00
|
|
|
msg, false, stdver);
|
2001-02-19 21:15:25 +00:00
|
|
|
oldindex++;
|
|
|
|
newindex++;
|
2001-11-07 08:24:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-10-04 02:29:03 +00:00
|
|
|
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", newnum, oldnum,
|
|
|
|
to->num_entities, oldmax,
|
2005-04-30 08:45:17 +00:00
|
|
|
delta->in_frame,
|
2005-05-07 00:48:19 +00:00
|
|
|
delta->delta_sequence & UPDATE_MASK);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (!delta->client)
|
2003-03-21 21:25:44 +00:00
|
|
|
Sys_Printf ("demo\n");
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
2001-11-07 08:24:56 +00:00
|
|
|
ent = EDICT_NUM (&sv_pr_state, newnum);
|
|
|
|
// SV_Printf ("baseline %i\n", newnum);
|
2010-12-09 05:27:36 +00:00
|
|
|
SV_WriteDelta (&SVdata (ent)->state, &to->entities[newindex], msg,
|
|
|
|
true, stdver);
|
2001-11-04 21:23:22 +00:00
|
|
|
newindex++;
|
2001-11-07 08:24:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newnum > oldnum) { // the old entity isn't present in
|
|
|
|
// the new message
|
2001-08-28 02:43:24 +00:00
|
|
|
// SV_Printf ("remove %i\n", oldnum);
|
2001-11-07 08:24:56 +00:00
|
|
|
MSG_WriteShort (msg, oldnum | U_REMOVE);
|
2001-02-19 21:15:25 +00:00
|
|
|
oldindex++;
|
2001-11-07 08:24:56 +00:00
|
|
|
continue;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-07 08:24:56 +00:00
|
|
|
MSG_WriteShort (msg, 0); // end of packetentities
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2005-04-30 04:37:01 +00:00
|
|
|
static void
|
2005-05-09 12:12:48 +00:00
|
|
|
write_demoplayer (delta_t *delta, plent_state_t *from, plent_state_t *to,
|
|
|
|
sizebuf_t *msg, int mask, int full)
|
2005-04-30 04:37:01 +00:00
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int j;
|
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
flags = to->es.flags >> 1; // convert PF_(GIB|DEAD) to DF_(GIB|DEAD)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags &= DF_GIB | DF_DEAD; // PF_MSEC and PF_COMMAND aren't wanted
|
|
|
|
if (full) {
|
|
|
|
flags |= DF_ORIGIN | (DF_ORIGIN << 1) | (DF_ORIGIN << 2)
|
|
|
|
| DF_ANGLES | (DF_ANGLES << 1) | (DF_ANGLES << 2)
|
|
|
|
| DF_EFFECTS | DF_SKINNUM | DF_WEAPONFRAME | DF_MODEL;
|
|
|
|
} else {
|
|
|
|
for (j = 0; j < 3; j++)
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.origin[j] != to->es.origin[j])
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= DF_ORIGIN << j;
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
if (from->cmd.angles[j] != to->cmd.angles[j])
|
|
|
|
flags |= DF_ANGLES << j;
|
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.modelindex != to->es.modelindex)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= DF_MODEL;
|
2021-03-11 05:27:36 +00:00
|
|
|
if ((from->es.effects & 0xff) != (to->es.effects & 0xff))
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= DF_EFFECTS;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.skinnum != to->es.skinnum)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= DF_SKINNUM;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.weaponframe != to->es.weaponframe)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= DF_WEAPONFRAME;
|
|
|
|
}
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
MSG_WriteByte (msg, svc_playerinfo);
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.number);
|
2005-04-30 04:37:01 +00:00
|
|
|
MSG_WriteShort (msg, flags);
|
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.frame);
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
if (flags & (DF_ORIGIN << j))
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteCoord (msg, to->es.origin[j]);
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
if (flags & (DF_ANGLES << j))
|
2005-04-30 08:45:17 +00:00
|
|
|
MSG_WriteAngle16 (msg, to->cmd.angles[j]);
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
if (flags & DF_MODEL)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.modelindex);
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
if (flags & DF_SKINNUM)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.skinnum);
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
if (flags & DF_EFFECTS)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.effects);
|
2005-04-30 04:37:01 +00:00
|
|
|
|
|
|
|
if (flags & DF_WEAPONFRAME)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.weaponframe);
|
2005-04-30 08:45:17 +00:00
|
|
|
}
|
2005-04-30 04:37:01 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
static void
|
2005-05-09 12:12:48 +00:00
|
|
|
write_player (delta_t *delta, plent_state_t *from, plent_state_t *to,
|
|
|
|
sizebuf_t *msg, int mask, int full)
|
2005-04-30 08:45:17 +00:00
|
|
|
{
|
2021-03-11 05:27:36 +00:00
|
|
|
int flags = to->es.flags;
|
2005-04-30 08:45:17 +00:00
|
|
|
int qf_bits = 0;
|
|
|
|
int i;
|
2005-05-09 12:12:48 +00:00
|
|
|
int ds = delta->delta_sequence & 0x7f;
|
2005-04-30 08:45:17 +00:00
|
|
|
|
|
|
|
if (full) {
|
|
|
|
flags |= PF_VELOCITY1 | PF_VELOCITY2 | PF_VELOCITY3 | PF_MODEL
|
|
|
|
| PF_SKINNUM | PF_EFFECTS | PF_WEAPONFRAME;
|
|
|
|
if (full > 1) {
|
|
|
|
qf_bits = PF_ALPHA | PF_SCALE | PF_EFFECTS2 | PF_GLOWSIZE
|
|
|
|
| PF_GLOWCOLOR | PF_COLORMOD | PF_FRAME2;
|
|
|
|
flags |= PF_QF;
|
|
|
|
}
|
2005-05-09 12:12:48 +00:00
|
|
|
ds = -1;
|
2005-04-30 08:45:17 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < 3; i++)
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.velocity[i] != to->es.velocity[i])
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= PF_VELOCITY1 << i;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.modelindex != to->es.modelindex)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= PF_MODEL;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.skinnum != to->es.skinnum)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= PF_SKINNUM;
|
2021-03-11 05:27:36 +00:00
|
|
|
if ((from->es.effects & 0xff) != (to->es.effects &0xff))
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= PF_EFFECTS;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.weaponframe != to->es.weaponframe)
|
2005-04-30 08:45:17 +00:00
|
|
|
flags |= PF_WEAPONFRAME;
|
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.alpha != to->es.alpha)
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_ALPHA;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.scale != to->es.scale)
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_SCALE;
|
2021-03-11 05:27:36 +00:00
|
|
|
if ((from->es.effects & 0xff00) != (to->es.effects & 0xff00))
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_EFFECTS2;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.glow_size != to->es.glow_size)
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_GLOWSIZE;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.glow_color != to->es.glow_color)
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_GLOWCOLOR;
|
2021-03-11 05:27:36 +00:00
|
|
|
if (from->es.colormod != to->es.colormod)
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_COLORMOD;
|
2021-03-11 05:27:36 +00:00
|
|
|
if ((from->es.frame & 0xff00) != (to->es.frame & 0xff00))
|
2005-04-30 08:45:17 +00:00
|
|
|
qf_bits |= PF_FRAME2;
|
|
|
|
if (qf_bits)
|
|
|
|
flags |= PF_QF;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags &= mask;
|
|
|
|
|
|
|
|
MSG_WriteByte (msg, svc_playerinfo);
|
2005-05-09 12:12:48 +00:00
|
|
|
if (delta->type == dt_tp_qtv)
|
|
|
|
MSG_WriteByte (msg, ds);
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.number);
|
2005-04-30 08:45:17 +00:00
|
|
|
MSG_WriteShort (msg, flags);
|
|
|
|
|
2022-03-30 15:07:20 +00:00
|
|
|
MSG_WriteCoordV (msg, (vec_t*)&to->es.origin);//FIXME
|
2005-04-30 08:45:17 +00:00
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.frame);
|
2005-04-30 08:45:17 +00:00
|
|
|
|
|
|
|
if (flags & PF_MSEC)
|
|
|
|
MSG_WriteByte (msg, to->msec);
|
|
|
|
if (flags & PF_COMMAND)
|
|
|
|
MSG_WriteDeltaUsercmd (msg, &from->cmd, &to->cmd);
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
if (flags & (PF_VELOCITY1 << i))
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteShort (msg, to->es.velocity[i]);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (flags & PF_MODEL)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.modelindex);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (flags & PF_SKINNUM)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.skinnum);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (flags & PF_EFFECTS)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.effects);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (flags & PF_WEAPONFRAME)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.weaponframe);
|
2005-04-30 08:45:17 +00:00
|
|
|
|
|
|
|
if (flags & PF_QF) {
|
|
|
|
MSG_WriteByte (msg, qf_bits);
|
|
|
|
if (qf_bits & PF_ALPHA)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.alpha);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (qf_bits & PF_SCALE)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.scale);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (qf_bits & PF_EFFECTS2)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.effects >> 8);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (qf_bits & PF_GLOWSIZE)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.glow_size);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (qf_bits & PF_GLOWCOLOR)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.glow_color);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (qf_bits & PF_COLORMOD)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.colormod);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (qf_bits & PF_FRAME2)
|
2021-03-11 05:27:36 +00:00
|
|
|
MSG_WriteByte (msg, to->es.frame);
|
2005-04-30 08:45:17 +00:00
|
|
|
}
|
2005-04-30 04:37:01 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2021-07-26 02:15:51 +00:00
|
|
|
SV_WritePlayersToClient (delta_t *delta, set_t *pvs, sizebuf_t *msg)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2010-12-07 23:44:52 +00:00
|
|
|
int j, k;
|
2001-02-19 21:15:25 +00:00
|
|
|
client_t *cl;
|
2005-04-30 08:45:17 +00:00
|
|
|
edict_t *clent = 0;
|
|
|
|
int spec_track = 0;
|
|
|
|
int stdver = 2, full = stdver;
|
2002-06-28 02:11:13 +00:00
|
|
|
edict_t *ent;
|
2010-12-07 23:44:52 +00:00
|
|
|
edict_leaf_t *el;
|
2005-04-30 08:45:17 +00:00
|
|
|
packet_players_t *pack;
|
2005-05-05 11:46:29 +00:00
|
|
|
client_frame_t *frame = &delta->frames[delta->in_frame];
|
2005-04-30 08:45:17 +00:00
|
|
|
packet_players_t *from_pack = 0;
|
|
|
|
plent_state_t dummy_player_state, *state = &dummy_player_state;
|
|
|
|
static plent_state_t null_player_state;
|
2005-05-09 12:12:48 +00:00
|
|
|
void (*write) (delta_t *, plent_state_t *, plent_state_t *, sizebuf_t *,
|
|
|
|
int, int);
|
2005-04-30 08:45:17 +00:00
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
if (!null_player_state.es.alpha) {
|
|
|
|
null_player_state.es.alpha = 255;
|
|
|
|
null_player_state.es.scale = 16;
|
|
|
|
null_player_state.es.glow_size = 0;
|
|
|
|
null_player_state.es.glow_color = 254;
|
|
|
|
null_player_state.es.colormod = 255;
|
2005-04-30 08:45:17 +00:00
|
|
|
}
|
2021-03-11 05:27:36 +00:00
|
|
|
null_player_state.es.modelindex = 0;
|
2005-04-30 08:45:17 +00:00
|
|
|
|
|
|
|
if (delta->client) {
|
|
|
|
clent = delta->client->edict;
|
|
|
|
spec_track = delta->client->spec_track;
|
2021-03-11 05:27:36 +00:00
|
|
|
null_player_state.es.modelindex = sv_playermodel;
|
2005-04-30 08:45:17 +00:00
|
|
|
full = 0; // normal qw clients don't get real deltas on players
|
|
|
|
}
|
|
|
|
|
|
|
|
write = write_player;
|
2005-05-07 00:48:19 +00:00
|
|
|
if (!clent && delta->type == dt_tp_demo)
|
2005-04-30 08:45:17 +00:00
|
|
|
write = write_demoplayer;
|
2002-10-04 02:29:03 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
if (delta->delta_sequence != -1) {
|
2005-05-07 00:48:19 +00:00
|
|
|
client_frame_t *fromframe;
|
|
|
|
fromframe = &delta->frames[delta->delta_sequence & UPDATE_MASK];
|
2005-05-09 12:12:48 +00:00
|
|
|
from_pack = &fromframe->players;
|
2005-04-30 08:45:17 +00:00
|
|
|
full = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pack = &frame->players;
|
|
|
|
pack->num_players = 0;
|
2002-10-04 02:29:03 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
for (j = k = 0, cl = svs.clients; j < MAX_CLIENTS; j++, cl++) {
|
|
|
|
int mask = ~PF_WEAPONFRAME;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-08-18 06:26:09 +00:00
|
|
|
if (cl->state != cs_spawned && cl->state != cs_server)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ent = cl->edict;
|
|
|
|
|
|
|
|
// ZOID visibility tracking
|
2005-04-30 08:45:17 +00:00
|
|
|
// self or the the ent being tracked as a spectator always gets sent
|
|
|
|
if (ent != clent && !(spec_track && spec_track - 1 == j)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cl->spectator)
|
|
|
|
continue;
|
|
|
|
|
2004-03-07 00:25:09 +00:00
|
|
|
if (pvs) {
|
|
|
|
// ignore if not touching a PV leaf
|
2010-12-09 05:27:36 +00:00
|
|
|
for (el = SVdata (ent)->leafs; el; el = el->next) {
|
2021-07-26 02:15:51 +00:00
|
|
|
if (set_is_member (pvs, el->leafnum))
|
2004-03-07 00:25:09 +00:00
|
|
|
break;
|
2010-12-07 23:44:52 +00:00
|
|
|
}
|
|
|
|
if (!el)
|
2004-03-07 00:25:09 +00:00
|
|
|
continue; // not visible
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
if (pack->players)
|
|
|
|
state = &pack->players[pack->num_players];
|
|
|
|
pack->num_players++;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.number = j;
|
|
|
|
state->es.flags = 0;
|
|
|
|
VectorCopy (SVvector (ent, origin), state->es.origin);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
state->msec = min (255, 1000 * (sv.time - cl->localtime));
|
2002-06-19 02:55:57 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
state->cmd = cl->lastcmd;
|
|
|
|
if (SVfloat (ent, health) <= 0) { // don't show the corpse
|
|
|
|
// looking around...
|
|
|
|
state->cmd.angles[0] = 0;
|
|
|
|
state->cmd.angles[1] = SVvector (ent, angles)[1];
|
|
|
|
state->cmd.angles[0] = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 05:27:36 +00:00
|
|
|
VectorCopy (SVvector (ent, velocity), state->es.velocity);
|
|
|
|
state->es.modelindex = SVfloat (ent, modelindex);
|
|
|
|
state->es.frame = SVfloat (ent, frame);
|
|
|
|
state->es.skinnum = SVfloat (ent, skin);
|
|
|
|
state->es.effects = SVfloat (ent, effects);
|
|
|
|
state->es.weaponframe = SVfloat (ent, weaponframe);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
if (SVfloat (ent, health) <= 0)
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.flags |= PF_DEAD;
|
2005-04-30 08:45:17 +00:00
|
|
|
if (SVvector (ent, mins)[2] != -24)
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.flags |= PF_GIB;
|
|
|
|
state->es.flags |= PF_MSEC | PF_COMMAND;
|
|
|
|
|
|
|
|
state->es.alpha = 255;
|
|
|
|
state->es.scale = 16;
|
|
|
|
state->es.glow_size = 0;
|
|
|
|
state->es.glow_color = 254;
|
|
|
|
state->es.colormod = 255;
|
2005-04-30 08:45:17 +00:00
|
|
|
if (sv_fields.alpha != -1 && SVfloat (ent, alpha)) {
|
|
|
|
float alpha = SVfloat (ent, alpha);
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.alpha = bound (0, alpha, 1) * 255.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2005-04-30 08:45:17 +00:00
|
|
|
if (sv_fields.scale != -1 && SVfloat (ent, scale)) {
|
|
|
|
float scale = SVfloat (ent, scale);
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.scale = bound (0, scale, 15.9375) * 16;
|
2005-04-30 08:45:17 +00:00
|
|
|
}
|
|
|
|
if (sv_fields.glow_size != -1 && SVfloat (ent, glow_size)) {
|
|
|
|
int glow_size = SVfloat (ent, glow_size);
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.glow_size = bound (-1024, glow_size, 1016) >> 3;
|
2005-04-30 08:45:17 +00:00
|
|
|
}
|
|
|
|
if (sv_fields.glow_color != -1 && SVfloat (ent, glow_color))
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.glow_color = SVfloat (ent, glow_color);
|
2005-04-30 08:45:17 +00:00
|
|
|
if (sv_fields.colormod != -1
|
|
|
|
&& !VectorIsZero (SVvector (ent, colormod))) {
|
|
|
|
float *colormod= SVvector (ent, colormod);
|
2021-03-11 05:27:36 +00:00
|
|
|
state->es.colormod = ((int) (bound (0, colormod[0], 1) * 7) << 5) |
|
|
|
|
((int) (bound (0, colormod[1], 1) * 7) << 2) |
|
|
|
|
(int) (bound (0, colormod[2], 1) * 3);
|
2001-11-07 08:24:56 +00:00
|
|
|
}
|
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
if (cl->spectator) {
|
2010-01-13 06:42:26 +00:00
|
|
|
// send only origin and velocity of spectators
|
2005-04-30 08:45:17 +00:00
|
|
|
mask &= PF_VELOCITY1 | PF_VELOCITY2 | PF_VELOCITY3;
|
|
|
|
} else if (ent == clent) {
|
|
|
|
// don't send a lot of data on personal entity
|
|
|
|
mask &= ~(PF_MSEC | PF_COMMAND);
|
|
|
|
mask |= PF_WEAPONFRAME;
|
|
|
|
}
|
2001-11-07 08:24:56 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
if (spec_track && spec_track - 1 == j)
|
|
|
|
mask |= PF_WEAPONFRAME;
|
2002-06-19 02:55:57 +00:00
|
|
|
|
2005-04-30 08:45:17 +00:00
|
|
|
if (from_pack && from_pack->players) {
|
2005-05-09 12:12:48 +00:00
|
|
|
while (k < from_pack->num_players
|
2021-03-11 05:27:36 +00:00
|
|
|
&& from_pack->players[k].es.number < state->es.number)
|
2005-04-30 08:45:17 +00:00
|
|
|
k++;
|
2005-05-09 12:12:48 +00:00
|
|
|
if (k < from_pack->num_players
|
2021-03-11 05:27:36 +00:00
|
|
|
&& from_pack->players[k].es.number == state->es.number) {
|
2005-05-09 12:12:48 +00:00
|
|
|
write (delta, &from_pack->players[k], state, msg, mask, full);
|
2005-04-30 08:45:17 +00:00
|
|
|
continue;
|
2002-06-19 02:55:57 +00:00
|
|
|
}
|
2005-05-09 12:12:48 +00:00
|
|
|
full = 1;
|
2002-06-19 02:55:57 +00:00
|
|
|
}
|
2005-05-09 12:12:48 +00:00
|
|
|
write (delta, &null_player_state, state, msg, mask, full);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 02:15:51 +00:00
|
|
|
static inline set_t *
|
2005-04-30 08:45:17 +00:00
|
|
|
calc_pvs (delta_t *delta)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-07-26 02:15:51 +00:00
|
|
|
set_t *pvs = 0;
|
2005-04-30 08:45:17 +00:00
|
|
|
vec3_t org;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// find the client's PVS
|
2005-04-30 08:45:17 +00:00
|
|
|
if (delta->pvs == dt_pvs_normal) {
|
|
|
|
edict_t *clent = delta->client->edict;
|
2002-10-04 02:29:03 +00:00
|
|
|
VectorAdd (SVvector (clent, origin), SVvector (clent, view_ofs), org);
|
|
|
|
pvs = SV_FatPVS (org);
|
2005-04-30 08:45:17 +00:00
|
|
|
} else if (delta->pvs == dt_pvs_fat) {
|
2010-01-13 06:42:26 +00:00
|
|
|
// when recording a demo, send only entities that can be seen. Can help
|
2005-04-30 08:45:17 +00:00
|
|
|
// shrink the mvd at expense of effectively lossy compressio (ents that
|
|
|
|
// can't be seen by a player either won't get updated or will disappear
|
|
|
|
// for people watching the mvd from viewpoints with no players around
|
|
|
|
// (not sure yet:).
|
2002-10-04 02:29:03 +00:00
|
|
|
client_t *cl;
|
2005-04-30 08:45:17 +00:00
|
|
|
int i;
|
2002-10-17 16:03:18 +00:00
|
|
|
|
2002-10-04 02:29:03 +00:00
|
|
|
for (i=0, cl = svs.clients; i<MAX_CLIENTS; i++, cl++) {
|
2003-03-03 21:46:41 +00:00
|
|
|
if (cl->state != cs_spawned && cl->state != cs_server)
|
2002-10-04 02:29:03 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cl->spectator)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
VectorAdd (SVvector (cl->edict, origin),
|
|
|
|
SVvector (cl->edict, view_ofs), org);
|
|
|
|
if (pvs == NULL) {
|
|
|
|
pvs = SV_FatPVS (org);
|
|
|
|
} else {
|
2021-02-01 10:31:11 +00:00
|
|
|
SV_AddToFatPVS (org, sv.worldmodel->brush.nodes);
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-30 08:45:17 +00:00
|
|
|
return pvs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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 (delta_t *delta, sizebuf_t *msg)
|
|
|
|
{
|
2021-07-26 02:15:51 +00:00
|
|
|
set_t *pvs = 0;
|
2010-12-07 23:44:52 +00:00
|
|
|
int e, num_edicts;
|
2005-04-30 08:45:17 +00:00
|
|
|
int max_packet_entities = MAX_DEMO_PACKET_ENTITIES;
|
|
|
|
int stdver = 1;
|
|
|
|
client_frame_t *frame;
|
|
|
|
edict_t *ent;
|
2010-12-07 23:44:52 +00:00
|
|
|
edict_leaf_t *el;
|
2005-04-30 08:45:17 +00:00
|
|
|
entity_state_t *state;
|
|
|
|
packet_entities_t *pack;
|
|
|
|
|
|
|
|
if (delta->client) {
|
2007-05-07 14:58:53 +00:00
|
|
|
max_packet_entities = MAX_PACKET_ENTITIES;
|
2005-04-30 08:45:17 +00:00
|
|
|
stdver = delta->client->stdver;
|
|
|
|
}
|
|
|
|
|
|
|
|
pvs = calc_pvs (delta);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// send over the players in the PVS
|
2005-04-30 08:45:17 +00:00
|
|
|
SV_WritePlayersToClient (delta, pvs, msg);
|
|
|
|
|
|
|
|
// this is the frame we are creating
|
|
|
|
frame = &delta->frames[delta->in_frame];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// put other visible entities into either a packet_entities or a nails
|
|
|
|
// message
|
|
|
|
pack = &frame->entities;
|
|
|
|
pack->num_entities = 0;
|
|
|
|
|
|
|
|
numnails = 0;
|
|
|
|
|
2001-12-10 03:17:21 +00:00
|
|
|
num_edicts = min (sv.num_edicts, 512); //FIXME stupid protocol limit
|
|
|
|
|
2001-10-29 05:42:10 +00:00
|
|
|
for (e = MAX_CLIENTS + 1, ent = EDICT_NUM (&sv_pr_state, e);
|
2002-06-28 02:11:13 +00:00
|
|
|
e < num_edicts; e++, ent = NEXT_EDICT (&sv_pr_state, ent)) {
|
2001-08-14 11:15:47 +00:00
|
|
|
if (ent->free)
|
|
|
|
continue;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// ignore ents without visible models
|
2001-10-16 22:55:37 +00:00
|
|
|
if (!SVfloat (ent, modelindex)
|
|
|
|
|| !*PR_GetString (&sv_pr_state, SVstring (ent, model)))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
2004-03-07 00:25:09 +00:00
|
|
|
if (pvs) {
|
2002-10-04 02:29:03 +00:00
|
|
|
// ignore if not touching a PV leaf
|
2010-12-09 05:27:36 +00:00
|
|
|
for (el = SVdata (ent)->leafs; el; el = el->next) {
|
2021-07-26 02:15:51 +00:00
|
|
|
if (set_is_member (pvs, el->leafnum))
|
2002-10-04 02:29:03 +00:00
|
|
|
break;
|
2010-12-07 23:44:52 +00:00
|
|
|
}
|
|
|
|
if (!el)
|
|
|
|
continue; // not visible
|
2002-10-04 02:29:03 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (SV_AddNailUpdate (ent))
|
|
|
|
continue; // added to the special update list
|
|
|
|
|
|
|
|
// add to the packetentities
|
2002-10-17 16:03:18 +00:00
|
|
|
if (pack->num_entities == max_packet_entities) {
|
2001-02-19 21:15:25 +00:00
|
|
|
continue; // all full
|
2002-08-15 21:11:57 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
state = &pack->entities[pack->num_entities];
|
|
|
|
pack->num_entities++;
|
|
|
|
|
|
|
|
state->number = e;
|
|
|
|
state->flags = 0;
|
2001-08-08 20:28:53 +00:00
|
|
|
VectorCopy (SVvector (ent, origin), state->origin);
|
|
|
|
VectorCopy (SVvector (ent, angles), state->angles);
|
|
|
|
state->modelindex = SVfloat (ent, modelindex);
|
|
|
|
state->frame = SVfloat (ent, frame);
|
|
|
|
state->colormap = SVfloat (ent, colormap);
|
|
|
|
state->skinnum = SVfloat (ent, skin);
|
|
|
|
state->effects = SVfloat (ent, effects);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// LordHavoc: cleaned up Endy's coding style, shortened the code,
|
|
|
|
// and implemented missing effects
|
|
|
|
// Ender: EXTEND (QSG - Begin)
|
|
|
|
{
|
|
|
|
state->alpha = 255;
|
|
|
|
state->scale = 16;
|
2001-03-27 03:57:17 +00:00
|
|
|
state->glow_size = 0;
|
|
|
|
state->glow_color = 254;
|
2001-02-19 21:15:25 +00:00
|
|
|
state->colormod = 255;
|
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if (sv_fields.alpha != -1 && SVfloat (ent, alpha))
|
|
|
|
state->alpha = bound (0, SVfloat (ent, alpha), 1) * 255.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if (sv_fields.scale != -1 && SVfloat (ent, scale))
|
|
|
|
state->scale = bound (0, SVfloat (ent, scale), 15.9375) * 16.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-08 20:28:53 +00:00
|
|
|
if (sv_fields.glow_size != -1 && SVfloat (ent, glow_size))
|
2002-06-28 02:11:13 +00:00
|
|
|
state->glow_size =
|
|
|
|
bound (-1024, (int) SVfloat (ent, glow_size), 1016) >> 3;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-16 01:09:17 +00:00
|
|
|
if (sv_fields.glow_color != -1 && SVfloat (ent, glow_color))
|
|
|
|
state->glow_color = (int) SVfloat (ent, glow_color);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-06-28 02:11:13 +00:00
|
|
|
if (sv_fields.colormod != -1 && SVvector (ent, colormod)[0]
|
|
|
|
&& SVvector (ent, colormod)[1] && SVvector (ent, colormod)[2])
|
2001-02-19 21:15:25 +00:00
|
|
|
state->colormod =
|
2001-08-28 02:43:24 +00:00
|
|
|
((int) (bound (0, SVvector (ent, colormod)[0], 1) * 7.0)
|
|
|
|
<< 5) |
|
|
|
|
((int) (bound (0, SVvector (ent, colormod)[1], 1) * 7.0)
|
|
|
|
<< 2) |
|
2001-08-08 20:28:53 +00:00
|
|
|
(int) (bound (0, SVvector (ent, colormod)[2], 1) * 3.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// Ender: EXTEND (QSG - End)
|
|
|
|
}
|
|
|
|
|
|
|
|
// encode the packet entities as a delta from the
|
|
|
|
// last packetentities acknowledged by the client
|
2005-04-30 08:45:17 +00:00
|
|
|
SV_EmitPacketEntities (delta, pack, msg, stdver);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// now add the specialized nail update
|
2007-04-07 13:52:26 +00:00
|
|
|
SV_EmitNailUpdate (msg, !delta->client);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|