]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
new implementation of shownames with MSG_ENTITY (broken currently)
authorFruitieX <fruitiex@gmail.com>
Mon, 11 Apr 2011 18:34:34 +0000 (21:34 +0300)
committerFruitieX <fruitiex@gmail.com>
Mon, 11 Apr 2011 18:34:34 +0000 (21:34 +0300)
qcsrc/client/Main.qc
qcsrc/common/constants.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc

index 6de1a872ed487acfd85f756a4bce37be3c709d6d..38025a56525d252ff46e4e320927582a4c19d98b 100644 (file)
@@ -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;
index 13c1bc824461ed93a12e786ba6998d7ac3ab10e0..bfe3dec49703df794916993d0be7e1257ff3f499 100644 (file)
@@ -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;
 
index 8135dded55b147f6abceb3af8c3317fe55aa2960..59baea3c315f04fea9860e743f52e4cbaea7bf05 100644 (file)
@@ -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;
index 84d090acc21e9eadc29d86e391612682f67770b6..3f6b0ca4b47979f8b7395fe89064a8b34bc069e4 100644 (file)
@@ -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);
     }
 }
 
index 47f4a4aea3c6038b6c4e2aeea582e2c8c35d3bb0..6cca99ab201c9b55b730ed17d2726b31e93e02b8 100644 (file)
@@ -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();
index 84dd07d94a185f3c065296f49cc3e2af6b79a017..251bc5f3b682e5a2f0a50f7ec76b06fdbc030eb3 100644 (file)
@@ -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);