3 // #define PROP(public, fld, sv, cl)
4 #define ENTCS_NETPROPS(PROP) \
5 PROP(true, sv_entnum, \
6 { WriteByte(MSG_ENTITY, etof(player) - 1); }, \
7 { this.sv_entnum = ReadByte(); }) \
10 { WriteShort(MSG_ENTITY, this.origin.x); WriteShort(MSG_ENTITY, this.origin.y); \
11 WriteShort(MSG_ENTITY, this.origin.z); }, \
12 { this.has_origin = true; vector v; v.x = ReadShort(); v.y = ReadShort(); v.z = ReadShort(); setorigin(this, v); }) \
14 PROP(false, angles_y, \
15 { WriteByte(MSG_ENTITY, this.angles.y / 360 * 256); }, \
16 { vector v = '0 0 0'; v.y = ReadByte() / 256 * 360; this.angles = v; }) \
19 { WriteByte(MSG_ENTITY, this.health / 10); /* FIXME: use a better scale? */ }, \
20 { this.healthvalue = ReadByte() * 10; }) \
22 PROP(false, armorvalue, \
23 { WriteByte(MSG_ENTITY, this.armorvalue / 10); /* FIXME: use a better scale? */ }, \
24 { this.armorvalue = ReadByte() * 10; }) \
27 { WriteString(MSG_ENTITY, this.netname); }, \
28 { if (this.netname) strunzone(this.netname); this.netname = strzone(ReadString()); }) \
31 { WriteString(MSG_ENTITY, this.model); }, \
32 { if (this.model) strunzone(this.model); this.model = strzone(ReadString()); }) \
35 { WriteByte(MSG_ENTITY, this.skin); }, \
36 { this.skin = ReadByte(); }) \
42 int ENTCS_PUBLICMASK = 0;
43 STATIC_INIT(ENTCS_PUBLICMASK)
46 #define X(public, fld, sv, cl) { if (public) ENTCS_PUBLICMASK |= BIT(i); } i += 1;
49 if (i >= BITS(16 - 1)) LOG_FATAL("Exceeded ENTCS_NETPROPS limit");
52 bool entcs_send(entity this, entity to, int sf)
54 entity player = this.owner;
56 if (IS_PLAYER(to) || to.caplayer) // unless spectating,
58 bool same_team = (to == player) || (teamplay && player.team == to.team);
59 if (!same_team && !radar_showennemies) sf &= ENTCS_PUBLICMASK; // no private updates
61 sf |= this.m_forceupdate;
62 this.m_forceupdate = 0;
64 IS_PLAYER(player) // player must be active
65 && player.deadflag == DEAD_NO // player must be alive
66 || player == to // player is self
68 if (!valid) return false;
69 WriteHeader(MSG_ENTITY, ENT_CLIENT_ENTCS);
70 WriteShort(MSG_ENTITY, sf);
72 #define X(public, fld, sv, cl) { if (sf & BIT(i)) sv; } i += 1;
81 this.nextthink = time + 0.033333333333; // TODO: increase this to like 0.15 once the client can do smoothing
82 entity o = this.owner;
84 #define X(public, fld, sv, cl) \
85 if (o.fld != this.fld) \
88 this.SendFlags |= BIT(i); \
95 void entcs_attach(entity player)
97 entity e = player.entcs = new(entcs_sender);
100 e.think = entcs_think;
102 Net_LinkEntity(e, false, 0, entcs_send);
105 void entcs_detach(entity player)
107 if (!player.entcs) return;
108 remove(player.entcs);
116 void Ent_RemoveEntCS()
119 entcs_receiver[this.sv_entnum] = NULL;
125 this.nextthink = time;
126 entity e = CSQCModel_server2csqc(this.sv_entnum + 1);
130 this.has_origin = true;
131 this.origin = e.origin;
132 // `cl_forceplayermodels 1` sounds will be wrong until the player has been in the PVS, but so be it
133 if (this.model != e.model)
135 if (this.model) strunzone(this.model);
136 this.model = strzone(e.model);
141 NET_HANDLE(ENT_CLIENT_ENTCS, bool isnew)
146 this.classname = "entcs_receiver";
147 this.entremove = Ent_RemoveEntCS;
148 this.think = entcs_think;
149 this.nextthink = time;
151 InterpolateOrigin_Undo();
152 int sf = ReadShort();
153 this.has_origin = false;
154 this.m_entcs_private = boolean(sf & 1);
156 #define X(public, fld, sv, cl) { if (sf & BIT(i)) cl; } i += 1;
159 entcs_receiver[this.sv_entnum] = this;
160 this.iflags |= IFLAG_ORIGIN;
161 InterpolateOrigin_Note();