From 083ed3e9b724f46b638033cd46a6df9f214c7d48 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 8 Sep 2020 06:50:38 +1000 Subject: [PATCH] - SW: Handle `angAdjust` and `horizAdjust` directly in `processMovement()` instead of via `DoPlayerTurn()`/`DoPlayerHorizon()`. * Eliminates issues with when to call when player is dead, etc. Handles cases like climbing a ladder which doesn't trigger `DoPlayerTurn()`. --- source/sw/src/input.cpp | 6 + source/sw/src/player.cpp | 242 +++++++++++++++++---------------------- source/sw/src/track.cpp | 2 +- 3 files changed, 115 insertions(+), 135 deletions(-) diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 79ed8cdf9..8e0607cee 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -283,6 +283,9 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM)) DoPlayerHorizon(pp, q16horz, scaleAdjust); + if (pp->horizAdjust) + pp->q16horiz += FloatToFixed(scaleAdjust * pp->horizAdjust); + if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL)) DoPlayerTurn(pp, q16avel, scaleAdjust); @@ -294,6 +297,9 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_TURRET)) DoPlayerTurnTurret(pp, q16avel); + + if (pp->angAdjust) + pp->q16ang = (pp->q16ang + FloatToFixed(scaleAdjust * pp->angAdjust)) & 0x7FFFFFF; } loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL); diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index a8e68559a..44464df5c 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1548,82 +1548,74 @@ DoPlayerCrawlHeight(PLAYERp pp) void DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust) { - if (!TEST(pp->Flags, PF_DEAD) || TEST(pp->Flags, PF_DEAD) && TEST(pp->Flags, PF_DEAD_HEAD|PF_HEAD_CONTROL)) + if (!TEST(pp->Flags, PF_TURN_180)) { - if (!TEST(pp->Flags, PF_TURN_180)) + if (pp->input.actions & SB_TURNAROUND) { - if (pp->input.actions & SB_TURNAROUND) + if (pp->KeyPressBits & SB_TURNAROUND) { - if (pp->KeyPressBits & SB_TURNAROUND) - { - fixed_t delta_ang; + fixed_t delta_ang; - pp->KeyPressBits &= ~SB_TURNAROUND; + pp->KeyPressBits &= ~SB_TURNAROUND; - pp->turn180_target = pp->q16ang + IntToFixed(1024); + pp->turn180_target = pp->q16ang + IntToFixed(1024); - // make the first turn in the clockwise direction - // the rest will follow - delta_ang = labs(GetDeltaQ16Angle(pp->turn180_target, pp->q16ang)) >> TURN_SHIFT; - pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF; + // make the first turn in the clockwise direction + // the rest will follow + delta_ang = labs(GetDeltaQ16Angle(pp->turn180_target, pp->q16ang)) >> TURN_SHIFT; + pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF; - SET(pp->Flags, PF_TURN_180); - } - } - else - { - pp->KeyPressBits |= SB_TURNAROUND; + SET(pp->Flags, PF_TURN_180); } } - - if (TEST(pp->Flags, PF_TURN_180)) + else { - fixed_t delta_ang; - - delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang) >> TURN_SHIFT; - pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF; - - sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); - - if (!Prediction && pp->PlayerUnderSprite >= 0) - { - sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); - } - - // get new delta to see how close we are - delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang); - - if (labs(delta_ang) < (IntToFixed(3) << TURN_SHIFT)) - { - pp->q16ang = pp->turn180_target; - RESET(pp->Flags, PF_TURN_180); - } - else - { - return; - } - } - - if (q16avel != 0) - { - pp->q16ang = (pp->q16ang + q16avel) & 0x7FFFFFF; + pp->KeyPressBits |= SB_TURNAROUND; } } - if (!cl_syncinput && pp->angAdjust) + if (TEST(pp->Flags, PF_TURN_180)) { - pp->q16ang = (pp->q16ang + FloatToFixed(scaleAdjust * pp->angAdjust)) & 0x7FFFFFF; + fixed_t delta_ang; + + delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang) >> TURN_SHIFT; + pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF; + + sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); + + if (!Prediction && pp->PlayerUnderSprite >= 0) + { + sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); + } + + // get new delta to see how close we are + delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang); + + if (labs(delta_ang) < (IntToFixed(3) << TURN_SHIFT)) + { + pp->q16ang = pp->turn180_target; + RESET(pp->Flags, PF_TURN_180); + } + else + { + return; + } } - // update players sprite angle - // NOTE: It's also updated in UpdatePlayerSprite, but needs to be - // here to cover - // all cases. - sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); - - if (!Prediction && pp->PlayerUnderSprite >= 0) + if (q16avel != 0) { - sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); + pp->q16ang = (pp->q16ang + q16avel) & 0x7FFFFFF; + + // update players sprite angle + // NOTE: It's also updated in UpdatePlayerSprite, but needs to be + // here to cover + // all cases. + sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang); + + if (!Prediction && pp->PlayerUnderSprite >= 0) + { + sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); + } } } @@ -1833,71 +1825,68 @@ PlayerAutoLook(PLAYERp pp, double const scaleAdjust) void DoPlayerHorizon(PLAYERp pp, fixed_t const q16horz, double const scaleAdjust) { - if (!TEST(pp->Flags, PF_DEAD)) + // Fixme: This should probably be made optional. + if (cl_slopetilting) + PlayerAutoLook(pp, scaleAdjust); + + if (q16horz) { - // Fixme: This should probably be made optional. - if (cl_slopetilting) - PlayerAutoLook(pp, scaleAdjust); + pp->q16horizbase += q16horz; + SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); + } - if (q16horz) + // this is the locked type + if (pp->input.actions & (SB_AIM_UP|SB_AIM_DOWN)) + { + // set looking because player is manually looking. + SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); + + // adjust q16horiz negative + if (pp->input.actions & SB_AIM_DOWN) + pp->q16horizbase -= FloatToFixed(scaleAdjust * (HORIZ_SPEED >> 1)); + + // adjust q16horiz positive + if (pp->input.actions & SB_AIM_UP) + pp->q16horizbase += FloatToFixed(scaleAdjust * (HORIZ_SPEED >> 1)); + } + + // this is the unlocked type + if (pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN|SB_CENTERVIEW)) + { + RESET(pp->Flags, PF_LOCK_HORIZ); + SET(pp->Flags, PF_LOOKING); + + // adjust q16horiz negative + if (pp->input.actions & SB_LOOK_DOWN) + pp->q16horizbase -= FloatToFixed(scaleAdjust * HORIZ_SPEED); + + // adjust q16horiz positive + if (pp->input.actions & SB_LOOK_UP) + pp->q16horizbase += FloatToFixed(scaleAdjust * HORIZ_SPEED); + + if (pp->input.actions & SB_CENTERVIEW) + pp->q16horizoff = 0; + } + + if (!TEST(pp->Flags, PF_LOCK_HORIZ)) + { + if (!(pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN))) { - pp->q16horizbase += q16horz; - SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); - } - - // this is the locked type - if (pp->input.actions & (SB_AIM_UP|SB_AIM_DOWN)) - { - // set looking because player is manually looking. - SET(pp->Flags, PF_LOCK_HORIZ | PF_LOOKING); - - // adjust q16horiz negative - if (pp->input.actions & SB_AIM_DOWN) - pp->q16horizbase -= FloatToFixed(scaleAdjust * (HORIZ_SPEED >> 1)); - - // adjust q16horiz positive - if (pp->input.actions & SB_AIM_UP) - pp->q16horizbase += FloatToFixed(scaleAdjust * (HORIZ_SPEED >> 1)); - } - - // this is the unlocked type - if (pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN|SB_CENTERVIEW)) - { - RESET(pp->Flags, PF_LOCK_HORIZ); - SET(pp->Flags, PF_LOOKING); - - // adjust q16horiz negative - if (pp->input.actions & SB_LOOK_DOWN) - pp->q16horizbase -= FloatToFixed(scaleAdjust * HORIZ_SPEED); - - // adjust q16horiz positive - if (pp->input.actions & SB_LOOK_UP) - pp->q16horizbase += FloatToFixed(scaleAdjust * HORIZ_SPEED); - - if (pp->input.actions & SB_CENTERVIEW) - pp->q16horizoff = 0; - } - - if (!TEST(pp->Flags, PF_LOCK_HORIZ)) - { - if (!(pp->input.actions & (SB_LOOK_UP|SB_LOOK_DOWN))) + // not pressing the q16horiz keys + if (pp->q16horizbase != IntToFixed(100)) { - // not pressing the q16horiz keys - if (pp->q16horizbase != IntToFixed(100)) + // move q16horiz back to 100 + for (int i = 1; i; i--) { - // move q16horiz back to 100 - for (int i = 1; i; i--) - { - // this formula does not work for q16horiz = 101-103 - pp->q16horizbase += xs_CRoundToInt(scaleAdjust * (IntToFixed(25) - (pp->q16horizbase >> 2))); - } - } - else - { - // not looking anymore because q16horiz is back at 100 - RESET(pp->Flags, PF_LOOKING); + // this formula does not work for q16horiz = 101-103 + pp->q16horizbase += xs_CRoundToInt(scaleAdjust * (IntToFixed(25) - (pp->q16horizbase >> 2))); } } + else + { + // not looking anymore because q16horiz is back at 100 + RESET(pp->Flags, PF_LOOKING); + } } } @@ -1913,11 +1902,6 @@ DoPlayerHorizon(PLAYERp pp, fixed_t const q16horz, double const scaleAdjust) // add base and offsets pp->q16horiz = pp->q16horizbase + pp->q16horizoff; - - if (!cl_syncinput) - { - pp->q16horiz += xs_CRoundToInt(scaleAdjust * pp->horizAdjust); - } } void @@ -4293,7 +4277,7 @@ PlayerOnLadder(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - playerSetAngle(pp, pp->LadderAngle); + playerAddAngle(pp, FixedToFloat(GetDeltaQ16Angle(IntToFixed(pp->LadderAngle), pp->q16ang))); return TRUE; } @@ -6296,9 +6280,6 @@ DoPlayerDeathHoriz(PLAYERp pp, short target, short speed) { if (pp->q16horiz > IntToFixed(target)) { - if (!cl_syncinput) - SET(pp->Flags2, PF2_INPUT_CAN_AIM); - playerAddHoriz(pp, -speed); if (pp->q16horiz <= IntToFixed(target)) @@ -6307,9 +6288,6 @@ DoPlayerDeathHoriz(PLAYERp pp, short target, short speed) if (pp->q16horiz < IntToFixed(target)) { - if (!cl_syncinput) - SET(pp->Flags2, PF2_INPUT_CAN_AIM); - playerAddHoriz(pp, speed); if (pp->q16horiz >= IntToFixed(target)) @@ -6410,10 +6388,6 @@ void DoPlayerDeathFollowKiller(PLAYERp pp) if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum)) { - if (!cl_syncinput) - { - SET(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL); - } playerAddAngle(pp, GetDeltaQ16Angle(gethiq16angle(kp->x - pp->posx, kp->y - pp->posy), pp->q16ang) / (double)(FRACUNIT << 4)); } } @@ -7452,7 +7426,7 @@ domovethings(void) // auto tracking mode for single player multi-game if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex) { - playerSetAngle(&Player[screenpeek], gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy) / (double)(FRACUNIT)); + playerSetAngle(&Player[screenpeek], FixedToFloat(gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy))); } if (!TEST(pp->Flags, PF_DEAD)) diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index 2d9c3e1ba..cdfcfcb80 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -1675,7 +1675,7 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny) // New angle is formed by taking last known angle and // adjusting by the delta angle - playerSetAngle(pp, (pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng)) / (double)(FRACUNIT)); + playerSetAngle(pp, FixedToFloat(pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng))); UpdatePlayerSprite(pp); }