From 206d65649e8a9d5c66a984d032d11043814b15b2 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 20 Mar 2011 00:37:03 +0100 Subject: [PATCH] Optimize Weapons panel code by removing an unnecessary loop Operation less per frame: (4 comparisons + 3 add operations + 2 assignments) * weapon count --- qcsrc/client/hud.qc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 9252d5b59..44a10eed1 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -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); -- 2.39.2