- Tidy up PlayerAngles::doPitchKeys() interface by passing the whole sync packet through.

This commit is contained in:
Mitchell Richters 2023-03-13 21:17:53 +11:00
parent 9ffc65fa48
commit 62561d863e
7 changed files with 20 additions and 19 deletions

View file

@ -167,30 +167,31 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void PlayerAngles::doPitchKeys(ESyncBits* actions, const bool stopcentering) void PlayerAngles::doPitchKeys(InputPacket* const input)
{ {
// Cancel return to center if conditions met. // Cancel return to center if conditions met.
if (stopcentering) *actions &= ~SB_CENTERVIEW; if (input->horz)
input->actions &= ~SB_CENTERVIEW;
// Process keyboard input. // Process keyboard input.
if (auto aiming = !!(*actions & SB_AIM_DOWN) - !!(*actions & SB_AIM_UP)) if (const auto aiming = !!(input->actions & SB_AIM_DOWN) - !!(input->actions & SB_AIM_UP))
{ {
pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_AIMSPEED)) * aiming; pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_AIMSPEED) * aiming);
*actions &= ~SB_CENTERVIEW; input->actions &= ~SB_CENTERVIEW;
} }
if (auto looking = !!(*actions & SB_LOOK_DOWN) - !!(*actions & SB_LOOK_UP)) if (const auto looking = !!(input->actions & SB_LOOK_DOWN) - !!(input->actions & SB_LOOK_UP))
{ {
pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_LOOKSPEED)) * looking; pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_LOOKSPEED) * looking);
*actions |= SB_CENTERVIEW; input->actions |= SB_CENTERVIEW;
} }
// Do return to centre. // Do return to centre.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) if ((input->actions & SB_CENTERVIEW) && !(input->actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{ {
const auto pitch = abs(pActor->spr.Angles.Pitch); const auto pitch = abs(pActor->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(pActor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale)) if (scaletozero(pActor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale))
*actions &= ~SB_CENTERVIEW; input->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.

View file

@ -20,7 +20,7 @@ struct PlayerAngles
friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
// Prototypes. // Prototypes.
void doPitchKeys(ESyncBits* actions, const bool stopcentering); void doPitchKeys(InputPacket* const input);
void doYawKeys(ESyncBits* actions); void doYawKeys(ESyncBits* actions);
void doViewPitch(const bool canslopetilt, const bool climbing = false); void doViewPitch(const bool canslopetilt, const bool climbing = false);
void doViewYaw(const ESyncBits actions); void doViewYaw(const ESyncBits actions);

View file

@ -1705,7 +1705,7 @@ void ProcessInput(PLAYER* pPlayer)
const int florhit = pPlayer->actor->hit.florhit.type; const int florhit = pPlayer->actor->hit.florhit.type;
pPlayer->Angles.doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0)); pPlayer->Angles.doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0));
pPlayer->Angles.doPitchKeys(&pInput->actions, pInput->horz); pPlayer->Angles.doPitchKeys(pInput);
pPlayer->slope = pPlayer->actor->spr.Angles.Pitch.Tan(); pPlayer->slope = pPlayer->actor->spr.Angles.Pitch.Tan();
if (pInput->actions & SB_INVPREV) if (pInput->actions & SB_INVPREV)

View file

@ -2988,7 +2988,7 @@ HORIZONLY:
p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum);
} }
p->Angles.doPitchKeys(&actions, GetPlayerHorizon(snum).Sgn()); p->Angles.doPitchKeys(&p->sync);
p->checkhardlanding(); p->checkhardlanding();

View file

@ -3802,7 +3802,7 @@ HORIZONLY:
p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum); p->GetActor()->spr.Angles.Pitch += GetPlayerHorizon(snum);
} }
p->Angles.doPitchKeys(&actions, GetPlayerHorizon(snum).Sgn()); p->Angles.doPitchKeys(&p->sync);
p->checkhardlanding(); p->checkhardlanding();

View file

@ -2471,7 +2471,7 @@ sectdone:
pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(PlayerList[nPlayer].input.horz); pPlayer->pActor->spr.Angles.Pitch += DAngle::fromDeg(PlayerList[nPlayer].input.horz);
} }
pPlayer->Angles.doPitchKeys(&PlayerList[nLocalPlayer].input.actions, PlayerList[nPlayer].input.pan); pPlayer->Angles.doPitchKeys(&PlayerList[nLocalPlayer].input);
if (actions & (SB_AIM_UP | SB_AIM_DOWN) || PlayerList[nPlayer].input.horz) if (actions & (SB_AIM_UP | SB_AIM_DOWN) || PlayerList[nPlayer].input.horz)
{ {

View file

@ -2163,7 +2163,7 @@ void DoPlayerMove(PLAYER* pp)
pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz);
} }
pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); pp->Angles.doPitchKeys(&pp->input);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
@ -2750,7 +2750,7 @@ void DoPlayerMoveVehicle(PLAYER* pp)
pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz);
} }
pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); pp->Angles.doPitchKeys(&pp->input);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
@ -2796,7 +2796,7 @@ void DoPlayerMoveTurret(PLAYER* pp)
pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz);
} }
pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); pp->Angles.doPitchKeys(&pp->input);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);
} }
@ -3398,7 +3398,7 @@ void DoPlayerClimb(PLAYER* pp)
pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz); pp->actor->spr.Angles.Pitch += DAngle::fromDeg(pp->input.horz);
} }
pp->Angles.doPitchKeys(&pp->input.actions, pp->input.horz); pp->Angles.doPitchKeys(&pp->input);
DoPlayerSlopeTilting(pp); DoPlayerSlopeTilting(pp);