3 // #define PROP(public, fld, sv, cl)
4 #define ENTCS_NETPROPS(PROP) PROP(false, sv_entnum, {}, {}) /* sentinel */ \
6 { WriteShort(chan, this.origin.x); WriteShort(chan, this.origin.y); \
7 WriteShort(chan, this.origin.z); }, \
8 { this.has_sv_origin = true; vector v; v.x = ReadShort(); v.y = ReadShort(); v.z = ReadShort(); setorigin(this, v); }) \
10 PROP(false, angles_y, \
11 { WriteByte(chan, this.angles.y / 360 * 256); }, \
12 { vector v = '0 0 0'; v.y = ReadByte() / 256 * 360; this.angles = v; }) \
15 { WriteByte(chan, bound(0, this.health / 10, 255)); /* FIXME: use a better scale? */ }, \
16 { this.healthvalue = ReadByte() * 10; }) \
18 PROP(false, armorvalue, \
19 { WriteByte(chan, bound(0, this.armorvalue / 10, 255)); /* FIXME: use a better scale? */ }, \
20 { this.armorvalue = ReadByte() * 10; }) \
23 { WriteString(chan, this.netname); }, \
24 { if (this.netname) strunzone(this.netname); this.netname = strzone(ReadString()); }) \
27 { WriteString(chan, this.model); }, \
28 { if (this.model) strunzone(this.model); this.model = strzone(ReadString()); }) \
31 { WriteByte(chan, this.skin); }, \
32 { this.skin = ReadByte(); }) \
34 PROP(true, clientcolors, \
35 { WriteByte(chan, this.clientcolors); }, \
36 { this.colormap = ReadByte(); }) \
39 { WriteShort(chan, this.frags); }, \
40 { this.frags = ReadShort(); }) \
46 int ENTCS_PUBLICMASK = 0;
47 STATIC_INIT(ENTCS_PUBLICMASK)
50 #define X(public, fld, sv, cl) { \
52 ENTCS_PUBLICMASK |= BIT(i); \
58 if (i >= BITS(16 - 1)) LOG_FATAL("Exceeded ENTCS_NETPROPS limit");
61 bool _entcs_send(entity this, entity to, int sf, int chan)
63 entity player = this.owner;
64 sf |= BIT(0); // assume private
66 if (radar_showennemies) break;
67 if ((to == player) || (teamplay && player.team == to.team)) break;
68 if (!(IS_PLAYER(to) || to.caplayer) && time > game_starttime) break;
69 sf &= ENTCS_PUBLICMASK; // no private updates
71 sf |= this.m_forceupdate;
72 this.m_forceupdate = 0;
73 if (chan == MSG_ENTITY)
74 WriteHeader(chan, ENT_CLIENT_ENTCS);
76 WriteHeader(chan, CLIENT_ENTCS);
77 WriteByte(chan, etof(player) - 1);
80 #define X(public, fld, sv, cl) { \
91 bool entcs_send(entity this, entity to, int sf)
93 return _entcs_send(this, to, sf, MSG_ENTITY);
96 void entcs_think(entity this)
98 this.nextthink = time + 0.033333333333; // TODO: increase this to like 0.15 once the client can do smoothing
99 entity o = this.owner;
101 #define X(public, fld, sv, cl) { \
102 if (o.fld != this.fld) { \
104 this.SendFlags |= BIT(i); \
110 setorigin(this, this.origin); // relink
113 void entcs_attach(entity player)
115 entity e = player.entcs = new(entcs_sender);
117 setthink(e, entcs_think);
119 Net_LinkEntity(e, false, 0, entcs_send);
120 if (!IS_REAL_CLIENT(player)) return;
121 FOREACH_CLIENT(true, {
123 _entcs_send(it.entcs, msg_entity = player, BITS(23), MSG_ONE);
127 void entcs_detach(entity player)
129 if (!player.entcs) return;
130 delete(player.entcs);
138 void Ent_RemoveEntCS(entity this)
140 int n = this.sv_entnum;
141 entity e = entcs_receiver(n);
142 entcs_receiver(n, NULL);
143 if (e != this) delete(e);
146 void entcs_think(entity this)
148 entity e = CSQCModel_server2csqc(this.sv_entnum);
151 this.has_origin = this.has_sv_origin;
154 this.has_origin = true;
155 this.origin = e.origin;
156 // `cl_forceplayermodels 1` sounds will be wrong until the player has been in the PVS, but so be it
157 if (this.model != e.model)
159 if (this.model) strunzone(this.model);
160 this.model = strzone(e.model);
164 bool ReadEntcs(entity this)
167 entity e = entcs_receiver(n);
169 setthink(e, entcs_think); \
170 entcs_receiver(n, e); \
177 e = new_pure(entcs_receiver);
187 else if (e != this && this)
195 InterpolateOrigin_Undo(e);
197 int sf = ReadShort();
198 e.has_sv_origin = false;
199 e.m_entcs_private = boolean(sf & BIT(0));
201 #define X(public, fld, sv, cl) { \
209 e.iflags |= IFLAG_ORIGIN;
210 InterpolateOrigin_Note(e);
215 NET_HANDLE(ENT_CLIENT_ENTCS, bool isnew)
220 this.classname = "entcs_receiver";
221 this.entremove = Ent_RemoveEntCS;
223 return ReadEntcs(this);
226 NET_HANDLE(CLIENT_ENTCS, bool isnew)
228 return ReadEntcs(NULL);