]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize Weapons panel code by removing an unnecessary loop
authorterencehill <piuntn@gmail.com>
Sat, 19 Mar 2011 23:37:03 +0000 (00:37 +0100)
committerterencehill <piuntn@gmail.com>
Sat, 19 Mar 2011 23:37:03 +0000 (00:37 +0100)
Operation less per frame:
(4 comparisons + 3 add operations + 2 assignments) * weapon count

qcsrc/client/hud.qc

index 9252d5b5966973df82e0b1117e45ea578b0fed08..44a10eed1baa97de4be0ce4152bf792b0f91cb7c 100644 (file)
@@ -699,13 +699,6 @@ void HUD_Weapons(void)
        }
 
        float i, weapid, wpnalpha, weapon_cnt;
-       weapon_cnt = 0;
-       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-       {
-               self = get_weaponinfo(i);
-               if(self.impulse >= 0)
-                       ++weapon_cnt;
-       }
 
        // TODO make this configurable
        if(weaponorder_bypriority != autocvar_cl_weaponpriority)
@@ -729,6 +722,8 @@ void HUD_Weapons(void)
                                ++weapon_cnt;
                        }
                }
+               for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
+                       weaponorder[i] = NULL;
                heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
 
                weaponorder_cmp_str = string_null;
@@ -803,11 +798,13 @@ void HUD_Weapons(void)
 
        float weapons_st = getstati(STAT_WEAPONS);
 
-       for(i = 0; i < weapon_cnt; ++i)
+       for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
        {
+               self = weaponorder[i];
+               if (!self || self.impulse < 0)
+                       continue;
                wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
 
-               self = weaponorder[i];
                weapid = self.impulse;
 
                // draw background behind currently selected weapon
@@ -837,7 +834,7 @@ void HUD_Weapons(void)
                }
 
                // draw the weapon icon
-               if((weapid >= 0) && (weapons_st & self.weapons))
+               if(weapons_st & self.weapons)
                {
                        drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);