From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Fri, 23 Sep 2022 13:03:57 +0000 (+0200) Subject: strafehud: improve turn timeout code X-Git-Tag: xonotic-v0.8.6~136^2~22 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ae578de72f873811eba27b5c2683d824ac53871f;p=xonotic%2Fxonotic-data.pk3dir.git strafehud: improve turn timeout code --- diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 191da7dae..34308f2f4 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -96,8 +96,6 @@ void HUD_StrafeHUD() static float turn_lasttime = 0; static bool turn = false; static float turnangle; - static float turnspeed; - static float turnaccel; static float dt_update = 0; static int dt_time = 0; static float dt_sum = 0; @@ -175,7 +173,7 @@ void HUD_StrafeHUD() if(onground_lasttime == 0) onground_expired = true; else - onground_expired = (time - onground_lasttime) >= autocvar_hud_panel_strafehud_timeout_ground; + onground_expired = (time - onground_lasttime) >= autocvar_hud_panel_strafehud_timeout_ground; // timeout for slick ramps if(!onground && !onground_expired) // if ground timeout hasn't expired yet use ground physics { @@ -343,43 +341,37 @@ void HUD_StrafeHUD() } else // air strafe only { - bool turn_expired = (time - turn_lasttime) >= autocvar_hud_panel_strafehud_timeout_turn; + bool turn_expired = (time - turn_lasttime) >= autocvar_hud_panel_strafehud_timeout_turn; // timeout for jumping with strafe keys only if(strafekeys) + turn = true; + else if(turn_expired) + turn = false; + + if(turn) // CPMA turning { - if(onground_expired) // timeout for slick ramps + if(strafekeys) { - turn = true; // CPMA turning turn_lasttime = time; turnangle = wishangle; - - // calculate the maximum air strafe speed and acceleration - float strafity = 1 - (90 - fabs(wishangle)) / 45; - - if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0) - { - maxspeed = min(maxspeed, GeomLerp(PHYS_MAXAIRSPEED(strafeplayer), strafity, PHYS_MAXAIRSTRAFESPEED(strafeplayer))); - } - turnspeed = movespeed = min(movespeed, maxspeed); - - if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0) - { - maxaccel = GeomLerp(PHYS_AIRACCELERATE(strafeplayer), strafity, PHYS_AIRSTRAFEACCELERATE(strafeplayer)); - } - turnaccel = maxaccel; } - } - else if(turn) - { - if(!turn_expired) // retain last state until strafe turning times out + else // retain last state until strafe turning times out { wishangle = turnangle; - movespeed = turnspeed; - maxaccel = turnaccel; } - else // timeout for jumping with strafe keys only + + // calculate the maximum air strafe speed and acceleration + float strafity = 1 - (90 - fabs(wishangle)) / 45; + + if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0) + { + maxspeed = min(maxspeed, GeomLerp(PHYS_MAXAIRSPEED(strafeplayer), strafity, PHYS_MAXAIRSTRAFESPEED(strafeplayer))); + } + movespeed = min(movespeed, maxspeed); + + if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0) { - turn = false; + maxaccel = GeomLerp(PHYS_AIRACCELERATE(strafeplayer), strafity, PHYS_AIRSTRAFEACCELERATE(strafeplayer)); } } }