From 6a5b085a50f28a620395ba830bbbd7139f7349f3 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sat, 4 Feb 2023 01:27:15 +0100 Subject: [PATCH] Add patch from Juhu/strafehud-features branch: "strafehud: simplify sonar string handling code" --- qcsrc/client/hud/panel/strafehud.qc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 1beb23bce..ec811bcc9 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -839,22 +839,19 @@ void HUD_StrafeHUD() string newsound = autocvar_hud_panel_strafehud_sonar_audio; static string cursound = string_null; static string sonarsound = string_null; - if(newsound != cursound) { - if(cursound != "") strunzone(cursound); - - if(newsound != "") cursound = strzone(newsound); - else cursound = string_null; - - if(sonarsound != "") strunzone(sonarsound); - sonarsound = strzone(_Sound_fixpath(newsound)); - - if(sonarsound != "") { + if(newsound == "") { + cursound = sonarsound = string_null; + } + else if(newsound != cursound) { + strfree(cursound); + cursound = strzone(newsound); + + strfree(sonarsound); + sonarsound = _Sound_fixpath(newsound); + if(sonarsound) { + sonarsound = strzone(sonarsound); precache_sound(sonarsound); } - else { - strunzone(sonarsound); - sonarsound = string_null; - } } // draw the actual strafe angle @@ -910,7 +907,7 @@ void HUD_StrafeHUD() float sonar_pitch = max(0, autocvar_hud_panel_strafehud_sonar_pitch_start); sonar_pitch += autocvar_hud_panel_strafehud_sonar_pitch_range * sonar_ratio ** max(1, autocvar_hud_panel_strafehud_sonar_pitch_exponent); - if(sonar_volume > 0) { + if(sonarsound && (sonar_volume > 0)) { sound7(csqcplayer, CH_INFO, sonarsound, bound(0, sonar_volume, 1) * VOL_BASE, ATTN_NONE, max(0.000001, sonar_pitch * 100), 0); } } -- 2.39.2