From bb1113c2519ffc69c271c54c7bf3e2d5b217973f Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Thu, 1 Dec 2022 07:59:13 +1100 Subject: [PATCH] - Remove the whole angle locking concept, we can just force synchronised input instead which is cleaner. --- source/core/gameinput.cpp | 111 +++++++++++++----------------- source/core/gameinput.h | 10 --- source/games/blood/src/nnexts.cpp | 6 +- source/games/blood/src/player.cpp | 3 - 4 files changed, 50 insertions(+), 80 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index d2dd07dca..d6ec60433 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -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()) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index d42b52152..1a32c95d2 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -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 AngleLocks; DCoreActor* pActor; // Internal angle updater to reduce boilerplate from the public setters. diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 0033baab5..870f86dd4 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -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 diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 2d7f273cc..d007d2d6a 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -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) {