- same procedure for the motorcycle - and again roughly 10% of the input code down.

This commit is contained in:
Christoph Oelckers 2020-07-16 19:16:56 +02:00
parent fca4bdcafb
commit ff9e2c3f5e
2 changed files with 90 additions and 78 deletions

View File

@ -682,9 +682,92 @@ enum
TURBOTURNTIME = (TICRATE/8) // 7
};
//---------------------------------------------------------------------------
//
// split out of playerinputboat for readability purposes and condensed using ?: operators
// split out of playerinputmotocycle for readability purposes and condensed using ?: operators
//
//---------------------------------------------------------------------------
int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, bool goback, double factor)
{
static int turnheldtime;
static int lastcontroltime;
int tics = totalclock - lastcontroltime;
lastcontroltime = totalclock;
if (p->MotoSpeed == 0 || !p->on_ground)
{
if (turnl)
{
p->TiltStatus -= (float)factor;
if (p->TiltStatus < -10)
p->TiltStatus = -10;
}
else if (turnr)
{
p->TiltStatus += (float)factor;
if (p->TiltStatus > 10)
p->TiltStatus = 10;
}
}
else
{
if (turnl || p->moto_drink < 0)
{
turnheldtime += tics;
p->TiltStatus -= (float)factor;
if (p->TiltStatus < -10)
p->TiltStatus = -10;
if (turnheldtime >= TURBOTURNTIME && p->MotoSpeed > 0)
{
if (goback) return bike_turn ? 20 : 10;
else return bike_turn ? -20 : -10;
}
else
{
if (goback) return bike_turn ? 10 : 3;
else return bike_turn ? -10 : -3;
}
}
else if (turnr || p->moto_drink > 0)
{
turnheldtime += tics;
p->TiltStatus += (float)factor;
if (p->TiltStatus > 10)
p->TiltStatus = 10;
if (turnheldtime >= TURBOTURNTIME && p->MotoSpeed > 0)
{
if (goback) return bike_turn ? -20 : -10;
else return bike_turn ? 20 : 10;
}
else
{
if (goback) return bike_turn ? -10 : -3;
else return bike_turn ? 10 : 3;
}
}
else
{
turnheldtime = 0;
if (p->TiltStatus > 0)
p->TiltStatus -= (float)factor;
else if (p->TiltStatus < 0)
p->TiltStatus += (float)factor;
if (fabs(p->TiltStatus) < 0.025)
p->TiltStatus = 0;
}
}
return 0;
}
//---------------------------------------------------------------------------
//
// same for the boat
//
//---------------------------------------------------------------------------

View File

@ -494,6 +494,8 @@ void P_GetInput(int const playerNum)
pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX));
}
int motoApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, bool goback, double factor);
void P_GetInputMotorcycle(int playerNum)
{
auto &thisPlayer = g_player[playerNum];
@ -585,84 +587,11 @@ void P_GetInputMotorcycle(int playerNum)
localInput.bits |= turnLeft << SK_AIM_DOWN;
localInput.bits |= turnRight << SK_LOOK_LEFT;
static int32_t turnHeldTime;
static int32_t lastInputClock; // MED
int32_t const elapsedTics = (int32_t)totalclock - lastInputClock;
int const moveBack = buttonMap.ButtonDown(gamefunc_Move_Backward) && pPlayer->MotoSpeed <= 0;
if (pPlayer->MotoSpeed == 0 || !pPlayer->on_ground)
{
if (turnLeft)
{
pPlayer->TiltStatus -= scaleAdjustmentToInterval(1);
if (pPlayer->TiltStatus < -10)
pPlayer->TiltStatus = -10;
}
else if (turnRight)
{
pPlayer->TiltStatus += scaleAdjustmentToInterval(1);
if (pPlayer->TiltStatus > 10)
pPlayer->TiltStatus = 10;
}
}
else
{
if (turnLeft || pPlayer->moto_drink < 0)
{
turnHeldTime += elapsedTics;
pPlayer->TiltStatus -= scaleAdjustmentToInterval(1);
if (pPlayer->TiltStatus < -10)
pPlayer->TiltStatus = -10;
if (turnHeldTime >= TURBOTURNTIME && pPlayer->MotoSpeed > 0)
{
if (moveBack)
input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 40 : 20)));
else
input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 40 : 20)));
}
else
{
if (moveBack)
input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 20 : 6)));
else
input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 20 : 6)));
}
}
else if (turnRight || pPlayer->moto_drink > 0)
{
turnHeldTime += elapsedTics;
pPlayer->TiltStatus += scaleAdjustmentToInterval(1);
if (pPlayer->TiltStatus > 10)
pPlayer->TiltStatus = 10;
if (turnHeldTime >= TURBOTURNTIME && pPlayer->MotoSpeed > 0)
{
if (moveBack)
input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 40 : 20)));
else
input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 40 : 20)));
}
else
{
if (moveBack)
input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 20 : 6)));
else
input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 20 : 6)));
}
}
else
{
turnHeldTime = 0;
if (pPlayer->TiltStatus > 0)
pPlayer->TiltStatus -= scaleAdjustmentToInterval(1);
else if (pPlayer->TiltStatus < 0)
pPlayer->TiltStatus += scaleAdjustmentToInterval(1);
}
}
if (pPlayer->TiltStatus > -0.025 && pPlayer->TiltStatus < 0.025)
pPlayer->TiltStatus = 0;
// turn is truncated to integer precision to avoid having micro-movement affect the result, which makes a significant difference here.
int turnvel = motoApplyTurn(pPlayer, turnLeft, turnRight, turn >> FRACBITS, moveBack, scaleAdjust);
input.q16avel += int(turnvel * scaleAdjust * FRACUNIT * 2);
if (pPlayer->moto_underwater)
{
@ -817,7 +746,7 @@ void P_GetInputBoat(int playerNum)
// turn is truncated to integer precision to avoid having micro-movement affect the result, which makes a significant difference here.
int turnvel = boatApplyTurn(pPlayer, turnLeft, turnRight, turn >> FRACBITS, scaleAdjust);
input.q16avel += int(turnvel * scaleAdjust * FRACUNIT);
input.q16avel += int(turnvel * scaleAdjust * FRACUNIT * 2);
input.fvel += pPlayer->MotoSpeed;
input.q16avel = fix16_mul(input.q16avel, avelScale);