]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Put accuracy colors code in external functions in miscfunctions.qc in order to avoid...
authorterencehill <piuntn@gmail.com>
Fri, 18 Jan 2013 22:29:13 +0000 (23:29 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 5 Feb 2013 15:07:19 +0000 (16:07 +0100)
qcsrc/client/View.qc
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/miscfunctions.qc
qcsrc/client/scoreboard.qc

index d1c10405805f93f4135b3abba6bde4391ee968c2..55fc92e2b9b3ca95132c198ff61ee4191a574135 100644 (file)
@@ -1498,25 +1498,8 @@ void CSQC_UpdateView(float w, float h)
 
 void CSQC_common_hud(void)
 {
-    // do some accuracy var caching
-    float i;
-    if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
-    {
-        if(autocvar_accuracy_color_levels != acc_color_levels)
-        {
-            if(acc_color_levels)
-                strunzone(acc_color_levels);
-            acc_color_levels = strzone(autocvar_accuracy_color_levels);
-            acc_levels = tokenize_console(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)) / 100.0;
-        }
-        // let know that acc_col[] needs to be loaded
-        acc_col[0] = '-1 0 0';
-    }
+       if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS))
+               Accuracy_LoadLevels();
 
     HUD_Main(); // always run these functions for alpha checks
     HUD_DrawScoreboard();
index b1d96028a7995ecfeedd8909596bbeb781a13fe2..7c1e256642295be34e8768beaf745027e61a4371 100644 (file)
@@ -437,13 +437,13 @@ void HUD_Weapons(void)
        // declarations
        WEPSET_DECLARE_A(weapons_stat);
        WEPSET_COPY_AS(weapons_stat);
-       float i, f, a, j, factor;
+       float i, f, a;
        float screen_ar, center_x = 0, center_y;
        float weapon_count, weapon_id;
        float row, column, rows, columns;
        float aspect = autocvar_hud_panel_weapons_aspect;
 
-       float show_accuracy = false, panel_weapon_accuracy;
+       float panel_weapon_accuracy;
 
        float timeout = autocvar_hud_panel_weapons_timeout;
        float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
@@ -683,14 +683,8 @@ void HUD_Weapons(void)
                        baroffset_y = (weapon_size_y - barsize_y) / 2;
                }
        }
-
-       if(autocvar_hud_panel_weapons_accuracy && acc_levels)
-       {
-               show_accuracy = true;
-               if (acc_col[0] == '-1 0 0')
-                       for (i = 0; i < acc_levels; ++i)
-                               acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
-       }
+       if(autocvar_hud_panel_weapons_accuracy)
+               Accuracy_LoadColors();
 
        row = column = 0;
        for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
@@ -720,21 +714,12 @@ void HUD_Weapons(void)
                        drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 
                // draw the weapon accuracy
-               if(show_accuracy)
+               if(autocvar_hud_panel_weapons_accuracy)
                {
                        panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
                        if(panel_weapon_accuracy >= 0)
                        {
-                               // find the max level lower than weapon_accuracy
-                               j = acc_levels-1;
-                               while ( j && panel_weapon_accuracy < acc_lev[j] )
-                                       --j;
-
-                               // inject color j+1 in color j, how much depending on how much weapon_accuracy is higher than level j
-                               factor = (panel_weapon_accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
-                               color = acc_col[j];
-                               color = color + factor * (acc_col[j+1] - color);
-
+                               color = Accuracy_GetColor(panel_weapon_accuracy);
                                drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
                }
index 8c7557427ba095c6233b81f97b5e3ab636db8687..0da6ac5d087e5875bc3cc9efa5a66336593b35f6 100644 (file)
@@ -15,12 +15,6 @@ const float BORDER_MULTIPLIER = 0.25;
 float scoreboard_bottom;
 float weapon_accuracy[WEP_MAXCOUNT];
 
-#define MAX_ACCURACY_LEVELS 10
-float acc_lev[MAX_ACCURACY_LEVELS];
-vector acc_col[MAX_ACCURACY_LEVELS];
-float acc_levels;
-string acc_color_levels;
-
 float complain_weapon;
 string complain_weapon_name;
 float complain_weapon_type;
index 6cceb42bacda13964394e996318c8f37f0e8fb3f..9e5505b0a5bb5c47c0b1af68e5ff225623332985 100644 (file)
@@ -635,3 +635,61 @@ void draw_endBoldFont()
 {
        drawfont = FONT_USER+1;
 }
+
+
+#define MAX_ACCURACY_LEVELS 10
+float acc_lev[MAX_ACCURACY_LEVELS];
+vector acc_col[MAX_ACCURACY_LEVELS];
+float acc_col_loadtime;
+float acc_levels;
+string acc_color_levels;
+void Accuracy_LoadLevels()
+{
+       float i;
+       if(autocvar_accuracy_color_levels != acc_color_levels)
+       {
+               if(acc_color_levels)
+                       strunzone(acc_color_levels);
+               acc_color_levels = strzone(autocvar_accuracy_color_levels);
+               acc_levels = tokenize_console(acc_color_levels);
+               if(acc_levels > MAX_ACCURACY_LEVELS)
+                       acc_levels = MAX_ACCURACY_LEVELS;
+               if(acc_levels < 2)
+                       print("Warning: accuracy_color_levels must contain at least 2 values\n");
+
+               for(i = 0; i < acc_levels; ++i)
+                       acc_lev[i] = stof(argv(i)) / 100.0;
+       }
+}
+
+void Accuracy_LoadColors()
+{
+       float i;
+       if(time > acc_col_loadtime)
+       if(acc_levels >= 2)
+       {
+               for(i = 0; i < acc_levels; ++i)
+                       acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
+               acc_col_loadtime = time + 2;
+       }
+}
+
+vector Accuracy_GetColor(float accuracy)
+{
+       float j, factor;
+       vector color;
+       if(acc_levels < 2)
+               return '0 0 0'; // return black, can't determine the right color
+
+       // find the max level lower than acc
+       j = acc_levels-1;
+       while(j && accuracy < acc_lev[j])
+               --j;
+
+       // inject color j+1 in color j, how much depending on how much accuracy is higher than level j
+       factor = (accuracy - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
+       color = acc_col[j];
+       color = color + factor * (acc_col[j+1] - color);
+       return color;
+}
+
index af982ad46547bd4d2435e56f40e7e929b6d38723..ea54d0fbee38823a790acc86f74251d218025c63 100644 (file)
@@ -999,11 +999,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 
        float weapon_stats;
 
-       if (!acc_levels)
-               rgb = '1 1 1';
-       else if (acc_col[0] == '-1 0 0')
-               for (i = 0; i < acc_levels; ++i)
-                       acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
+       Accuracy_LoadColors();
 
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
@@ -1033,20 +1029,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        float padding;
                        padding = (weapon_width - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
 
-                       if (acc_levels)
-                       {
-                               // find the max level lower than weapon_stats
-                               float j;
-                               j = acc_levels-1;
-                               while ( j && weapon_stats < acc_lev[j] )
-                                       --j;
-
-                               // 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_col[j];
-                               rgb = rgb + factor * (acc_col[j+1] - rgb);
-                       }
+                       rgb = Accuracy_GetColor(weapon_stats);
 
                        drawstring(pos + '1 0 0' * padding + '0 1 0' * weapon_height, s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                }