From: terencehill Date: Fri, 18 Jan 2013 22:29:13 +0000 (+0100) Subject: Put accuracy colors code in external functions in miscfunctions.qc in order to avoid... X-Git-Tag: xonotic-v0.7.0~98^2~2 X-Git-Url: https://de.git.xonotic.org/?a=commitdiff_plain;h=c87ff55a126627adfa488f035b8943637ec403b8;p=xonotic%2Fxonotic-data.pk3dir.git Put accuracy colors code in external functions in miscfunctions.qc in order to avoid duplicate code. Make so that color cvars are read only every 2 seconds, not every frame. Also fix 100% weapon accuracy color displayed black instead of green in the scoreboard --- diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index d1c104058..55fc92e2b 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -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(); diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index b1d96028a..7c1e25664 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -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); } } diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 8c7557427..0da6ac5d0 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -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; diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index 6cceb42ba..9e5505b0a 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -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; +} + diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index af982ad46..ea54d0fbe 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -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); }