From 401236980c86090b31638487a52f50e235ef4ea0 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 18 Mar 2023 12:14:20 +1100 Subject: [PATCH] - Duke: Tidy up some unnecessarily deep branches in vehicle input code. --- source/games/duke/src/input.cpp | 191 +++++++++++++++----------------- 1 file changed, 88 insertions(+), 103 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 034fbd919..af6fd177c 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -570,60 +570,57 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons p->TiltStatus = 10; } } + else if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) + { + constexpr float velScale = (3.f / 10.f); + const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + + if (p->vehTurnLeft || p->moto_drink < 0) + { + p->TiltStatus -= (float)factor; + + if (p->TiltStatus < -10) + p->TiltStatus = -10; + + if (kbdLeft) + turnvel -= isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx < 0) + turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); + } + + if (p->vehTurnRight || p->moto_drink > 0) + { + p->TiltStatus += (float)factor; + + if (p->TiltStatus > 10) + p->TiltStatus = 10; + + if (kbdRight) + turnvel += isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx > 0) + turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); + } + } else { - if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) - { - constexpr float velScale = (3.f / 10.f); - const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN; + resetTurnHeldAmt(); - if (p->vehTurnLeft || p->moto_drink < 0) - { - p->TiltStatus -= (float)factor; - - if (p->TiltStatus < -10) - p->TiltStatus = -10; - - if (kbdLeft) - turnvel -= isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx < 0) - turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - - if (p->vehTurnRight || p->moto_drink > 0) - { - p->TiltStatus += (float)factor; - - if (p->TiltStatus > 10) - p->TiltStatus = 10; - - if (kbdRight) - turnvel += isTurboTurnTime() && p->MotoSpeed > 0 ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx > 0) - turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) - turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - } - else - { - resetTurnHeldAmt(); - - if (p->TiltStatus > 0) - p->TiltStatus -= (float)factor; - else if (p->TiltStatus < 0) - p->TiltStatus += (float)factor; - } + if (p->TiltStatus > 0) + p->TiltStatus -= (float)factor; + else if (p->TiltStatus < 0) + p->TiltStatus += (float)factor; } if (fabs(p->TiltStatus) < factor) @@ -643,63 +640,51 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons float turnvel = 0; p->oTiltStatus = p->TiltStatus; - if (p->MotoSpeed) + if (p->MotoSpeed && (p->vehTurnLeft || p->vehTurnRight || p->moto_drink)) { - if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) + const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); + const float baseVel = VEHICLETURN * velScale; + + if (p->vehTurnLeft || p->moto_drink < 0) { - const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f); - const float baseVel = VEHICLETURN * velScale; - - if (p->vehTurnLeft || p->moto_drink < 0) + if (!p->NotOnWater) { - if (!p->NotOnWater) - { - p->TiltStatus -= (float)factor; - if (p->TiltStatus < -10) - p->TiltStatus = -10; - } - - if (kbdLeft) - turnvel -= isTurboTurnTime() ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx < 0) - turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) - turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - - if (p->vehTurnRight || p->moto_drink > 0) - { - if (!p->NotOnWater) - { - p->TiltStatus += (float)factor; - if (p->TiltStatus > 10) - p->TiltStatus = 10; - } - - if (kbdRight) - turnvel += isTurboTurnTime() ? baseVel : baseVel * velScale; - - if (hidInput->mouseturnx > 0) - turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); - - if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) - turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; - - updateTurnHeldAmt(factor); - } - } - else if (!p->NotOnWater) - { - resetTurnHeldAmt(); - - if (p->TiltStatus > 0) p->TiltStatus -= (float)factor; - else if (p->TiltStatus < 0) + if (p->TiltStatus < -10) + p->TiltStatus = -10; + } + + if (kbdLeft) + turnvel -= isTurboTurnTime() ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx < 0) + turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] > 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); + } + + if (p->vehTurnRight || p->moto_drink > 0) + { + if (!p->NotOnWater) + { p->TiltStatus += (float)factor; + if (p->TiltStatus > 10) + p->TiltStatus = 10; + } + + if (kbdRight) + turnvel += isTurboTurnTime() ? baseVel : baseVel * velScale; + + if (hidInput->mouseturnx > 0) + turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f)); + + if (hidInput->joyaxes[JOYAXIS_Yaw] < 0) + turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw]; + + updateTurnHeldAmt(factor); } } else if (!p->NotOnWater)