- Internalise player InputPacket access.

This commit is contained in:
Mitchell Richters 2023-10-29 19:50:25 +11:00 committed by Christoph Oelckers
parent 531c95c7ca
commit ce75f7d7ef
8 changed files with 51 additions and 52 deletions

View file

@ -68,40 +68,40 @@ CUSTOM_CVAR(Int, cl_viewtilting, 0, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void DCorePlayer::doPitchInput(InputPacket* const input) void DCorePlayer::doPitchInput()
{ {
// Add player's mouse/device input. // Add player's mouse/device input.
if (input->ang.Pitch.Degrees()) if (cmd.ucmd.ang.Pitch.Degrees())
{ {
actor->spr.Angles.Pitch += input->ang.Pitch * gameInput.SyncInput(); actor->spr.Angles.Pitch += cmd.ucmd.ang.Pitch * gameInput.SyncInput();
input->actions &= ~SB_CENTERVIEW; cmd.ucmd.actions &= ~SB_CENTERVIEW;
} }
// Set up a myriad of bools. // Set up a myriad of bools.
const auto aimingUp = (input->actions & SB_LOOK_UP) == SB_AIM_UP; const auto aimingUp = (cmd.ucmd.actions & SB_LOOK_UP) == SB_AIM_UP;
const auto aimingDown = (input->actions & SB_LOOK_DOWN) == SB_AIM_DOWN; const auto aimingDown = (cmd.ucmd.actions & SB_LOOK_DOWN) == SB_AIM_DOWN;
const auto lookingUp = (input->actions & SB_LOOK_UP) == SB_LOOK_UP; const auto lookingUp = (cmd.ucmd.actions & SB_LOOK_UP) == SB_LOOK_UP;
const auto lookingDown = (input->actions & SB_LOOK_DOWN) == SB_LOOK_DOWN; const auto lookingDown = (cmd.ucmd.actions & SB_LOOK_DOWN) == SB_LOOK_DOWN;
// Process keyboard input. // Process keyboard input.
if (const auto aiming = aimingDown - aimingUp) if (const auto aiming = aimingDown - aimingUp)
{ {
actor->spr.Angles.Pitch += getTicrateAngle(PITCH_AIMSPEED * aiming); actor->spr.Angles.Pitch += getTicrateAngle(PITCH_AIMSPEED * aiming);
input->actions &= ~SB_CENTERVIEW; cmd.ucmd.actions &= ~SB_CENTERVIEW;
} }
if (const auto looking = lookingDown - lookingUp) if (const auto looking = lookingDown - lookingUp)
{ {
actor->spr.Angles.Pitch += getTicrateAngle(PITCH_LOOKSPEED * looking); actor->spr.Angles.Pitch += getTicrateAngle(PITCH_LOOKSPEED * looking);
input->actions |= SB_CENTERVIEW; cmd.ucmd.actions |= SB_CENTERVIEW;
} }
// Do return to centre. // Do return to centre.
if ((input->actions & SB_CENTERVIEW) && !(lookingUp || lookingDown)) if ((cmd.ucmd.actions & SB_CENTERVIEW) && !(lookingUp || lookingDown))
{ {
const auto pitch = abs(actor->spr.Angles.Pitch); const auto pitch = abs(actor->spr.Angles.Pitch);
const auto scale = pitch > PITCH_CNTRSINEOFFSET ? (pitch - PITCH_CNTRSINEOFFSET).Cos() : 1.; const auto scale = pitch > PITCH_CNTRSINEOFFSET ? (pitch - PITCH_CNTRSINEOFFSET).Cos() : 1.;
if (scaletozero(actor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale)) if (scaletozero(actor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale))
input->actions &= ~SB_CENTERVIEW; cmd.ucmd.actions &= ~SB_CENTERVIEW;
} }
// clamp before we finish, factoring in the player's view pitch offset. // clamp before we finish, factoring in the player's view pitch offset.
@ -117,25 +117,25 @@ void DCorePlayer::doPitchInput(InputPacket* const input)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void DCorePlayer::doYawInput(InputPacket* const input) void DCorePlayer::doYawInput()
{ {
// Add player's mouse/device input. // Add player's mouse/device input.
actor->spr.Angles.Yaw += input->ang.Yaw * gameInput.SyncInput(); actor->spr.Angles.Yaw += cmd.ucmd.ang.Yaw * gameInput.SyncInput();
if (input->actions & SB_TURNAROUND) if (cmd.ucmd.actions & SB_TURNAROUND)
{ {
if (YawSpin == nullAngle) if (YawSpin == nullAngle)
{ {
// currently not spinning, so start a spin // currently not spinning, so start a spin
YawSpin = -DAngle180; YawSpin = -DAngle180;
} }
input->actions &= ~SB_TURNAROUND; cmd.ucmd.actions &= ~SB_TURNAROUND;
} }
if (YawSpin < nullAngle) if (YawSpin < nullAngle)
{ {
// return spin to 0 // return spin to 0
DAngle add = getTicrateAngle(!(input->actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH); DAngle add = getTicrateAngle(!(cmd.ucmd.actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH);
YawSpin += add; YawSpin += add;
if (YawSpin > nullAngle) if (YawSpin > nullAngle)
{ {
@ -206,14 +206,14 @@ void DCorePlayer::doViewPitch(const bool canslopetilt, const bool climbing)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void DCorePlayer::doViewYaw(InputPacket* const input) void DCorePlayer::doViewYaw()
{ {
// Process angle return to zeros. // Process angle return to zeros.
scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN); scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN);
scaletozero(ViewAngles.Roll, YAW_LOOKRETURN); scaletozero(ViewAngles.Roll, YAW_LOOKRETURN);
// Process keyboard input. // Process keyboard input.
if (const auto looking = !!(input->actions & SB_LOOK_RIGHT) - !!(input->actions & SB_LOOK_LEFT)) if (const auto looking = !!(cmd.ucmd.actions & SB_LOOK_RIGHT) - !!(cmd.ucmd.actions & SB_LOOK_LEFT))
{ {
ViewAngles.Yaw += getTicrateAngle(YAW_LOOKINGSPEED * looking); ViewAngles.Yaw += getTicrateAngle(YAW_LOOKINGSPEED * looking);
ViewAngles.Roll += getTicrateAngle(YAW_ROTATESPEED * looking); ViewAngles.Roll += getTicrateAngle(YAW_ROTATESPEED * looking);
@ -227,20 +227,20 @@ void DCorePlayer::doViewYaw(InputPacket* const input)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void DCorePlayer::doRollInput(InputPacket* const input, const DVector2& nVelVect, const double nMaxVel, const bool bUnderwater) void DCorePlayer::doRollInput(const DVector2& nVelVect, const double nMaxVel, const bool bUnderwater)
{ {
// Allow viewtilting if we're not in a VR mode. // Allow viewtilting if we're not in a VR mode.
if (!vr_mode) if (!vr_mode)
{ {
// Scale/attenuate tilting based on player actions. // Scale/attenuate tilting based on player actions.
const auto rollAmp = cl_viewtiltscale / (1 + bUnderwater); const auto rollAmp = cl_viewtiltscale / (1 + bUnderwater);
const auto runScale = 1. / (1 + !(input->actions & SB_RUN)); const auto runScale = 1. / (1 + !(cmd.ucmd.actions & SB_RUN));
const auto strafeScale = 1 + !!input->vel.Y; const auto strafeScale = 1 + !!cmd.ucmd.vel.Y;
if (cl_viewtilting == 1) if (cl_viewtilting == 1)
{ {
// Console-like yaw rolling. Adjustment == ~(90/32) for keyboard turning. Clamp is 1.5x this value. // Console-like yaw rolling. Adjustment == ~(90/32) for keyboard turning. Clamp is 1.5x this value.
const auto rollAdj = input->ang.Yaw * ROLL_TILTAVELSCALE * rollAmp; const auto rollAdj = cmd.ucmd.ang.Yaw * ROLL_TILTAVELSCALE * rollAmp;
const auto rollMax = ROLL_TILTAVELMAX * cl_viewtiltscale; const auto rollMax = ROLL_TILTAVELMAX * cl_viewtiltscale;
scaletozero(actor->spr.Angles.Roll, ROLL_TILTRETURN); scaletozero(actor->spr.Angles.Roll, ROLL_TILTRETURN);
actor->spr.Angles.Roll = clamp(actor->spr.Angles.Roll + rollAdj, -rollMax, rollMax); actor->spr.Angles.Roll = clamp(actor->spr.Angles.Roll + rollAdj, -rollMax, rollMax);
@ -268,6 +268,6 @@ void DCorePlayer::doRollInput(InputPacket* const input, const DVector2& nVelVect
else else
{ {
// Add player's device input. // Add player's device input.
actor->spr.Angles.Roll += input->ang.Roll * gameInput.SyncInput(); actor->spr.Angles.Roll += cmd.ucmd.ang.Roll * gameInput.SyncInput();
} }
} }

View file

@ -38,11 +38,11 @@ public:
virtual DCoreActor* GetActor() = 0; virtual DCoreActor* GetActor() = 0;
// Angle prototypes. // Angle prototypes.
void doPitchInput(InputPacket* const input); void doPitchInput();
void doYawInput(InputPacket* const input); void doYawInput();
void doViewPitch(const bool canslopetilt, const bool climbing = false); void doViewPitch(const bool canslopetilt, const bool climbing = false);
void doViewYaw(InputPacket* const input); void doViewYaw();
void doRollInput(InputPacket* const input, const DVector2& nVelVect, const double nMaxVel, const bool bUnderwater); void doRollInput(const DVector2& nVelVect, const double nMaxVel, const bool bUnderwater);
// Angle methods. // Angle methods.
void InitAngles(const DAngle viewyaw = nullAngle) void InitAngles(const DAngle viewyaw = nullAngle)

View file

@ -6055,7 +6055,7 @@ static void actCheckDudes()
nDrag -= Scale(nDrag, (double)actor->xspr.height, 256.); nDrag -= Scale(nDrag, (double)actor->xspr.height, 256.);
constexpr auto maxVel = (36211. / 3000.); constexpr auto maxVel = (36211. / 3000.);
pPlayer->doRollInput(&pPlayer->cmd.ucmd, actor->vel.XY(), maxVel, false); pPlayer->doRollInput(actor->vel.XY(), maxVel, false);
pPlayer->StrafeVel -= pPlayer->StrafeVel * nDrag; pPlayer->StrafeVel -= pPlayer->StrafeVel * nDrag;
} }

View file

@ -1581,8 +1581,8 @@ void ProcessInput(DBloodPlayer* pPlayer)
pPlayer->StrafeVel += pInput->vel.Y * svAccel * speed; pPlayer->StrafeVel += pInput->vel.Y * svAccel * speed;
} }
pPlayer->doViewYaw(pInput); pPlayer->doViewYaw();
pPlayer->doYawInput(pInput); pPlayer->doYawInput();
if (!(pInput->actions & SB_JUMP)) if (!(pInput->actions & SB_JUMP))
pPlayer->cantJump = 0; pPlayer->cantJump = 0;
@ -1707,7 +1707,7 @@ void ProcessInput(DBloodPlayer* pPlayer)
const int florhit = pPlayer->GetActor()->hit.florhit.type; const int florhit = pPlayer->GetActor()->hit.florhit.type;
pPlayer->doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0)); pPlayer->doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0));
pPlayer->doPitchInput(pInput); pPlayer->doPitchInput();
pPlayer->slope = pPlayer->GetActor()->spr.Angles.Pitch.Tan(); pPlayer->slope = pPlayer->GetActor()->spr.Angles.Pitch.Tan();
if (pInput->actions & SB_INVPREV) if (pInput->actions & SB_INVPREV)

View file

@ -1665,7 +1665,7 @@ void processinput_d(DDukePlayer* const p)
doubvel = TICSPERFRAME; doubvel = TICSPERFRAME;
checklook(p, actions); checklook(p, actions);
p->doViewYaw(&p->cmd.ucmd); p->doViewYaw();
p->updatecentering(); p->updatecentering();
@ -1708,7 +1708,7 @@ void processinput_d(DDukePlayer* const p)
gameInput.ForceInputSync(p->pnum); gameInput.ForceInputSync(p->pnum);
} }
p->doYawInput(&p->cmd.ucmd); p->doYawInput();
purplelavacheck(p); purplelavacheck(p);
@ -1812,7 +1812,7 @@ void processinput_d(DDukePlayer* const p)
} }
} }
p->doRollInput(&p->cmd.ucmd, p->vel.XY(), maxVel, (psectlotag == 1) || (psectlotag == 2)); p->doRollInput(p->vel.XY(), maxVel, (psectlotag == 1) || (psectlotag == 2));
HORIZONLY: HORIZONLY:
@ -1928,7 +1928,7 @@ HORIZONLY:
playerAimDown(p, actions); playerAimDown(p, actions);
} }
p->doPitchInput(&p->cmd.ucmd); p->doPitchInput();
p->checkhardlanding(); p->checkhardlanding();

View file

@ -2486,7 +2486,7 @@ void processinput_r(DDukePlayer* const p)
doubvel = TICSPERFRAME; doubvel = TICSPERFRAME;
checklook(p, actions); checklook(p, actions);
p->doViewYaw(&p->cmd.ucmd); p->doViewYaw();
p->apply_seasick(); p->apply_seasick();
p->updatecentering(); p->updatecentering();
@ -2545,7 +2545,7 @@ void processinput_r(DDukePlayer* const p)
gameInput.ForceInputSync(p->pnum); gameInput.ForceInputSync(p->pnum);
} }
p->doYawInput(&p->cmd.ucmd); p->doYawInput();
purplelavacheck(p); purplelavacheck(p);
@ -2703,7 +2703,7 @@ void processinput_r(DDukePlayer* const p)
if (!p->OnMotorcycle && !p->OnBoat) if (!p->OnMotorcycle && !p->OnBoat)
{ {
p->doRollInput(&p->cmd.ucmd, p->vel.XY(), maxVel, (psectlotag == 1) || (psectlotag == 2)); p->doRollInput(p->vel.XY(), maxVel, (psectlotag == 1) || (psectlotag == 2));
} }
HORIZONLY: HORIZONLY:
@ -2895,7 +2895,7 @@ HORIZONLY:
pact->spr.Angles.Pitch += maphoriz(d); pact->spr.Angles.Pitch += maphoriz(d);
} }
p->doPitchInput(&p->cmd.ucmd); p->doPitchInput();
p->checkhardlanding(); p->checkhardlanding();

