From 655ec2c4347b6b160b583048d3c0643db08d2999 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sun, 15 Jan 2023 12:47:09 +0100 Subject: [PATCH] Add patch from Juhu/strafehud-features branch: "strafehud: add audible feedback to strafehud (strafe sonar)" --- _hud_common.cfg | 8 +++++ qcsrc/client/hud/panel/strafehud.qc | 47 +++++++++++++++++++++++++++++ qcsrc/client/hud/panel/strafehud.qh | 8 +++++ 3 files changed, 63 insertions(+) diff --git a/_hud_common.cfg b/_hud_common.cfg index 0089d5063..827d405d4 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -199,6 +199,14 @@ seta hud_panel_strafehud_timeout_ground "0.1" "time (in seconds) after take off seta hud_panel_strafehud_timeout_turn "0.1" "time (in seconds) after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)" seta hud_panel_strafehud_antiflicker_angle "0.01" "how many degrees from 0° to 180° the hud ignores if it could cause visual disturbances otherwise (and to counter rounding errors)" seta hud_panel_strafehud_fps_update "0.5" "update interval (in seconds) of the frametime to calculate the optimal angle, smaller values may cause flickering" +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_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" +seta hud_panel_strafehud_sonar_pitch_range "0.1" "dynamic playback speed range of the strafe sonar as you approach the optimal angle" // hud panel aliases alias quickmenu "cl_cmd hud quickmenu ${* ?}" diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 1d5e84ba8..323a80066 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -808,6 +808,27 @@ void HUD_StrafeHUD() drawfill(panel_pos + eX * (indicator_direction ? 0 : panel_size.x - direction_size_horizontal.x) + eY * panel_size.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, autocvar_hud_panel_strafehud_direction_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } + 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 != "") { + precache_sound(sonarsound); + } + else { + strunzone(sonarsound); + sonarsound = string_null; + } + } + // draw the actual strafe angle if(!immobile) { float moveangle = fabs(angle + wishangle); @@ -838,6 +859,32 @@ void HUD_StrafeHUD() { currentangle_color = StrafeHUD_mixColors(autocvar_hud_panel_strafehud_angle_neutral_color, currentangle_color, fabs(strafe_ratio)); } + + // 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_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); + } + } + } } if(mode == STRAFEHUD_MODE_VIEW_CENTERED || straight_overturn) diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 28ee51b23..0571c05bc 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -54,6 +54,14 @@ AUTOCVAR_SAVE(hud_panel_strafehud_timeout_ground, float, 0.1, "time (in seconds) AUTOCVAR_SAVE(hud_panel_strafehud_timeout_turn, float, 0.1, "time (in seconds) after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)"); AUTOCVAR_SAVE(hud_panel_strafehud_antiflicker_angle, float, 0.01, "how many degrees from 0° to 180° the hud ignores if it could cause visual disturbances otherwise (and to counter rounding errors)"); AUTOCVAR_SAVE(hud_panel_strafehud_fps_update, float, 0.5, "update interval (in seconds) of the frametime to calculate the optimal angle, smaller values may cause flickering"); +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_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"); +AUTOCVAR_SAVE(hud_panel_strafehud_sonar_pitch_range, float, 0.1, "dynamic playback speed range of the strafe sonar as you approach the optimal angle"); void HUD_Panel_DrawStrafeHUD(float, float, float, vector, float, int, int); vector StrafeHUD_mixColors(vector, vector, float); -- 2.39.2