- Duke: Tidy up some unnecessarily deep branches in vehicle input code.

This commit is contained in:
Mitchell Richters 2023-03-18 12:14:20 +11:00
parent 51a20211f3
commit 401236980c

View file

@ -570,60 +570,57 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
p->TiltStatus = 10; 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 else
{ {
if (p->vehTurnLeft || p->vehTurnRight || p->moto_drink) resetTurnHeldAmt();
{
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) if (p->TiltStatus > 0)
{ p->TiltStatus -= (float)factor;
p->TiltStatus -= (float)factor; else if (p->TiltStatus < 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 (fabs(p->TiltStatus) < factor) if (fabs(p->TiltStatus) < factor)
@ -643,63 +640,51 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
float turnvel = 0; float turnvel = 0;
p->oTiltStatus = p->TiltStatus; 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); if (!p->NotOnWater)
const float baseVel = VEHICLETURN * velScale;
if (p->vehTurnLeft || p->moto_drink < 0)
{ {
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; 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; 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) else if (!p->NotOnWater)