PROP(false, origin, \
{ WriteShort(MSG_ENTITY, this.origin.x); WriteShort(MSG_ENTITY, this.origin.y); \
WriteShort(MSG_ENTITY, this.origin.z); }, \
- { this.has_origin = true; vector v; v.x = ReadShort(); v.y = ReadShort(); v.z = ReadShort(); setorigin(this, v); }) \
+ { this.has_sv_origin = true; vector v; v.x = ReadShort(); v.y = ReadShort(); v.z = ReadShort(); setorigin(this, v); }) \
\
PROP(false, angles_y, \
{ WriteByte(MSG_ENTITY, this.angles.y / 360 * 256); }, \
if (i >= BITS(16 - 1)) LOG_FATAL("Exceeded ENTCS_NETPROPS limit");
}
- bool entcs_customize()
- {
- SELFPARAM();
- entity player = this.owner;
- return IS_PLAYER(player) // player must be active
- && player.deadflag == DEAD_NO // player must be alive
- ;
- }
-
bool entcs_send(entity this, entity to, int sf)
{
entity player = this.owner;
- sf |= 1;
+ sf |= BIT(0) | BIT(1);
if (IS_PLAYER(to) || to.caplayer) // unless spectating,
{
bool same_team = (to == player) || (teamplay && player.team == to.team);
}
sf |= this.m_forceupdate;
this.m_forceupdate = 0;
+ bool valid =
+ IS_PLAYER(player) // player must be active
+ && player.deadflag == DEAD_NO // player must be alive
+ || player == to // player is self
+ ;
+ if (!valid) sf = 0;
WriteHeader(MSG_ENTITY, ENT_CLIENT_ENTCS);
WriteShort(MSG_ENTITY, sf);
int i = 1;
e.think = entcs_think;
e.nextthink = time;
Net_LinkEntity(e, false, 0, entcs_send);
- e.customizeentityforclient = entcs_customize;
}
void entcs_detach(entity player)
void Ent_RemoveEntCS()
{
SELFPARAM();
- entcs_receiver[this.sv_entnum] = NULL;
+ entcs_receiver(this.sv_entnum, NULL);
}
void entcs_think()
{
SELFPARAM();
- this.nextthink = time;
- entity e = CSQCModel_server2csqc(this.sv_entnum + 1);
- bool exists = !!e;
- if (exists)
+ entity e = CSQCModel_server2csqc(this.sv_entnum);
+ if (e == NULL)
+ {
+ this.has_origin = this.has_sv_origin;
+ return;
+ }
+ this.has_origin = true;
+ this.origin = e.origin;
+ // `cl_forceplayermodels 1` sounds will be wrong until the player has been in the PVS, but so be it
+ if (this.model != e.model)
{
- this.has_origin = true;
- this.origin = e.origin;
- // `cl_forceplayermodels 1` sounds will be wrong until the player has been in the PVS, but so be it
- if (this.model != e.model)
- {
- if (this.model) strunzone(this.model);
- this.model = strzone(e.model);
- }
+ if (this.model) strunzone(this.model);
+ this.model = strzone(e.model);
}
}
this.classname = "entcs_receiver";
this.entremove = Ent_RemoveEntCS;
this.think = entcs_think;
- this.nextthink = time;
}
- InterpolateOrigin_Undo();
+ InterpolateOrigin_Undo(this);
int sf = ReadShort();
- this.has_origin = false;
- this.m_entcs_private = boolean(sf & 1);
+ this.has_sv_origin = false;
+ this.m_entcs_private = boolean(sf & BIT(0));
int i = 1;
#define X(public, fld, sv, cl) { if (sf & BIT(i)) cl; } i += 1;
ENTCS_NETPROPS(X);
#undef X
- entcs_receiver[this.sv_entnum] = this;
+ entcs_receiver(this.sv_entnum, this);
this.iflags |= IFLAG_ORIGIN;
- InterpolateOrigin_Note();
+ InterpolateOrigin_Note(this);
+ this.think();
return true;
}