From: FruitieX Date: Mon, 11 Apr 2011 18:34:34 +0000 (+0300) Subject: new implementation of shownames with MSG_ENTITY (broken currently) X-Git-Tag: xonotic-v0.5.0~302 X-Git-Url: https://de.git.xonotic.org/?a=commitdiff_plain;h=8c1c9365bbfe7e44623fb3a886078c11dc712841;p=xonotic%2Fxonotic-data.pk3dir.git new implementation of shownames with MSG_ENTITY (broken currently) --- diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index 6de1a872e..38025a565 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -907,6 +907,59 @@ void Ent_ReadAccuracy(void) } } +.float health, armorvalue; +void Ent_ShowNames() +{ + float sf, the_entnum; + + sf = ReadByte(); + the_entnum = ReadByte(); + + if(sf & 1) + { + playerslots[the_entnum].origin_x = ReadShort(); + playerslots[the_entnum].origin_y = ReadShort(); + playerslots[the_entnum].origin_z = ReadShort(); + print("Updated origin = ", vtos(playerslots[the_entnum].origin), " for player # ", ftos(the_entnum), "\n"); + } + if(sf & 2) + { + playerslots[the_entnum].health = ReadByte(); + playerslots[the_entnum].armorvalue = ReadByte(); + print("Updated health/armor = ", ftos(playerslots[the_entnum].health), "/", ftos(playerslots[the_entnum].health), " for player # ", ftos(the_entnum), "\n"); + } + if(sf & 4) + playerslots[the_entnum].netname = ReadString(); + + /* + string thename; + float thehealth, thearmor; + + if(shownames_netname) + strunzone(shownames_netname); + thename = strzone(ReadString()); + thehealth = ReadByte(); + thearmor = ReadByte(); + + if(autocvar_hud_panel_shownames == 1 && thehealth > 0) // teammates only + { + shownames_netname = thename; + shownames_health = thehealth; + shownames_armor = thearmor; + + shownames_time = time + autocvar_hud_panel_shownames_sustain; + } + else if(autocvar_hud_panel_shownames == 2) + { + shownames_netname = thename; + shownames_health = thehealth; + shownames_armor = thearmor; + + shownames_time = time + autocvar_hud_panel_shownames_sustain; + } + */ +} + // 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(); @@ -971,6 +1024,7 @@ 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)); break; @@ -1324,35 +1378,6 @@ void Net_WeaponComplain() { weapontime = time; // ping the weapon panel } -void Net_ShowNames() -{ - string thename; - float thehealth, thearmor; - - if(shownames_netname) - strunzone(shownames_netname); - thename = strzone(ReadString()); - thehealth = ReadByte(); - thearmor = ReadByte(); - - if(autocvar_hud_panel_shownames == 1 && thehealth > 0) // teammates only - { - shownames_netname = thename; - shownames_health = thehealth; - shownames_armor = thearmor; - - shownames_time = time + autocvar_hud_panel_shownames_sustain; - } - else if(autocvar_hud_panel_shownames == 2) - { - shownames_netname = thename; - shownames_health = thehealth; - shownames_armor = thearmor; - - shownames_time = time + autocvar_hud_panel_shownames_sustain; - } -} - // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer. // You must ALWAYS first acquire the temporary ID, which is sent as a byte. // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event. @@ -1423,10 +1448,6 @@ float CSQC_Parse_TempEntity() Net_WeaponComplain(); bHandled = true; break; - case TE_CSQC_SHOWNAMES: - Net_ShowNames(); - bHandled = true; - break; default: // No special logic for this temporary entity; return 0 so the engine can handle it bHandled = false; diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 13c1bc824..bfe3dec49 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -63,7 +63,6 @@ const float TE_CSQC_NOTIFY = 112; const float TE_CSQC_WEAPONCOMPLAIN = 113; const float TE_CSQC_NEX_SCOPE = 116; const float TE_CSQC_MINELAYER_MAXMINES = 117; -const float TE_CSQC_SHOWNAMES = 118; const float RACE_NET_CHECKPOINT_HIT_QUALIFYING = 0; // byte checkpoint, short time, short recordtime, string recordholder const float RACE_NET_CHECKPOINT_CLEAR = 1; @@ -114,6 +113,7 @@ const float ENT_CLIENT_HOOK = 27; const float ENT_CLIENT_LGBEAM = 28; const float ENT_CLIENT_GAUNTLET = 29; const float ENT_CLIENT_ACCURACY = 30; +const float ENT_CLIENT_SHOWNAMES = 31; const float ENT_CLIENT_TURRET = 40; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 8135dded5..59baea3c3 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -1756,6 +1756,11 @@ void ClientConnect (void) CheatInitClient(); PlayerStats_AddPlayer(self); + + self.shownames = spawn(); + self.shownames.owner = self; + self.shownames.think = shownames_think; + Net_LinkEntity(self.shownames, FALSE, 0, SendEntity_ShowNames); } /* @@ -1855,6 +1860,8 @@ void ClientDisconnect (void) self.playerid = 0; ReadyCount(); + remove(self.shownames); + // free cvars GetCvars(-1); } @@ -2709,9 +2716,6 @@ void PlayerPreThink (void) self.effects = self.effects - (self.effects & EF_NODRAW); } - if(frametime > 0) // don't do this in cl_movement frames, just in server ticks - UpdateSelectedPlayer(); - //don't allow the player to turn around while game is paused! if(timeoutStatus == 2) { self.v_angle = self.lastV_angle; diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 84d090acc..3f6b0ca4b 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -732,59 +732,48 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht } } -void net_shownames(entity selected, float teammate) +.float the_entnum; +// sendflags use: 1 = origin, 2 = health/armor, 0x80 = same team (includes health) +float SendEntity_ShowNames(entity to, float sendflags) { - float teammate_health, teammate_armor; - if(teammate) + WriteByte(MSG_ENTITY, ENT_CLIENT_SHOWNAMES); + //sendflags &= 127; + if(teams_matter && self.team == to.team) + sendflags |= 128; + else + sendflags &~= 2; + WriteByte(MSG_ENTITY, sendflags); + WriteByte(MSG_ENTITY, self.the_entnum); + if(sendflags & 1) { - teammate_health = selected.health; - teammate_armor = selected.armorvalue; + WriteShort(MSG_ENTITY, rint(self.origin_x)); + WriteShort(MSG_ENTITY, rint(self.origin_y)); + WriteShort(MSG_ENTITY, rint(self.origin_z)); } - - msg_entity = self; - WRITESPECTATABLE_MSG_ONE({ - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteByte(MSG_ONE, TE_CSQC_SHOWNAMES); - WriteString(MSG_ONE, playername(selected)); - WriteByte(MSG_ONE, teammate_health); - WriteByte(MSG_ONE, teammate_armor); - }); + if(sendflags & 2) + { + WriteByte(MSG_ENTITY, self.health); + WriteByte(MSG_ENTITY, self.armorvalue); + } + return TRUE; } -void UpdateSelectedPlayer() +void shownames_think() { - entity selected; - selected = world; - - if(!autocvar_sv_allow_shownames) - return; - - if(clienttype(self) != CLIENTTYPE_REAL) - return; - - if(self.cvar_cl_shownames == 0) - return; - - makevectors(self.v_angle); // sets v_forward - - // cursor trace - if(self.selected_player_display_timeout < time) + if(self.origin != self.owner.origin) { - WarpZone_crosshair_trace(self); - if(trace_ent && trace_ent.classname == "player" && !trace_ent.deadflag) - { - selected = trace_ent; - self.last_selected_player = selected; - self.selected_player_display_timeout = time + 0.1; // update at 0.1s intervals - } + setorigin(self, self.owner.origin); + self.SendFlags |= 1; } - - if(selected) - { - if(teams_matter && self.team == selected.team) - net_shownames(selected, 1); - else - net_shownames(selected, 0); + if(self.health != self.owner.health || self.armorvalue != self.owner.armorvalue) + { + self.health = self.owner.health; + self.armorvalue = self.owner.armorvalue; + self.SendFlags |= 2; + } + if(self.the_entnum != num_for_edict(self.owner)) + { + self.the_entnum = num_for_edict(self); } } diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 47f4a4aea..6cca99ab2 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -310,7 +310,6 @@ float default_weapon_alpha; .float cvar_cl_handicap; .float cvar_cl_playerdetailreduction; .float cvar_scr_centertime; -.float cvar_cl_shownames; .string cvar_g_xonoticversion; .string cvar_cl_weaponpriority; .string cvar_cl_weaponpriorities[10]; @@ -362,10 +361,6 @@ float W_AmmoItemCode(float wpn); float W_WeaponBit(float wpn); string W_Name(float weaponid); -void UpdateSelectedPlayer(); -.entity last_selected_player; -.float selected_player_display_timeout; // when the selection will time out - void FixIntermissionClient(entity e); void FixClientCvars(entity e); @@ -664,3 +659,6 @@ float serverflags; .entity muzzle_flash; .float misc_bulletcounter; // replaces uzi & hlac bullet counter. + +.entity shownames; +void shownames_think(); diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 84dd07d94..251bc5f3b 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -461,11 +461,6 @@ string formatmessage(string msg) replacement = cursor_ent.netname; if (!replacement || !cursor_ent) replacement = "nothing"; - } else if (escape == "p") { - if (self.last_selected_player) - replacement = self.last_selected_player.netname; - else - replacement = "(nobody)"; } else if (escape == "s") replacement = ftos(vlen(self.velocity - self.velocity_z * '0 0 1')); else if (escape == "S") @@ -586,7 +581,6 @@ void GetCvars(float f) GetCvars_handleFloat(s, f, autoswitch, "cl_autoswitch"); GetCvars_handleFloat(s, f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction"); GetCvars_handleFloat(s, f, cvar_scr_centertime, "scr_centertime"); - GetCvars_handleFloat(s, f, cvar_cl_shownames, "cl_shownames"); GetCvars_handleString(s, f, cvar_g_xonoticversion, "g_xonoticversion"); GetCvars_handleFloat(s, f, cvar_cl_handicap, "cl_handicap"); GetCvars_handleString_Fixup(s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);