From: terencehill Date: Sat, 21 Mar 2020 13:25:40 +0000 (+0100) Subject: Put blink code in its own function X-Git-Tag: xonotic-v0.8.5~1144^2~8^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4e87bfcc805dfb9a76c37788ecdd860ec52305c4;p=xonotic%2Fxonotic-data.pk3dir.git Put blink code in its own function --- diff --git a/qcsrc/client/hud/panel/healtharmor.qc b/qcsrc/client/hud/panel/healtharmor.qc index 1dc0e52c0..9523be0e5 100644 --- a/qcsrc/client/hud/panel/healtharmor.qc +++ b/qcsrc/client/hud/panel/healtharmor.qc @@ -81,13 +81,10 @@ void HUD_HealthArmor() mySize -= '2 2 0' * panel_bg_padding; } - float BLINK_FACTOR = 0.5; - float BLINK_BASE = 0.5; - float BLINK_FREQ = 7; float air_alpha = 1; if (STAT(AIR_FINISHED) && time > STAT(AIR_FINISHED)) { - air_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); + air_alpha = blink(0.5, 0.5, 7); air_time = 10; } @@ -211,10 +208,7 @@ void HUD_HealthArmor() if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth) { - float BLINK_FACTOR = 0.15; - float BLINK_BASE = 0.85; - float BLINK_FREQ = 9; - pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); + pain_health_alpha = blink(0.85, 0.15, 9); } } HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL); diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index bb0bfe12c..2d0cf212d 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -214,6 +214,19 @@ vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float b return boxsize * (0.5 * (1 - sz)); } +// NOTE base is the central value +// freq: circle frequency, = 2*pi*frequency in hertz +float blink(float base, float range, float freq) +{ + // note: + // RMS = sqrt(base^2 + 0.5 * range^2) + // thus + // base = sqrt(RMS^2 - 0.5 * range^2) + // ensure RMS == 1 + + return base + range * cos(time * freq); +} + void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag) { vector line_dim = '0 0 0'; diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index d259efe66..56bb176ef 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -52,6 +52,8 @@ float expandingbox_sizefactor_from_fadelerp(float fadelerp); vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor); +float blink(float base, float range, float freq); + void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag); void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag); diff --git a/qcsrc/common/gamemodes/gamemode/ctf/cl_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/cl_ctf.qc index c82e0bce9..cbbe9afb7 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/cl_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/cl_ctf.qc @@ -69,15 +69,6 @@ void HUD_Mod_CTF(vector pos, vector mySize) X(neutral); #undef X - const float BLINK_FACTOR = 0.15; - const float BLINK_BASE = 0.85; - // note: - // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2) - // thus - // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2) - // ensure RMS == 1 - const float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz - #define X(team, cond) \ string team##_icon = string_null, team##_icon_prevstatus = string_null; \ int team##_alpha, team##_alpha_prevstatus; \ @@ -86,7 +77,7 @@ void HUD_Mod_CTF(vector pos, vector mySize) switch (team##flag) { \ case 1: team##_icon = "flag_" #team "_taken"; break; \ case 2: team##_icon = "flag_" #team "_lost"; break; \ - case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \ + case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = blink(0.85, 0.15, 5); break; \ default: \ if ((stat_items & CTF_SHIELDED) && (cond)) { \ team##_icon = "flag_" #team "_shielded"; \ @@ -98,7 +89,7 @@ void HUD_Mod_CTF(vector pos, vector mySize) switch (team##flag_prevstatus) { \ case 1: team##_icon_prevstatus = "flag_" #team "_taken"; break; \ case 2: team##_icon_prevstatus = "flag_" #team "_lost"; break; \ - case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \ + case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = blink(0.85, 0.15, 5); break; \ default: \ if (team##flag == 3) { \ team##_icon_prevstatus = "flag_" #team "_carrying"; /* make it more visible */\ diff --git a/qcsrc/common/gamemodes/gamemode/keepaway/cl_keepaway.qc b/qcsrc/common/gamemodes/gamemode/keepaway/cl_keepaway.qc index b2d087428..660a5511e 100644 --- a/qcsrc/common/gamemodes/gamemode/keepaway/cl_keepaway.qc +++ b/qcsrc/common/gamemodes/gamemode/keepaway/cl_keepaway.qc @@ -13,10 +13,7 @@ void HUD_Mod_Keepaway(vector pos, vector mySize) { mod_active = 1; // keepaway should always show the mod HUD - float BLINK_FACTOR = 0.15; - float BLINK_BASE = 0.85; - float BLINK_FREQ = 5; - float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); + float kaball_alpha = blink(0.85, 0.15, 5); int stat_items = STAT(ITEMS); int kaball = (stat_items/IT_KEY1) & 1; diff --git a/qcsrc/common/mutators/mutator/itemstime/itemstime.qc b/qcsrc/common/mutators/mutator/itemstime/itemstime.qc index 8d2bb318f..5add006c3 100644 --- a/qcsrc/common/mutators/mutator/itemstime/itemstime.qc +++ b/qcsrc/common/mutators/mutator/itemstime/itemstime.qc @@ -194,12 +194,7 @@ void DrawItemsTimeItem(vector myPos, vector mySize, float ar, string item_icon, if (autocvar_hud_panel_itemstime_hidespawned == 2) picalpha = 1; else if (item_available) - { - float BLINK_FACTOR = 0.15; - float BLINK_BASE = 0.85; - float BLINK_FREQ = 5; - picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); - } + picalpha = blink(0.85, 0.15, 5); else picalpha = 0.5; t = floor(item_time - time + 0.999);