From: terencehill Date: Tue, 2 Nov 2010 23:15:31 +0000 (+0100) Subject: Put the accuracy colors in an array and load them only when needed to reduce cvars... X-Git-Tag: xonotic-v0.1.0preview~134^2~6^2~17 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d0791096b36cd0cd9a5ed0876c6e10610c42d0cf;p=xonotic%2Fxonotic-data.pk3dir.git Put the accuracy colors in an array and load them only when needed to reduce cvars accesses --- diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index a29696751..dca5630fc 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -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 diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 0fff17d2e..f7c9c9fd0 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -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); diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 328a59036..b661e30ff 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -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; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 93aaf46c4..f6aaeed46 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -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);