From 6c6d85a09727ef5e6ca7ac0abc54b11895aa59d1 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 15 May 2011 20:12:46 +0200 Subject: [PATCH] remove entity spam from shownames --- qcsrc/client/Main.qc | 40 ++++++++---------------------------- qcsrc/client/shownames.qc | 8 ++++---- qcsrc/server/autocvars.qh | 2 -- qcsrc/server/cl_client.qc | 14 ------------- qcsrc/server/cl_player.qc | 43 --------------------------------------- qcsrc/server/defs.qh | 3 --- qcsrc/server/ent_cs.qc | 31 +++++++++++++++++++++------- 7 files changed, 37 insertions(+), 104 deletions(-) diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index a097f0719..d7cb0ce62 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -679,9 +679,18 @@ void Ent_ReadEntCS() self.angles_y = ReadByte() * 360.0 / 256; self.angles_x = self.angles_z = 0; } + if(sf & 8) + self.healthvalue = ReadByte() * 10; + if(sf & 16) + self.armorvalue = ReadByte() * 10; + if(sf & 128) // same team + self.sameteam = TRUE; + else + self.sameteam = FALSE; entcs_receiver[self.sv_entnum] = self; self.entremove = Ent_RemoveEntCS; + self.draw2d = Draw_ShowNames; InterpolateOrigin_Note(); } @@ -907,36 +916,6 @@ void Ent_ReadAccuracy(void) } } -void Ent_ShowNames() -{ - float sf; - - // entity init, TODO can this be done only once somehow? - self.the_entnum = ReadByte(); // TODO: fixme to only send once somehow - self.draw2d = Draw_ShowNames; - - //self.movetype = MOVETYPE_FLY; // movetype needed so we can traceline? - //self.mins = '-20 -20 -24'; - //self.maxs = '20 20 45'; - self.classname = "shownames_tag"; - - sf = ReadByte(); - - if(sf & 1) - { - self.healthvalue = ReadByte() * 10; - } - if(sf & 2) - { - self.armorvalue = ReadByte() * 10; - } - - if(sf & 128) // same team - self.sameteam = TRUE; - else - self.sameteam = FALSE; -} - // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured. // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS. void Ent_RadarLink(); @@ -1003,7 +982,6 @@ void(float bIsNewEntity) CSQC_Ent_Update = case ENT_CLIENT_LGBEAM: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_LGBEAM); break; case ENT_CLIENT_GAUNTLET: Ent_ReadHook(bIsNewEntity, ENT_CLIENT_GAUNTLET); break; case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break; - case ENT_CLIENT_SHOWNAMES: Ent_ShowNames(); break; default: //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype)); error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname)); diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc index 82fa05e09..c467ea687 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -10,12 +10,12 @@ void Draw_ShowNames() if(!autocvar_hud_shownames) return; - if(self.the_entnum == player_localentnum && !autocvar_chase_active) + if(self.sv_entnum == player_localentnum && !autocvar_chase_active) return; if(self.sameteam || (!self.sameteam && autocvar_hud_shownames_enemies)) { - self.origin = getplayerorigin(self.the_entnum-1); + self.origin = getplayerorigin(self.sv_entnum-1); self.origin_z += autocvar_hud_shownames_offset; if(!self.sameteam) @@ -127,9 +127,9 @@ void Draw_ShowNames() } string s; - s = GetPlayerName(self.the_entnum-1); + s = GetPlayerName(self.sv_entnum-1); if((autocvar_hud_shownames_decolorize == 1 && teamplay) || autocvar_hud_shownames_decolorize == 2) - s = playername(s, GetPlayerColor(self.the_entnum-1)); + s = playername(s, GetPlayerColor(self.sv_entnum-1)); drawfontscale = '1 1 0' * resize; s = textShortenToWidth(s, namewidth, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors); diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 70719e0d7..26bd176b6 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -1127,7 +1127,6 @@ float autocvar_sv_airspeedlimit_nonqw; float autocvar_sv_airstopaccelerate; float autocvar_sv_airstrafeaccel_qw; float autocvar_sv_airstrafeaccelerate; -float autocvar_sv_allow_shownames; float autocvar_sv_autoscreenshot; float autocvar_sv_cheats; float autocvar_sv_curl_serverpackages_auto; @@ -1244,4 +1243,3 @@ float autocvar_waypoint_benchmark; float autocvar_welcome_message_time; float autocvar_sv_gameplayfix_gravityunaffectedbyticrate; float autocvar_g_trueaim_minrange; -float autocvar_sv_shownames_cull_distance; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 1406e13b8..f699e6db2 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -735,9 +735,6 @@ void PutObserverInServer (void) } else self.frags = FRAGS_SPECTATOR; - - if(self.shownames) - remove(self.shownames); } void FixPlayermodel() @@ -1103,15 +1100,6 @@ void PutClientInServer (void) PutObserverInServer (); } - if(!self.shownames) - { - self.shownames = spawn(); - self.shownames.owner = self; - self.shownames.think = shownames_think; - self.shownames.nextthink = time; - Net_LinkEntity(self.shownames, FALSE, 0, SendEntity_ShowNames); - } - //if(g_ctf) // ctf_playerchanged(); } @@ -1880,8 +1868,6 @@ void ClientDisconnect (void) self.playerid = 0; ReadyCount(); - remove(self.shownames); - // free cvars GetCvars(-1); } diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 13953f13a..c4bcded28 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -735,49 +735,6 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht } } -// sendflags use: 1 = health (value is 0 or 1 for dead/alive on enemies), 2 = armor, 0x80 = same team (includes health) -float SendEntity_ShowNames(entity to, float sendflags) -{ - float the_health; - the_health = self.health; - - WriteByte(MSG_ENTITY, ENT_CLIENT_SHOWNAMES); - WriteByte(MSG_ENTITY, num_for_edict(self.owner)); - - sendflags = sendflags & 127; - if(teams_matter && self.owner.team == to.team) - sendflags |= 128; - else if(self.owner.health >= 1) - the_health = 1; - - WriteByte(MSG_ENTITY, sendflags); - if(sendflags & 1) - { - WriteByte(MSG_ENTITY, the_health); - } - if(sendflags & 2) - { - WriteByte(MSG_ENTITY, self.armorvalue); - } - return TRUE; -} - -void shownames_think() -{ - self.origin = self.owner.origin + '0 0 1' * 48; - if(self.health != max(0, ceil(self.owner.health/10))) - { - self.health = max(0, ceil(self.owner.health/10)); - self.SendFlags |= 1; - } - if(self.armorvalue != max(0, ceil(self.owner.armorvalue/10))) - { - self.armorvalue = max(0, ceil(self.owner.armorvalue/10)); - self.SendFlags |= 2; - } - self.nextthink = time; -} - .float muted; // to be used by prvm_edictset server playernumber muted 1 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol) // message "": do not say, just test flood control diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 19f0c24a5..f3c754151 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -664,6 +664,3 @@ float serverflags; .entity muzzle_flash; .float misc_bulletcounter; // replaces uzi & hlac bullet counter. - -.entity shownames; -void shownames_think(); diff --git a/qcsrc/server/ent_cs.qc b/qcsrc/server/ent_cs.qc index 970f20a92..0a477b1b4 100644 --- a/qcsrc/server/ent_cs.qc +++ b/qcsrc/server/ent_cs.qc @@ -39,20 +39,27 @@ float entcs_customize() float entcs_send(entity to, float sf) { - entity o; - o = self.owner; + sf |= 128; + if(teams_matter && !radar_showennemies) + if(to.team != self.team) + sf &~= (8 | 16 | 128); // don't send h/a for enemies + WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS); WriteByte(MSG_ENTITY, sf); if(sf & 1) - WriteByte(MSG_ENTITY, num_for_edict(o)); + WriteByte(MSG_ENTITY, num_for_edict(self.owner)); if(sf & 2) { - WriteShort(MSG_ENTITY, o.origin_x); - WriteShort(MSG_ENTITY, o.origin_y); - WriteShort(MSG_ENTITY, o.origin_z); + WriteShort(MSG_ENTITY, self.origin_x); + WriteShort(MSG_ENTITY, self.origin_y); + WriteShort(MSG_ENTITY, self.origin_z); } if(sf & 4) - WriteByte(MSG_ENTITY, o.angles_y * 256.0 / 360); + WriteByte(MSG_ENTITY, self.angles_y * 256.0 / 360); + if(sf & 8) + WriteByte(MSG_ENTITY, self.health / 10); // FIXME use a better scale? + if(sf & 16) + WriteByte(MSG_ENTITY, self.armorvalue / 10); // FIXME use a better scale? return TRUE; }; @@ -73,6 +80,16 @@ void entcs_think() self.angles = o.angles; self.SendFlags |= 4; } + if(o.health != self.health) + { + self.health = o.health; + self.SendFlags |= 8; + } + if(o.armorvalue != self.armorvalue) + { + self.armorvalue = o.armorvalue; + self.SendFlags |= 16; + } }; entity attach_entcs() -- 2.39.2