- Duke/RR: Remove vehForward/Reverse variables from player struct.

* Back in 2020, I was trying to tidy stuff up and had no idea about network awareness, etc.
* The original game misused network bits here, however I don't see why the player's angle can't just be tested for signedness. Again, something I didn't see way back when...
This commit is contained in:
Mitchell Richters 2023-03-19 20:42:12 +11:00
parent 37e9cfed45
commit 81650036e6
7 changed files with 40 additions and 58 deletions

View file

@ -94,7 +94,6 @@ void GameInterface::Ticker()
p->pals.a--;
hud_input(i);
processinputvel(i);
fi.processinput(i);
fi.checksectors(i);
}

View file

@ -502,36 +502,6 @@ void hud_input(int plnum)
}
}
//---------------------------------------------------------------------------
//
// Main input routine.
// This includes several input improvements from EDuke32, but this code
// has been mostly rewritten completely to make it clearer and reduce redundancy.
//
//---------------------------------------------------------------------------
#if 0
enum
{
TURBOTURNTIME = (TICRATE/8), // 7
NORMALTURN = 15,
PREAMBLETURN = 5,
NORMALKEYMOVE = 40,
MAXVEL = ((NORMALKEYMOVE*2)+10),
MAXSVEL = ((NORMALKEYMOVE*2)+10),
MAXANGVEL = 1024, // 127
MAXHORIZVEL = 256, // 127
};
#endif
enum
{
MAXVELMOTO = 120,
};
static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f);
//---------------------------------------------------------------------------
//
// split out for readability
@ -608,6 +578,7 @@ static float getVehicleTurnVel(player_struct* p, HIDInput* const hidInput, const
static void processVehicleInput(player_struct *p, HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust)
{
static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f);
float baseVel, velScale;
// mask out all actions not compatible with vehicles.
@ -616,8 +587,9 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu
if (p->OnBoat || !p->moto_underwater)
{
p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->joyaxes[JOYAXIS_Forward], 1.f);
p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->joyaxes[JOYAXIS_Forward], 1.f);
const bool kbdForwards = buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe);
const bool kbdBackward = buttonMap.ButtonDown(gamefunc_Move_Backward);
inputBuffer->fvel = clamp(kbdForwards - kbdBackward + hidInput->joyaxes[JOYAXIS_Forward], -1.f, 1.f);
if (buttonMap.ButtonDown(gamefunc_Run))
inputBuffer->actions |= SB_CROUCH;
@ -627,7 +599,6 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu
{
velScale = (3.f / 10.f);
baseVel = VEHICLETURN * Sgn(p->MotoSpeed);
if (p->moto_underwater) p->MotoSpeed = 0;
}
else
{
@ -635,7 +606,6 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu
baseVel = VEHICLETURN * velScale;
}
inputBuffer->fvel = clamp<float>((float)p->MotoSpeed, -(MAXVELMOTO >> 3), MAXVELMOTO) * (1.f / 40.f);
inputBuffer->avel += (currInput->avel = getVehicleTurnVel(p, hidInput, (float)scaleAdjust, baseVel, velScale));
}

View file

@ -2600,6 +2600,7 @@ void processinput_d(int snum)
ESyncBits& actions = p->sync.actions;
processinputvel(snum);
auto sb_fvel = PlayerInputForwardVel(snum);
auto sb_svel = PlayerInputSideVel(snum);

View file

