]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Shownames: optimize
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 23 Nov 2015 05:18:45 +0000 (16:18 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 23 Nov 2015 05:25:30 +0000 (16:25 +1100)
qcsrc/client/shownames.qc

index 0dbffb8747fdda70a032fc4a5797df509ea0d63a..38c94ae9f171412325c53836fe47eee7acbc637d 100644 (file)
@@ -8,8 +8,6 @@
 
 #include "../lib/csqcmodel/cl_model.qh"
 
-entity shownames_ent[255];
-
 // self.isactive = player is in range and coordinates/status (health and armor) are up to date
 // self.origin = player origin
 // self.healthvalue
@@ -23,7 +21,6 @@ const float SHOWNAMES_FADESPEED = 4;
 const float SHOWNAMES_FADEDELAY = 0.4;
 void Draw_ShowNames(entity this)
 {
-       if (!autocvar_hud_shownames) return;
        if (this.sv_entnum == player_localentnum)  // self or spectatee
                if (!(autocvar_hud_shownames_self && autocvar_chase_active)) return;
        if (!this.sameteam && !autocvar_hud_shownames_enemies) return;
@@ -155,32 +152,39 @@ void Draw_ShowNames(entity this)
        }
 }
 
-void Draw_ShowNames_All()
+LinkedList shownames_ent;
+STATIC_INIT(shownames_ent)
 {
+       shownames_ent = LL_NEW();
        for (int i = 0; i < maxclients; ++i)
        {
-               entity e = shownames_ent[i];
-               if (!e)
-               {
-                       e = shownames_ent[i] = new(shownames_tag);
-                       e.sv_entnum = i + 1;
-               }
+               entity e = new(shownames_tag);
+               e.sv_entnum = i + 1;
+               LL_PUSH(shownames_ent, e);
+       }
+}
+
+void Draw_ShowNames_All()
+{
+       if (!autocvar_hud_shownames) return;
+       LL_EACH(shownames_ent, true, LAMBDA(
                entity entcs = entcs_receiver[i];
+               if (!entcs) continue;
                if (entcs.m_entcs_private)
                {
-                       e.healthvalue = entcs.healthvalue;
-                       e.armorvalue = entcs.armorvalue;
-                       e.sameteam = true;
+                       it.healthvalue = entcs.healthvalue;
+                       it.armorvalue = entcs.armorvalue;
+                       it.sameteam = true;
                }
                else
                {
-                       e.healthvalue = 0;
-                       e.armorvalue = 0;
-                       e.sameteam = false;
+                       it.healthvalue = 0;
+                       it.armorvalue = 0;
+                       it.sameteam = false;
                }
                bool dead = getplayerisdead(i);
-               if (!e.csqcmodel_isdead && entcs.has_origin) setorigin(e, entcs.origin);
-               e.csqcmodel_isdead = dead;
-               Draw_ShowNames(e);
-       }
+               if (!it.csqcmodel_isdead && entcs.has_origin) setorigin(it, entcs.origin);
+               it.csqcmodel_isdead = dead;
+               Draw_ShowNames(it);
+       ));
 }