- Remove the whole angle locking concept, we can just force synchronised input instead which is cleaner.

This commit is contained in:
Mitchell Richters 2022-12-01 07:59:13 +11:00 committed by Christoph Oelckers
parent 6c0493868e
commit bb1113c251
4 changed files with 50 additions and 80 deletions

View file

@ -175,44 +175,36 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe
void PlayerAngles::applyPitch(float const horz, ESyncBits* actions, double const scaleAdjust)
{
// Process only if movement isn't locked.
if (!lockedPitch())
{
// Process mouse input.
if (horz)
{
pActor->spr.Angles.Pitch += DAngle::fromDeg(horz);
*actions &= ~SB_CENTERVIEW;
}
// Process keyboard input.
if (auto aiming = !!(*actions & SB_AIM_DOWN) - !!(*actions & SB_AIM_UP))
{
pActor->spr.Angles.Pitch += getTicrateScale(PITCH_AIMSPEED) * scaleAdjust * aiming;
*actions &= ~SB_CENTERVIEW;
}
if (auto looking = !!(*actions & SB_LOOK_DOWN) - !!(*actions & SB_LOOK_UP))
{
pActor->spr.Angles.Pitch += getTicrateScale(PITCH_LOOKSPEED) * scaleAdjust * looking;
*actions |= SB_CENTERVIEW;
}
// Do return to centre.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{
const auto pitch = abs(pActor->spr.Angles.Pitch);
const auto scale = pitch > PITCH_CNTRSINEOFFSET ? (pitch - PITCH_CNTRSINEOFFSET).Cos() : 1.;
scaletozero(pActor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale, scaleAdjust);
if (!pActor->spr.Angles.Pitch.Sgn()) *actions &= ~SB_CENTERVIEW;
}
// clamp before we finish, even if it's clamped in the drawer.
pActor->spr.Angles.Pitch = ClampViewPitch(pActor->spr.Angles.Pitch);
}
else
// Process mouse input.
if (horz)
{
pActor->spr.Angles.Pitch += DAngle::fromDeg(horz);
*actions &= ~SB_CENTERVIEW;
}
// Process keyboard input.
if (auto aiming = !!(*actions & SB_AIM_DOWN) - !!(*actions & SB_AIM_UP))
{
pActor->spr.Angles.Pitch += getTicrateScale(PITCH_AIMSPEED) * scaleAdjust * aiming;
*actions &= ~SB_CENTERVIEW;
}
if (auto looking = !!(*actions & SB_LOOK_DOWN) - !!(*actions & SB_LOOK_UP))
{
pActor->spr.Angles.Pitch += getTicrateScale(PITCH_LOOKSPEED) * scaleAdjust * looking;
*actions |= SB_CENTERVIEW;
}
// Do return to centre.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{
const auto pitch = abs(pActor->spr.Angles.Pitch);
const auto scale = pitch > PITCH_CNTRSINEOFFSET ? (pitch - PITCH_CNTRSINEOFFSET).Cos() : 1.;
scaletozero(pActor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale, scaleAdjust);
if (!pActor->spr.Angles.Pitch.Sgn()) *actions &= ~SB_CENTERVIEW;
}
// clamp before we finish, even if it's clamped in the drawer.
pActor->spr.Angles.Pitch = ClampViewPitch(pActor->spr.Angles.Pitch);
}
@ -224,39 +216,31 @@ void PlayerAngles::applyPitch(float const horz, ESyncBits* actions, double const
void PlayerAngles::applyYaw(float const avel, ESyncBits* actions, double const scaleAdjust)
{
// Process only if movement isn't locked.
if (!lockedYaw())
// add player's input
pActor->spr.Angles.Yaw += DAngle::fromDeg(avel);
if (*actions & SB_TURNAROUND)
{
// add player's input
pActor->spr.Angles.Yaw += DAngle::fromDeg(avel);
if (*actions & SB_TURNAROUND)
if (YawSpin == nullAngle)
{
if (YawSpin == nullAngle)
{
// currently not spinning, so start a spin
YawSpin = -DAngle180;
}
*actions &= ~SB_TURNAROUND;
}
if (YawSpin < nullAngle)
{
// return spin to 0
DAngle add = getTicrateScale(!(*actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH) * scaleAdjust;
YawSpin += add;
if (YawSpin > nullAngle)
{
// Don't overshoot our target. With variable factor this is possible.
add -= YawSpin;
YawSpin = nullAngle;
}
pActor->spr.Angles.Yaw += add;
// currently not spinning, so start a spin
YawSpin = -DAngle180;
}
*actions &= ~SB_TURNAROUND;
}
else
if (YawSpin < nullAngle)
{
YawSpin = nullAngle;
// return spin to 0
DAngle add = getTicrateScale(!(*actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH) * scaleAdjust;
YawSpin += add;
if (YawSpin > nullAngle)
{
// Don't overshoot our target. With variable factor this is possible.
add -= YawSpin;
YawSpin = nullAngle;
}
pActor->spr.Angles.Yaw += add;
}
}
@ -348,7 +332,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P
arc("viewangles", w.ViewAngles)
("spin", w.YawSpin)
("actor", w.pActor)
("anglelocks", w.AngleLocks)
.EndObject();
if (arc.isReading())

View file

@ -62,23 +62,14 @@ struct PlayerAngles
}
// Pitch methods.
void lockPitch() { AngleLocks.Set(PITCH); }
void unlockPitch() { AngleLocks.Clear(PITCH); }
bool lockedPitch() { return AngleLocks[PITCH]; }
void addPitch(const DAngle value) { updateAngle(PITCH, ClampViewPitch(pActor->spr.Angles.Pitch + value)); }
void setPitch(const DAngle value, const bool backup = false) { updateAngle(PITCH, ClampViewPitch(value), backup); }
// Yaw methods.
void lockYaw() { AngleLocks.Set(YAW); }
void unlockYaw() { AngleLocks.Clear(YAW); }
bool lockedYaw() { return AngleLocks[YAW]; }
void addYaw(const DAngle value) { updateAngle(YAW, pActor->spr.Angles.Yaw + value); }
void setYaw(const DAngle value, const bool backup = false) { updateAngle(YAW, value, backup); }
// Roll methods.
void lockRoll() { AngleLocks.Set(ROLL); }
void unlockRoll() { AngleLocks.Clear(ROLL); }
bool lockedRoll() { return AngleLocks[ROLL]; }
void addRoll(const DAngle value) { updateAngle(ROLL, pActor->spr.Angles.Roll + value); }
void setRoll(const DAngle value, const bool backup = false) { updateAngle(ROLL, value, backup); }
@ -118,7 +109,6 @@ private:
// Private data which should never be accessed publically.
DRotator Targets, AppliedAmounts;
FixedBitArray<MAXANGLES> AngleLocks;
DCoreActor* pActor;
// Internal angle updater to reduce boilerplate from the public setters.

View file

@ -2186,8 +2186,8 @@ void trPlayerCtrlSetLookAngle(int value, PLAYER* pPlayer)
if (const double adjustment = clamp(value * 0.125 * (value > 0 ? lookStepUp : lookStepDown), downAngle, upAngle))
{
setForcedSyncInput();
pPlayer->Angles.setPitch(maphoriz(-100. * tan(adjustment * pi::pi() * (1. / 1024.))));
pPlayer->Angles.lockPitch();
}
}
@ -6050,13 +6050,13 @@ bool modernTypeOperateSprite(DBloodActor* actor, EVENT& event)
if (actor->xspr.data4 != 0) break;
else if (actor->spr.flags & kModernTypeFlag1)
{
setForcedSyncInput();
pPlayer->Angles.setYaw(actor->spr.Angles.Yaw);
pPlayer->Angles.lockYaw();
}
else if (valueIsBetween(actor->xspr.data2, -kAng360, kAng360))
{
setForcedSyncInput();
pPlayer->Angles.setYaw(mapangle(actor->xspr.data2));
pPlayer->Angles.lockYaw();
}
break;
case 10: // 74 (de)activate powerup

View file

@ -1718,9 +1718,6 @@ void ProcessInput(PLAYER* pPlayer)
doslopetilting(pPlayer);
pPlayer->Angles.unlockYaw();
pPlayer->Angles.unlockPitch();
pPlayer->slope = pPlayer->actor->spr.Angles.Pitch.Tan();
if (pInput->actions & SB_INVPREV)
{