Repair vehicle input functions following changes to input handling.

- Calculate turnAmount in 1st 'if (turn)' statement to save on a 2nd.
- Divide all subsequent values from turAmount for cascasing effect.
- Rearrange some code to save on if statements checking the same condition.
- Remove q16horz code since player has no vertical movement on a vehicle.
- Remove horizAngleAdjust code as it's not necessary and has a jarring effect.
This commit is contained in:
Mitchell Richters 2020-03-21 08:46:06 +11:00 committed by Christoph Oelckers
parent fca147c83b
commit f1b7707f7a

View file

@ -3596,11 +3596,6 @@ void P_GetInputMotorcycle(int playerNum)
input.q16avel = fix16_sadd(input.q16avel, fix16_sdiv(fix16_from_int(info.mousex), F16(32)));
input.q16avel = fix16_sadd(input.q16avel, fix16_from_int(info.dyaw / analogExtent * (analogTurnAmount << 1)));
input.q16horz = fix16_sadd(input.q16horz, fix16_sdiv(fix16_from_int(info.mousey), F16(64)));
if (!in_mouseflip) input.q16horz = -input.q16horz;
input.q16horz = fix16_ssub(input.q16horz, fix16_from_int(info.dpitch * analogTurnAmount / analogExtent));
input.svel -= info.dx * keyMove / analogExtent;
input.fvel -= info.dz * keyMove / analogExtent;
@ -3645,27 +3640,24 @@ void P_GetInputMotorcycle(int playerNum)
localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2;
localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3;
int turnAmount;
int const turn = input.q16avel / 32;
int turnLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left);
int turnRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right);
int avelScale = F16((turnLeft || turnRight) ? 1 : 0);
if (turn)
{
turnAmount = 40;
avelScale = fix16_max(avelScale, fix16_clamp(fix16_mul(turn, turn),0,F16(1)));
if (turn < 0)
turnLeft = 1;
else if (turn > 0)
turnRight = 1;
}
else
turnAmount = 20;
input.svel = input.fvel = input.q16avel = input.q16horz = 0;
if (!pPlayer->moto_underwater)
{
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) << SK_JUMP;
localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Backward) << SK_AIM_UP;
localInput.bits |= buttonMap.ButtonDown(gamefunc_Run) << SK_CROUCH;
}
input.svel = input.fvel = input.q16avel = 0;
localInput.bits |= turnLeft << SK_AIM_DOWN;
localInput.bits |= turnRight << SK_LOOK_LEFT;
@ -3702,36 +3694,16 @@ void P_GetInputMotorcycle(int playerNum)
if (turnHeldTime >= TURBOTURNTIME && pPlayer->moto_speed > 0)
{
if (moveBack)
{
if (turn)
input.q16avel += fix16_from_int(20*2);
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(turnAmount)));
else
input.q16avel += fix16_from_int(10*2);
}
else
{
if (turn)
input.q16avel -= fix16_from_int(20*2);
else
input.q16avel -= fix16_from_int(10*2);
}
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(turnAmount)));
}
else
{
if (moveBack)
{
if (turn)
input.q16avel += fix16_from_int(10*2);
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 2.667))));
else
input.q16avel += fix16_from_int(3*2);
}
else
{
if (turn)
input.q16avel -= fix16_from_int(10*2);
else
input.q16avel -= fix16_from_int(3*2);
}
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 2.667))));
}
}
else if (turnRight || pPlayer->moto_drink > 0)
@ -3743,36 +3715,16 @@ void P_GetInputMotorcycle(int playerNum)
if (turnHeldTime >= TURBOTURNTIME && pPlayer->moto_speed > 0)
{
if (moveBack)
{
if (turn)
input.q16avel -= fix16_from_int(20*2);
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(turnAmount)));
else
input.q16avel -= fix16_from_int(10*2);
}
else
{
if (turn)
input.q16avel += fix16_from_int(20*2);
else
input.q16avel += fix16_from_int(10*2);
}
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(turnAmount)));
}
else
{
if (moveBack)
{
if (turn)
input.q16avel -= fix16_from_int(10*2);
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 2.667))));
else
input.q16avel -= fix16_from_int(3*2);
}
else
{
if (turn)
input.q16avel += fix16_from_int(10*2);
else
input.q16avel += fix16_from_int(3*2);
}
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 2.667))));
}
}
else
@ -3787,83 +3739,20 @@ void P_GetInputMotorcycle(int playerNum)
}
if (pPlayer->moto_underwater)
{
pPlayer->moto_speed = 0;
input.q16avel = fix16_mul(input.q16avel, avelScale);
input.fvel += pPlayer->moto_speed;
int const movementLocked = P_CheckLockedMovement(playerNum);
if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING)
{
if (ud.scrollmode && ud.overhead_on)
{
ud.folfvel = input.fvel;
ud.folavel = fix16_to_int(input.q16avel);
}
localInput.fvel = localInput.svel = 0;
localInput.q16avel = localInput.q16horz = 0;
}
else
{
if (!(movementLocked & IL_NOMOVE))
{
localInput.fvel = clamp(localInput.fvel + input.fvel, -15, 120);
localInput.svel = clamp(localInput.svel + input.svel, -MAXSVEL, MAXSVEL);
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) << SK_JUMP;
localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Backward) << SK_AIM_UP;
localInput.bits |= buttonMap.ButtonDown(gamefunc_Run) << SK_CROUCH;
}
if (!(movementLocked & IL_NOANGLE))
{
input.q16avel = fix16_mul(input.q16avel, avelScale);
localInput.q16avel = fix16_sadd(localInput.q16avel, input.q16avel);
pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel) & 0x7FFFFFF;
}
if (!(movementLocked & IL_NOHORIZ))
{
localInput.q16horz = fix16_clamp(fix16_sadd(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL));
pPlayer->q16horiz = fix16_clamp(fix16_sadd(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX));
}
}
// A horiz diff of 128 equal 45 degrees, so we convert horiz to 1024 angle units
if (thisPlayer.horizAngleAdjust)
{
float const horizAngle
= atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(thisPlayer.horizAngleAdjust);
pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f)));
}
else if (pPlayer->return_to_center > 0 || thisPlayer.horizRecenter)
{
pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(66.666) - fix16_sdiv(pPlayer->q16horiz, F16(1.5))))));
if ((!pPlayer->return_to_center && thisPlayer.horizRecenter) || (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1)))
{
pPlayer->q16horiz = F16(100);
thisPlayer.horizRecenter = false;
}
if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1))
pPlayer->q16horizoff = 0;
}
if (pPlayer->q16horizoff > 0)
{
pPlayer->q16horizoff = fix16_ssub(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((pPlayer->q16horizoff >> 3) + fix16_one))));
pPlayer->q16horizoff = fix16_max(pPlayer->q16horizoff, 0);
}
else if (pPlayer->q16horizoff < 0)
{
pPlayer->q16horizoff = fix16_sadd(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((-pPlayer->q16horizoff >> 3) + fix16_one))));
pPlayer->q16horizoff = fix16_min(pPlayer->q16horizoff, 0);
}
if (thisPlayer.horizSkew)
pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(thisPlayer.horizSkew))));
pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX));
localInput.fvel = clamp(localInput.fvel + (input.fvel += pPlayer->moto_speed), -(MAXVEL / 8), (MAXVEL * 1.333));
if (TEST_SYNC_KEY(localInput.bits, SK_JUMP))
{
@ -3913,11 +3802,6 @@ void P_GetInputBoat(int playerNum)
input.q16avel = fix16_sadd(input.q16avel, fix16_sdiv(fix16_from_int(info.mousex), F16(32)));
input.q16avel = fix16_sadd(input.q16avel, fix16_from_int(info.dyaw / analogExtent * (analogTurnAmount << 1)));
input.q16horz = fix16_sadd(input.q16horz, fix16_sdiv(fix16_from_int(info.mousey), F16(64)));
if (!in_mouseflip) input.q16horz = -input.q16horz;
input.q16horz = fix16_ssub(input.q16horz, fix16_from_int(info.dpitch * analogTurnAmount / analogExtent));
input.svel -= info.dx * keyMove / analogExtent;
input.fvel -= info.dz * keyMove / analogExtent;
@ -3962,20 +3846,24 @@ void P_GetInputBoat(int playerNum)
localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2;
localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3;
int turnAmount;
int const turn = input.q16avel / 32;
int turnLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left);
int turnRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right);
int avelScale = F16((turnLeft || turnRight) ? 1 : 0);
if (turn)
{
turnAmount = 48;
avelScale = fix16_max(avelScale, fix16_clamp(fix16_mul(turn, turn),0,F16(1)));
if (turn < 0)
turnLeft = 1;
else if (turn > 0)
turnRight = 1;
}
else
turnAmount = 24;
input.svel = input.fvel = input.q16avel = input.q16horz = 0;
input.svel = input.fvel = input.q16avel = 0;
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) << SK_JUMP;
localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Backward) << SK_AIM_UP;
@ -3998,41 +3886,16 @@ void P_GetInputBoat(int playerNum)
pPlayer->tilt_status--;
if (pPlayer->tilt_status < -10)
pPlayer->tilt_status = -10;
}
if (turnHeldTime >= TURBOTURNTIME)
{
if (pPlayer->not_on_water)
{
if (turn)
input.q16avel -= fix16_from_int(6*2);
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(turnAmount)));
else
input.q16avel -= fix16_from_int(3*2);
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 3.333))));
}
else
{
if (turn)
input.q16avel -= fix16_from_int(20*2);
if (turnHeldTime >= TURBOTURNTIME)
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 3))));
else
input.q16avel -= fix16_from_int(10*2);
}
}
else
{
if (pPlayer->not_on_water)
{
if (turn)
input.q16avel -= fix16_from_int(2*2);
else
input.q16avel -= fix16_from_int(1*2);
}
else
{
if (turn)
input.q16avel -= fix16_from_int(6*2);
else
input.q16avel -= fix16_from_int(3*2);
}
}
input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(((turnAmount / 3.333) / 3))));
}
else if (turnRight || pPlayer->moto_drink > 0)
{
@ -4042,41 +3905,16 @@ void P_GetInputBoat(int playerNum)
pPlayer->tilt_status++;
if (pPlayer->tilt_status > 10)
pPlayer->tilt_status = 10;
}
if (turnHeldTime >= TURBOTURNTIME)
{
if (pPlayer->not_on_water)
{
if (turn)
input.q16avel += fix16_from_int(6*2);
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(turnAmount)));
else
input.q16avel += fix16_from_int(3*2);
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 3.333))));
}
else
{
if (turn)
input.q16avel += fix16_from_int(20*2);
if (turnHeldTime >= TURBOTURNTIME)
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnAmount / 3))));
else
input.q16avel += fix16_from_int(10*2);
}
}
else
{
if (pPlayer->not_on_water)
{
if (turn)
input.q16avel += fix16_from_int(2*2);
else
input.q16avel += fix16_from_int(1*2);
}
else
{
if (turn)
input.q16avel += fix16_from_int(6*2);
else
input.q16avel += fix16_from_int(3*2);
}
}
input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval(((turnAmount / 3.333) / 3))));
}
else if (!pPlayer->not_on_water)
{
@ -4098,82 +3936,10 @@ void P_GetInputBoat(int playerNum)
pPlayer->tilt_status++;
}
input.fvel += pPlayer->moto_speed;
input.q16avel = fix16_mul(input.q16avel, avelScale);
int const movementLocked = P_CheckLockedMovement(playerNum);
if ((ud.scrollmode && ud.overhead_on) || (movementLocked & IL_NOTHING) == IL_NOTHING)
{
if (ud.scrollmode && ud.overhead_on)
{
ud.folfvel = input.fvel;
ud.folavel = fix16_to_int(input.q16avel);
}
localInput.fvel = localInput.svel = 0;
localInput.q16avel = localInput.q16horz = 0;
}
else
{
if (!(movementLocked & IL_NOMOVE))
{
localInput.fvel = clamp(localInput.fvel + input.fvel, -15, 120);
localInput.svel = clamp(localInput.svel + input.svel, -MAXSVEL, MAXSVEL);
}
if (!(movementLocked & IL_NOANGLE))
{
localInput.q16avel = fix16_sadd(localInput.q16avel, input.q16avel);
pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel) & 0x7FFFFFF;
}
if (!(movementLocked & IL_NOHORIZ))
{
localInput.q16horz = fix16_clamp(fix16_sadd(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL));
pPlayer->q16horiz = fix16_clamp(fix16_sadd(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX));
}
}
// A horiz diff of 128 equal 45 degrees,
// so we convert horiz to 1024 angle units
if (thisPlayer.horizAngleAdjust)
{
float const horizAngle
= atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(thisPlayer.horizAngleAdjust);
pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f)));
}
else if (pPlayer->return_to_center > 0 || thisPlayer.horizRecenter)
{
pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(66.666) - fix16_sdiv(pPlayer->q16horiz, F16(1.5))))));
if ((!pPlayer->return_to_center && thisPlayer.horizRecenter) || (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1)))
{
pPlayer->q16horiz = F16(100);
thisPlayer.horizRecenter = false;
}
if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1))
pPlayer->q16horizoff = 0;
}
if (pPlayer->q16horizoff > 0)
{
pPlayer->q16horizoff = fix16_ssub(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((pPlayer->q16horizoff >> 3) + fix16_one))));
pPlayer->q16horizoff = fix16_max(pPlayer->q16horizoff, 0);
}
else if (pPlayer->q16horizoff < 0)
{
pPlayer->q16horizoff = fix16_sadd(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((-pPlayer->q16horizoff >> 3) + fix16_one))));
pPlayer->q16horizoff = fix16_min(pPlayer->q16horizoff, 0);
}
if (thisPlayer.horizSkew)
pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(thisPlayer.horizSkew))));
pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX));
localInput.fvel = clamp(localInput.fvel + (input.fvel += pPlayer->moto_speed), -15, 120);
}
int dword_A99D4, dword_A99D8, dword_A99DC, dword_A99E0;