@ -1471,8 +1471,14 @@ static void onMotorcycle(int snum, ESyncBits &actions)
int rng;
if (p->MotoSpeed < 0)
{
p->MotoSpeed = 0;
p->sync.fvel = 0;
}
const auto oldMotoSpeed = clamp<float>((float)p->MotoSpeed, -15.f, 120.f) * (1.f / 40.f);
bool forward = p->sync.fvel > 0;
bool reverse = p->sync.fvel < 0;
bool turnLeft = p->sync.avel < 0;
bool turnRight = p->sync.avel > 0;
@ -1481,7 +1487,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
actions &= ~SB_CROUCH;
}
if (p->vehForwardScale != 0)
if (forward != 0)
{
if (p->on_ground)
{
@ -1551,7 +1557,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
p->VBumpTarget = -30;
p->moto_do_bump = 1;
}
else if (p->vehForwardScale != 0 && !braking)
else if (forward && !braking)
{
if (p->MotoSpeed < 40)
{
@ -1559,8 +1565,8 @@ static void onMotorcycle(int snum, ESyncBits &actions)
p->moto_bump_fast = 1;
}
p->MotoSpeed += 2 * p->vehForwardScale;
p->vehForwardScale = 0;
p->MotoSpeed += 2 * p->sync.fvel;
forward = false;
if (p->MotoSpeed > 120)
p->MotoSpeed = 120;
@ -1577,13 +1583,13 @@ static void onMotorcycle(int snum, ESyncBits &actions)
p->moto_do_bump = 0;
}
if (p->vehReverseScale != 0 && p->MotoSpeed <= 0 && !braking)
if (reverse && p->MotoSpeed <= 0 && !braking)
{
bool temp = turnRight;
turnRight = turnLeft;
turnLeft = temp;
p->MotoSpeed = -15 * p->vehReverseScale;
p->vehReverseScale = 0;
p->MotoSpeed = 15.f * p->sync.fvel;
reverse = false;
}
}
if (p->MotoSpeed != 0 && p->on_ground == 1)
@ -1699,6 +1705,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
}
p->moto_on_mud = p->moto_on_oil = 0;
p->sync.fvel = oldMotoSpeed;
}
//---------------------------------------------------------------------------
@ -1715,6 +1722,9 @@ static void onBoat(int snum, ESyncBits &actions)
bool braking = false, heeltoe = false;
int rng;
const auto oldMotoSpeed = clamp<float>((float)p->MotoSpeed, -15.f, 120.f) * (1.f / 40.f);
bool forward = p->sync.fvel > 0;
bool reverse = p->sync.fvel < 0;
bool turnLeft = p->sync.avel < 0;
bool turnRight = p->sync.avel > 0;
@ -1735,13 +1745,13 @@ static void onBoat(int snum, ESyncBits &actions)
if (p->MotoSpeed < 0)
p->MotoSpeed = 0;
if ((actions & SB_CROUCH) && (p->vehForwardScale != 0))
if ((actions & SB_CROUCH) && forward)
{
heeltoe = true;
p->vehForwardScale = 0;
forward = false;
}
if (p->vehForwardScale != 0)
if (forward)
{
if (p->MotoSpeed == 0 && !S_CheckActorSoundPlaying(pact, 89))
{
@ -1830,15 +1840,15 @@ static void onBoat(int snum, ESyncBits &actions)
p->VBumpTarget = 30;
p->moto_do_bump = 1;
}
else if (p->vehForwardScale != 0)
else if (forward)
{
if (p->MotoSpeed < 40 && !p->NotOnWater)
{
p->VBumpTarget = -30;
p->moto_bump_fast = 1;
}
p->MotoSpeed += 1 * p->vehForwardScale;
p->vehForwardScale = 0;
p->MotoSpeed += 1 * p->sync.fvel;
forward = false;
if (p->MotoSpeed > 120)
p->MotoSpeed = 120;
}
@ -1851,13 +1861,13 @@ static void onBoat(int snum, ESyncBits &actions)
p->moto_do_bump = 0;
}
if (p->vehReverseScale != 0 && p->MotoSpeed == 0 && !braking)
if (reverse && p->MotoSpeed == 0 && !braking)
{
bool temp = turnRight;
turnRight = turnLeft;
turnLeft = temp;
p->MotoSpeed = -(!p->NotOnWater ? 25 : 20) * p->vehReverseScale;
p->vehReverseScale = 0;
p->MotoSpeed = (!p->NotOnWater ? 25 : 20) * p->sync.fvel;
reverse = false;
}
}
if (p->MotoSpeed != 0 && p->on_ground == 1)
@ -1938,6 +1948,8 @@ static void onBoat(int snum, ESyncBits &actions)
}
if (p->NotOnWater && p->MotoSpeed > 50)
p->MotoSpeed -= (p->MotoSpeed / 2.);
p->sync.fvel = oldMotoSpeed;
}
//---------------------------------------------------------------------------
@ -3197,9 +3209,6 @@ void processinput_r(int snum)
ESyncBits& actions = p->sync.actions;
auto sb_fvel = PlayerInputForwardVel(snum);
auto sb_svel = PlayerInputSideVel(snum);
auto psectp = p->cursector;
if (p->OnMotorcycle && pact->spr.extra > 0)
{
@ -3209,6 +3218,11 @@ void processinput_r(int snum)
{
onBoat(snum, actions);
}
processinputvel(snum);
auto sb_fvel = PlayerInputForwardVel(snum);
auto sb_svel = PlayerInputSideVel(snum);
if (psectp == nullptr)
{
if (pact->spr.extra > 0 && ud.clipping == 0)

View file

@ -308,7 +308,7 @@ struct player_struct
uint8_t hurt_delay2, nocheat;
uint8_t OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround;
uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud;
double vehForwardScale, vehReverseScale, MotoSpeed;
double MotoSpeed;
TArray<GameVarValue> uservars;

View file

@ -941,8 +941,6 @@ DEFINE_FIELD_X(DukePlayer, player_struct, moto_do_bump)
DEFINE_FIELD_X(DukePlayer, player_struct, moto_bump_fast)
DEFINE_FIELD_X(DukePlayer, player_struct, moto_on_oil)
DEFINE_FIELD_X(DukePlayer, player_struct, moto_on_mud)
DEFINE_FIELD_X(DukePlayer, player_struct, vehForwardScale)
DEFINE_FIELD_X(DukePlayer, player_struct, vehReverseScale)
DEFINE_FIELD_X(DukePlayer, player_struct, MotoSpeed)
DEFINE_FIELD_X(DukePlayer, player_struct, holoduke_on)
DEFINE_FIELD_X(DukePlayer, player_struct, actorsqu)

View file

@ -334,7 +334,7 @@ struct DukePlayer native
native uint8 hurt_delay2, nocheat;
native uint8 OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround;
native uint8 moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud;
native double vehForwardScale, vehReverseScale, MotoSpeed;
native double MotoSpeed;
// input stuff.
//InputPacket sync;