]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: simplify sonar string handling code
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sat, 4 Feb 2023 00:25:40 +0000 (01:25 +0100)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Tue, 4 Apr 2023 18:11:00 +0000 (20:11 +0200)
qcsrc/client/hud/panel/strafehud.qc

index edec4fb006b8acfe2f162f34a65be38a4b1b4c60..f6c23b682a94b8e48b29d89e04d3d533f51d7b5d 100644 (file)
@@ -902,25 +902,22 @@ 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(newsound == "")
                {
-                       if(cursound != "") strunzone(cursound);
-
-                       if(newsound != "") cursound = strzone(newsound);
-                       else cursound = string_null;
-
-                       if(sonarsound != "") strunzone(sonarsound);
-                       sonarsound = strzone(_Sound_fixpath(newsound));
+                       cursound = sonarsound = string_null;
+               }
+               else if(newsound != cursound)
+               {
+                       strfree(cursound);
+                       cursound = strzone(newsound);
 
-                       if(sonarsound != "")
+                       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
@@ -976,7 +973,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);
                        }
                }