From 630c10856e77aa8fe482647d840622fb9131b4eb Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 28 Nov 2022 16:34:29 +1100 Subject: [PATCH] - Re-write `PlayerAngles` scaled adjustment methods. --- source/core/gameinput.cpp | 8 +- source/core/gameinput.h | 176 ++++++++++++---------------- source/games/blood/src/controls.cpp | 3 +- source/games/blood/src/player.cpp | 3 +- source/games/duke/src/input.cpp | 3 +- source/games/duke/src/player_d.cpp | 3 +- source/games/duke/src/player_r.cpp | 3 +- source/games/exhumed/src/input.cpp | 3 +- source/games/exhumed/src/player.cpp | 3 +- source/games/sw/src/input.cpp | 3 +- source/games/sw/src/player.cpp | 3 +- 11 files changed, 84 insertions(+), 127 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index f9bae7a6f..8592b49b7 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -338,20 +338,16 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, P ("rotscrnang", w.ZzROTSCRNANG) ("spin", w.YawSpin) ("actor", w.pActor) - ("inputdisabled", w.legacyDisabledYaw) + ("anglelocks", w.AngleLocks) ("horizoff", w.ZzHORIZOFF) - ("inputdisabled", w.legacyDisabledPitch) .EndObject(); if (arc.isReading()) { w.ZzOLDLOOKANG = w.ZzLOOKANG; w.ZzOLDROTSCRNANG = w.ZzROTSCRNANG; - w.legacyDisabledYaw = w.legacyDisabledYaw; - w.resetAdjustmentYaw(); w.ZzOHORIZOFF = w.ZzHORIZOFF; - w.legacyDisabledPitch = w.legacyDisabledPitch; - w.resetAdjustmentPitch(); + w.resetAdjustments(); } } return arc; diff --git a/source/core/gameinput.h b/source/core/gameinput.h index f54b19a9d..78057b5b9 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -24,67 +24,53 @@ struct PlayerAngles void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust = 1, bool const climbing = false); // General methods. + void resetAdjustments() { Adjustments = {}; } void setActor(DCoreActor* const actor) { pActor = actor; } // Pitch methods. - void lockPitch() { legacyDisabledPitch = true; } - void unlockPitch() { legacyDisabledPitch = false; } - bool targetedPitch() { return legacyTargetPitch.Sgn(); } - bool lockedPitch() { return targetedPitch() || legacyDisabledPitch; } - void addPitch(DAngle const value) - { - if (!SyncInput()) - { - legacyAdjustmentPitch += value; - } - else - { - ZzHORIZON() += value; - } - } - void setPitch(DAngle value, bool const backup = false) - { - // Clamp incoming variable because sometimes the caller can exceed bounds. - value = ClampViewPitch(value); - - if (!SyncInput() && !backup) - { - legacyTargetPitch = value.Sgn() ? value : minAngle; - } - else - { - ZzHORIZON() = value; - if (backup) ZzOLDHORIZON() = ZzHORIZON(); - } - } + void lockPitch() { AngleLocks.Set(PITCH); } + void unlockPitch() { AngleLocks.Clear(PITCH); } + bool lockedPitch() { return Targets.Pitch.Sgn() || AngleLocks[PITCH]; } + void addPitch(const DAngle value) { addAngle(PITCH, value); } + void setPitch(const DAngle value, const bool backup = false) { setAngle(PITCH, ClampViewPitch(value), backup); } // Yaw methods. - void lockYaw() { legacyDisabledYaw = true; } - void unlockYaw() { legacyDisabledYaw = false; } - bool targetedYaw() { return legacyTargetYaw.Sgn(); } - bool lockedYaw() { return targetedYaw() || legacyDisabledYaw; } - void addYaw(const DAngle value) - { - if (!SyncInput()) - { - legacyAdjustmentYaw += value.Normalized180(); - } - else - { - ZzANGLE() += value; - } - } + void lockYaw() { AngleLocks.Set(YAW); } + void unlockYaw() { AngleLocks.Clear(YAW); } + bool lockedYaw() { return Targets.Yaw.Sgn() || AngleLocks[YAW]; } + void addYaw(const DAngle value) { addAngle(YAW, value); } + void setYaw(const DAngle value, const bool backup = false) { setAngle(YAW, value, backup); } - void setYaw(const DAngle value, bool const backup = false) + // Roll methods. + void lockRoll() { AngleLocks.Set(ROLL); } + void unlockRoll() { AngleLocks.Clear(ROLL); } + bool lockedRoll() { return Targets.Roll.Sgn() || AngleLocks[ROLL]; } + void addRoll(const DAngle value) { addAngle(ROLL, value); } + void setRoll(const DAngle value, const bool backup = false) { setAngle(ROLL, value, backup); } + + // Applicator of pending angle changes. + void applyScaledAdjustments(const double scaleAdjust) { - if (!SyncInput() && !backup) + for (unsigned i = 0; i < MAXANGLES; i++) { - legacyTargetYaw = value.Sgn() ? value : minAngle; - } - else - { - ZzANGLE() = value; - if (backup) ZzOLDANGLE() = ZzANGLE(); + if (Targets[i].Sgn()) + { + const auto delta = deltaangle(pActor->spr.Angles[i], Targets[i]); + + if (abs(delta.Degrees()) > BAngToDegree) + { + pActor->spr.Angles[i] += delta * scaleAdjust; + } + else + { + pActor->spr.Angles[i] = Targets[i]; + Targets[i] = nullAngle; + } + } + else if (Adjustments[i].Sgn()) + { + pActor->spr.Angles[i] += Adjustments[i] * scaleAdjust; + } } } @@ -108,27 +94,6 @@ struct PlayerAngles // Legacy, to be removed. DAngle ZzHORIZOFF, ZzOHORIZOFF; - void processLegacyHelperPitch(double const scaleAdjust) - { - if (targetedPitch()) - { - auto delta = deltaangle(ZzHORIZON(), legacyTargetPitch); - - if (abs(delta).Degrees() > 0.45) - { - ZzHORIZON() += delta * scaleAdjust; - } - else - { - ZzHORIZON() = legacyTargetPitch; - legacyTargetPitch = nullAngle; - } - } - else if (legacyAdjustmentPitch.Sgn()) - { - ZzHORIZON() += legacyAdjustmentPitch * scaleAdjust; - } - } void backupPitch() { ZzOLDHORIZON() = ZzHORIZON(); @@ -142,30 +107,8 @@ struct PlayerAngles DAngle horizOLDSUM() { return ZzOLDHORIZON() + ZzOHORIZOFF; } DAngle horizSUM() { return ZzHORIZON() + ZzHORIZOFF; } DAngle horizLERPSUM(double const interpfrac) { return interpolatedvalue(horizOLDSUM(), horizSUM(), interpfrac); } - void resetAdjustmentPitch() { legacyAdjustmentPitch = nullAngle; } DAngle ZzLOOKANG, ZzOLDLOOKANG, ZzROTSCRNANG, ZzOLDROTSCRNANG, YawSpin; - void processLegacyHelperYaw(double const scaleAdjust) - { - if (targetedYaw()) - { - auto delta = deltaangle(ZzANGLE(), legacyTargetYaw); - - if (abs(delta) > DAngleBuildToDeg) - { - ZzANGLE() += delta * scaleAdjust; - } - else - { - ZzANGLE() = legacyTargetYaw; - legacyTargetYaw = nullAngle; - } - } - else if (legacyAdjustmentYaw.Sgn()) - { - ZzANGLE() += legacyAdjustmentYaw * scaleAdjust; - } - } void backupYaw() { ZzOLDANGLE() = ZzANGLE(); @@ -186,19 +129,46 @@ struct PlayerAngles DAngle angLERPROTSCRN(double const interpfrac) { return interpolatedvalue(ZzOLDROTSCRNANG, ZzROTSCRNANG, interpfrac); } DAngle angRENDERLOOKANG(double const interpfrac) { return !SyncInput() ? ZzLOOKANG : angLERPLOOKANG(interpfrac); } DAngle angRENDERROTSCRN(double const interpfrac) { return !SyncInput() ? ZzROTSCRNANG : angLERPROTSCRN(interpfrac); } - void resetAdjustmentYaw() { legacyAdjustmentYaw = nullAngle; } private: + // DRotator indices. + enum : unsigned + { + PITCH, + YAW, + ROLL, + MAXANGLES, + }; + // Private data which should never be accessed publically. + DRotator Targets, Adjustments; + FixedBitArray AngleLocks; DCoreActor* pActor; + void addAngle(const unsigned angIndex, const DAngle value) + { + if (!SyncInput()) + { + Adjustments[angIndex] += value.Normalized180(); + } + else + { + pActor->spr.Angles[angIndex] += value; + } + } - // Legacy, to be removed. - DAngle legacyTargetPitch, legacyAdjustmentPitch; - bool legacyDisabledPitch; - - DAngle legacyTargetYaw, legacyAdjustmentYaw; - bool legacyDisabledYaw; + void setAngle(const unsigned angIndex, const DAngle value, const bool backup) + { + if (!SyncInput() && !backup) + { + Targets[angIndex] = value.Sgn() ? value : minAngle; + } + else + { + pActor->spr.Angles[angIndex] = value; + if (backup) pActor->PrevAngles[angIndex] = pActor->spr.Angles[angIndex]; + } + } }; class FSerializer; diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index 2d483b8be..b2ec66c20 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -66,8 +66,7 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju doslopetilting(pPlayer, scaleAdjust); } - pPlayer->Angles.processLegacyHelperYaw(scaleAdjust); - pPlayer->Angles.processLegacyHelperPitch(scaleAdjust); + pPlayer->Angles.applyScaledAdjustments(scaleAdjust); } if (packet) diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index f93594bc8..e967e83ea 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1522,8 +1522,7 @@ void ProcessInput(PLAYER* pPlayer) Item_JumpBoots = 3 }; - pPlayer->Angles.resetAdjustmentPitch(); - pPlayer->Angles.resetAdjustmentYaw(); + pPlayer->Angles.resetAdjustments(); DBloodActor* actor = pPlayer->actor; POSTURE* pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture]; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 36e9dad59..198e072dd 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -841,8 +841,7 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju p->Angles.applyPitch(input.horz, &p->sync.actions, scaleAdjust); } - p->Angles.processLegacyHelperYaw(scaleAdjust); - p->Angles.processLegacyHelperPitch(scaleAdjust); + p->Angles.applyScaledAdjustments(scaleAdjust); } if (packet) diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 14f57ee08..5af0537e6 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2725,8 +2725,7 @@ void processinput_d(int snum) p = &ps[snum]; auto pact = p->GetActor(); - p->Angles.resetAdjustmentPitch(); - p->Angles.resetAdjustmentYaw(); + p->Angles.resetAdjustments(); ESyncBits& actions = p->sync.actions; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index af159bdad..fd0d1c6eb 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3272,8 +3272,7 @@ void processinput_r(int snum) auto p = &ps[snum]; auto pact = p->GetActor(); - p->Angles.resetAdjustmentPitch(); - p->Angles.resetAdjustmentYaw(); + p->Angles.resetAdjustments(); ESyncBits& actions = p->sync.actions; diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index 496718cfe..4bd7bd85e 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -95,8 +95,7 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju } } - pPlayer->Angles.processLegacyHelperYaw(scaleAdjust); - pPlayer->Angles.processLegacyHelperPitch(scaleAdjust); + pPlayer->Angles.applyScaledAdjustments(scaleAdjust); UpdatePlayerSpriteAngle(pPlayer); } diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index d5bbea211..ea3046910 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -906,8 +906,7 @@ void AIPlayer::Tick(RunListEvent* ev) PlayerList[nPlayer].Angles.backupYaw(); PlayerList[nPlayer].Angles.backupPitch(); - PlayerList[nPlayer].Angles.resetAdjustmentYaw(); - PlayerList[nPlayer].Angles.resetAdjustmentPitch(); + PlayerList[nPlayer].Angles.resetAdjustments(); pPlayerActor->vel.XY() = sPlayerInput[nPlayer].vel; diff --git a/source/games/sw/src/input.cpp b/source/games/sw/src/input.cpp index 1b343bee1..ff3654b2c 100644 --- a/source/games/sw/src/input.cpp +++ b/source/games/sw/src/input.cpp @@ -200,8 +200,7 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju DoPlayerTurnTurret(pp, input.avel); } - pp->Angles.processLegacyHelperYaw(scaleAdjust); - pp->Angles.processLegacyHelperPitch(scaleAdjust); + pp->Angles.applyScaledAdjustments(scaleAdjust); } if (packet) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 6ff5e9fe0..5e814d5c0 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6973,8 +6973,7 @@ void domovethings(void) // Reset flags used while tying input to framerate pp->Flags2 &= ~(PF2_INPUT_CAN_AIM|PF2_INPUT_CAN_TURN_GENERAL|PF2_INPUT_CAN_TURN_VEHICLE|PF2_INPUT_CAN_TURN_TURRET); - pp->Angles.resetAdjustmentPitch(); - pp->Angles.resetAdjustmentYaw(); + pp->Angles.resetAdjustments(); // disable synchronised input if set by game. resetForcedSyncInput();