Put the accuracy colors in an array and load them only when needed to reduce cvars...
authorterencehill <piuntn@gmail.com>
Tue, 2 Nov 2010 23:15:31 +0000 (00:15 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 2 Nov 2010 23:15:31 +0000 (00:15 +0100)
qcsrc/client/View.qc
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/scoreboard.qc

index a296967..dca5630 100644 (file)
@@ -1256,18 +1256,22 @@ void CSQC_common_hud(void)
                case HUD_NORMAL:
                        // do some accuracy var caching
                        float i;
-                       if(cvar_string("hud_panel_weapons_accuracy_color_levels") != acc_color_levels)
                        if(!(gametype == GAME_RACE || gametype == GAME_CTS))
                        {
-                               if(acc_color_levels)
-                                       strunzone(acc_color_levels);
-                               acc_color_levels = strzone(cvar_string("hud_panel_weapons_accuracy_color_levels"));
-                               acc_levels = tokenize(acc_color_levels);
-                               if (acc_levels > MAX_ACCURACY_LEVELS)
-                                       acc_levels = MAX_ACCURACY_LEVELS;
-
-                               for (i = 0; i < acc_levels; ++i)
-                                       acc_lev[i] = stof(argv(i));
+                               if(cvar_string("hud_panel_weapons_accuracy_color_levels") != acc_color_levels)
+                               {
+                                       if(acc_color_levels)
+                                               strunzone(acc_color_levels);
+                                       acc_color_levels = strzone(cvar_string("hud_panel_weapons_accuracy_color_levels"));
+                                       acc_levels = tokenize(acc_color_levels);
+                                       if (acc_levels > MAX_ACCURACY_LEVELS)
+                                               acc_levels = MAX_ACCURACY_LEVELS;
+
+                                       for (i = 0; i < acc_levels; ++i)
+                                               acc_lev[i] = stof(argv(i));
+                               }
+                               // let know that acc_col[] needs to be loaded
+                               acc_col_x[0] = -1;
                        }
 
                        HUD_Main(); // always run these functions for alpha checks
index 0fff17d..f7c9c9f 100644 (file)
@@ -1698,7 +1698,12 @@ void HUD_Weapons(void)
 
        float show_accuracy;
        if(cvar("hud_panel_weapons_accuracy") && acc_levels)
+       {
+               if (acc_col_x[0] == -1)
+                       for (i = 0; i < acc_levels; ++i)
+                               acc_col[i] = stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i))));
                show_accuracy = true;
+       }
        float label = cvar("hud_panel_weapons_label");
 
        for(i = 0; i < weapon_cnt; ++i)
@@ -1732,8 +1737,8 @@ void HUD_Weapons(void)
                        // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
                        float factor;
                        factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
-                       color = acc_color(j);
-                       color = color + factor * (acc_color(j+1) - color);
+                       color = acc_col[j];
+                       color = color + factor * (acc_col[j+1] - color);
 
                        if(weapon_damage)
                                drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
index 328a590..b661e30 100644 (file)
@@ -18,9 +18,9 @@ float scoreboard_bottom;
 float weapon_hits[WEP_MAXCOUNT];
 float weapon_fired[WEP_MAXCOUNT];
 
-#define acc_color(i) stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i))))
 #define MAX_ACCURACY_LEVELS 10
 float acc_lev[MAX_ACCURACY_LEVELS];
+vector acc_col[MAX_ACCURACY_LEVELS];
 float acc_levels;
 string acc_color_levels;
 
index 93aaf46..f6aaeed 100644 (file)
@@ -944,6 +944,9 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 
        if (!acc_levels)
                rgb = '1 1 1';
+       else if (acc_col_x[0] == -1)
+               for (i = 0; i < acc_levels; ++i)
+                       acc_col[i] = stov(cvar_string(strcat("hud_panel_weapons_accuracy_color", ftos(i))));
 
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
@@ -994,8 +997,8 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                                // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
                                float factor;
                                factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
-                               rgb = acc_color(j);
-                               rgb = rgb + factor * (acc_color(j+1) - rgb);
+                               rgb = acc_col[j];
+                               rgb = rgb + factor * (acc_col[j+1] - rgb);
                        }
 
                        drawstring(pos + '1 0 0' * padding + '0 1 0' * weapon_height, s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);