From cfd17749a2860da607950c98409d99643398d64d Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Wed, 18 Jan 2023 13:11:43 +0100 Subject: [PATCH] Add patch from Juhu/strafehud-features branch: "strafehud: make sonar sound interval dynamic too" --- _hud_common.cfg | 3 ++- qcsrc/client/hud/panel/strafehud.qc | 37 +++++++++++++++-------------- qcsrc/client/hud/panel/strafehud.qh | 3 ++- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 827d405d4..6439c6662 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -202,7 +202,8 @@ seta hud_panel_strafehud_fps_update "0.5" "update interval (in seconds) of the f seta hud_panel_strafehud_sonar "0" "set to \"1\" to enable the strafe sonar" seta hud_panel_strafehud_sonar_audio "misc/talk" "audio to play for sonar" seta hud_panel_strafehud_sonar_start "0.5" "how optimal from 0 to 1 your strafing angle has to be for the strafe sonar to activate" -seta hud_panel_strafehud_sonar_interval "0.333333" "strafe sonar sound interval in seconds" +seta hud_panel_strafehud_sonar_interval_start "0.333333" "strafe sonar sound interval in seconds" +seta hud_panel_strafehud_sonar_interval_range "-0.222222" "dynamic sound interval range in seconds of the strafe sonar as you approach the optimal angle" seta hud_panel_strafehud_sonar_volume_start "0.333333" "sound volume of the strafe sonar" seta hud_panel_strafehud_sonar_volume_range "0.666666" "dynamic volume range of the strafe sonar as you approach the optimal angle" seta hud_panel_strafehud_sonar_pitch_start "0.9" "playback speed of the strafe sonar" diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 07f7cf140..c4e156457 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -872,27 +872,28 @@ void HUD_StrafeHUD() // reuse strafe ratio for strafe sonar static float sonar_time = 0; - bool sonar_ready = ((time - sonar_time) >= autocvar_hud_panel_strafehud_sonar_interval) || (sonar_time == 0); - if(autocvar_hud_panel_strafehud_sonar && sonar_ready) { - float sonar_start = bound(0, autocvar_hud_panel_strafehud_sonar_start, 1); - if(strafe_ratio >= sonar_start) { - sonar_time = time; - - float sonar_ratio = strafe_ratio - sonar_start; - if(sonar_start != 1) - sonar_ratio /= 1 - sonar_start; - else - sonar_ratio = 1; - float sonar_volume = bound(0, autocvar_hud_panel_strafehud_sonar_volume_start, 1); - sonar_volume += autocvar_hud_panel_strafehud_sonar_volume_range * sonar_ratio; + float sonar_start = bound(0, autocvar_hud_panel_strafehud_sonar_start, 1); + float sonar_ratio = strafe_ratio - sonar_start; + if(sonar_start != 1) + sonar_ratio /= 1 - sonar_start; + else + sonar_ratio = 1; - float sonar_pitch = max(0, autocvar_hud_panel_strafehud_sonar_pitch_start); - sonar_pitch += autocvar_hud_panel_strafehud_sonar_pitch_range * sonar_ratio; + float sonar_interval = max(0, autocvar_hud_panel_strafehud_sonar_interval_start); + sonar_interval += autocvar_hud_panel_strafehud_sonar_interval_range * sonar_ratio; + bool sonar_ready = (sonar_time == 0) || ((time - sonar_time) >= sonar_interval); + if(autocvar_hud_panel_strafehud_sonar && sonar_ready && (strafe_ratio >= sonar_start)) { + sonar_time = time; - if(sonar_volume > 0) { - sound7(csqcplayer, CH_INFO, sonarsound, bound(0, sonar_volume, 1) * VOL_BASE, ATTN_NONE, max(0.000001, sonar_pitch * 100), 0); - } + float sonar_volume = bound(0, autocvar_hud_panel_strafehud_sonar_volume_start, 1); + sonar_volume += autocvar_hud_panel_strafehud_sonar_volume_range * sonar_ratio; + + float sonar_pitch = max(0, autocvar_hud_panel_strafehud_sonar_pitch_start); + sonar_pitch += autocvar_hud_panel_strafehud_sonar_pitch_range * sonar_ratio; + + if(sonar_volume > 0) { + sound7(csqcplayer, CH_INFO, sonarsound, bound(0, sonar_volume, 1) * VOL_BASE, ATTN_NONE, max(0.000001, sonar_pitch * 100), 0); } } } diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 4dfff4507..5eaa93dbb 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -57,7 +57,8 @@ AUTOCVAR_SAVE(hud_panel_strafehud_fps_update, float, 0.5, "update interval (in s AUTOCVAR_SAVE(hud_panel_strafehud_sonar, bool, false, "set to \"1\" to enable the strafe sonar"); AUTOCVAR_SAVE(hud_panel_strafehud_sonar_audio, string, "misc/talk", "audio to play for sonar"); AUTOCVAR_SAVE(hud_panel_strafehud_sonar_start, float, 0.5, "how optimal from 0 to 1 your strafing angle has to be for the strafe sonar to activate"); -AUTOCVAR_SAVE(hud_panel_strafehud_sonar_interval, float, 0.333333, "strafe sonar sound interval in seconds"); +AUTOCVAR_SAVE(hud_panel_strafehud_sonar_interval_start, float, 0.333333, "strafe sonar sound interval in seconds"); +AUTOCVAR_SAVE(hud_panel_strafehud_sonar_interval_range, float, -0.222222, "dynamic sound interval range in seconds of the strafe sonar as you approach the optimal angle"); AUTOCVAR_SAVE(hud_panel_strafehud_sonar_volume_start, float, 0.333333, "sound volume of the strafe sonar"); AUTOCVAR_SAVE(hud_panel_strafehud_sonar_volume_range, float, 0.666666, "dynamic volume range of the strafe sonar as you approach the optimal angle"); AUTOCVAR_SAVE(hud_panel_strafehud_sonar_pitch_start, float, 0.9, "playback speed of the strafe sonar"); -- 2.39.2