View file

@ -1555,7 +1555,7 @@ static void doPlayerCameraEffects(DExhumedPlayer* const pPlayer, const double nD
doPlayerVertPanning(pPlayer, nDestVertPan * cl_slopetilting); doPlayerVertPanning(pPlayer, nDestVertPan * cl_slopetilting);
// Roll tilting effect, either console or Quake-style. // Roll tilting effect, either console or Quake-style.
pPlayer->doRollInput(&pPlayer->cmd.ucmd, pPlayerActor->vel.XY(), maxVel, nUnderwater); pPlayer->doRollInput(pPlayerActor->vel.XY(), maxVel, nUnderwater);
// Update Z bobbing. // Update Z bobbing.
if (cl_viewbob) if (cl_viewbob)
@ -1813,10 +1813,9 @@ static bool doPlayerInput(DExhumedPlayer* const pPlayer)
return false; return false;
// update player yaw here as per the original workflow. // update player yaw here as per the original workflow.
const auto pInput = &pPlayer->cmd.ucmd; pPlayer->doViewYaw();
pPlayer->doViewYaw(pInput); pPlayer->doYawInput();
pPlayer->doYawInput(pInput); pPlayer->doPitchInput();
pPlayer->doPitchInput(pInput);
if (nMove.type || nMove.exbits) if (nMove.type || nMove.exbits)
{ {

View file

@ -1850,8 +1850,8 @@ void DoPlayerMove(DSWPlayer* pp)
SlipSlope(pp); SlipSlope(pp);
pp->doViewYaw(&pp->cmd.ucmd); pp->doViewYaw();
pp->doYawInput(&pp->cmd.ucmd); pp->doYawInput();
UpdatePlayerSpriteAngle(pp); UpdatePlayerSpriteAngle(pp);
pp->lastcursector = pp->cursector; pp->lastcursector = pp->cursector;
@ -1900,7 +1900,7 @@ void DoPlayerMove(DSWPlayer* pp)
actor->vel.X = pp->vect.Length(); actor->vel.X = pp->vect.Length();
constexpr auto maxVel = (380401538. / 36022361.); constexpr auto maxVel = (380401538. / 36022361.);
pp->doRollInput(&pp->cmd.ucmd, pp->vect, maxVel, pp->Flags & (PF_SWIMMING|PF_DIVING)); pp->doRollInput(pp->vect, maxVel, pp->Flags & (PF_SWIMMING|PF_DIVING));
if (pp->Flags & (PF_CLIP_CHEAT)) if (pp->Flags & (PF_CLIP_CHEAT))
{ {
@ -1981,7 +1981,7 @@ void DoPlayerMove(DSWPlayer* pp)
DoPlayerSetWadeDepth(pp); DoPlayerSetWadeDepth(pp);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
pp->doPitchInput(&pp->cmd.ucmd); pp->doPitchInput();
if (pp->insector() && (pp->cursector->extra & SECTFX_DYNAMIC_AREA)) if (pp->insector() && (pp->cursector->extra & SECTFX_DYNAMIC_AREA))
{ {
@ -2567,7 +2567,7 @@ void DoPlayerMoveVehicle(DSWPlayer* pp)
pp->cursector = save_sect; // for speed pp->cursector = save_sect; // for speed
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
pp->doPitchInput(&pp->cmd.ucmd); pp->doPitchInput();
DoTankTreads(pp); DoTankTreads(pp);
} }
@ -2623,7 +2623,7 @@ void DoPlayerMoveTurret(DSWPlayer* pp)
pp->Flags |= (PF_PLAYER_MOVED); pp->Flags |= (PF_PLAYER_MOVED);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
pp->doPitchInput(&pp->cmd.ucmd); pp->doPitchInput();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -3208,7 +3208,7 @@ void DoPlayerClimb(DSWPlayer* pp)
ChangeActorSect(pp->GetActor(), pp->cursector); ChangeActorSect(pp->GetActor(), pp->cursector);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
pp->doPitchInput(&pp->cmd.ucmd); pp->doPitchInput();
if (FAF_ConnectArea(pp->cursector)) if (FAF_ConnectArea(pp->cursector))
{ {