From e36c9fc78ca5d39bc6d0cf7016302976f69978ab Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 7 Sep 2020 21:30:06 +1000 Subject: [PATCH] - SW: Hook up `angAdjust` and adjust all ticrate amendments of `q16ang` via `playerAddAngle()`/`playerSetAngle()`. * Promoted some uses of `getangle()` upscaled to Q16.16 with `gethiq16angle()` for higher precision. --- source/sw/src/draw.cpp | 2 +- source/sw/src/input.cpp | 2 +- source/sw/src/player.cpp | 48 ++++++++++++++++++++++------------------ source/sw/src/track.cpp | 2 +- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 0ee25028a..1e9970f70 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1699,7 +1699,7 @@ drawscreen(PLAYERp pp, double smoothratio) tx = tx + quake_x; ty = ty + quake_y; //tq16horiz = tq16horiz + IntToFixed(quake_x); - tq16ang = IntToFixed(NORM_ANGLE(FixedToInt(tq16ang) + quake_ang)); + tq16ang = NORM_Q16ANGLE(tq16ang + quake_ang); if (pp->sop_remote) { diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 21c898192..8307d96b6 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -278,7 +278,7 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool if (!cl_syncinput) { if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN)) - DoPlayerTurn(pp, q16avel, scaleAdjust); + DoPlayerTurn(pp, !TEST(pp->Flags, PF_DEAD) || TEST(pp->Flags, PF_DEAD) && TEST(pp->Flags, PF_DEAD_HEAD|PF_HEAD_CONTROL) ? q16avel : 0, scaleAdjust); if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM)) DoPlayerHorizon(pp, q16horz, scaleAdjust); } diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 5da89c579..9ca36b9d6 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1608,17 +1608,22 @@ DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust) if (q16avel != 0) { 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 (!cl_syncinput && pp->angAdjust) + { + pp->q16ang = (pp->q16ang + FloatToFixed(scaleAdjust * pp->angAdjust)) & 0x7FFFFFF; + } - if (!Prediction && pp->PlayerUnderSprite >= 0) - { - sprite[pp->PlayerUnderSprite].ang = FixedToInt(pp->q16ang); - } + // 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); } } @@ -3826,7 +3831,7 @@ DoPlayerClimb(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - pp->q16ang = IntToFixed(pp->LadderAngle); + playerSetAngle(pp, pp->LadderAngle); } } } @@ -4285,7 +4290,7 @@ PlayerOnLadder(PLAYERp pp) pp->lx = lsp->x + nx * 5; pp->ly = lsp->y + ny * 5; - pp->q16ang = IntToFixed(pp->LadderAngle); + playerSetAngle(pp, pp->LadderAngle); return TRUE; } @@ -5522,7 +5527,7 @@ DoPlayerBeginOperate(PLAYERp pp) pp->sop = pp->sop_control = sop; sop->controller = pp->SpriteP; - pp->q16ang = IntToFixed(sop->ang); + playerSetAngle(pp, sop->ang); pp->posx = sop->xmid; pp->posy = sop->ymid; COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); @@ -5607,7 +5612,7 @@ DoPlayerBeginRemoteOperate(PLAYERp pp, SECTOR_OBJECTp sop) save_sectnum = pp->cursectnum; - pp->q16ang = IntToFixed(sop->ang); + playerSetAngle(pp, sop->ang); pp->posx = sop->xmid; pp->posy = sop->ymid; COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); @@ -5738,7 +5743,7 @@ DoPlayerStopOperate(PLAYERp pp) if (TEST_BOOL1(pp->remote_sprite)) pp->q16ang = pp->oq16ang = IntToFixed(pp->remote_sprite->ang); else - pp->q16ang = pp->oq16ang = IntToFixed(getangle(pp->sop_remote->xmid - pp->posx, pp->sop_remote->ymid - pp->posy)); + pp->q16ang = pp->oq16ang = gethiq16angle(pp->sop_remote->xmid - pp->posx, pp->sop_remote->ymid - pp->posy); } if (pp->sop_control) @@ -6393,15 +6398,14 @@ void DoPlayerDeathFollowKiller(PLAYERp pp) if (pp->Killer > -1) { SPRITEp kp = &sprite[pp->Killer]; - fixed_t q16ang2, delta_q16ang; - if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, - pp->posx, pp->posy, pp->posz, pp->cursectnum)) + if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum)) { - q16ang2 = gethiq16angle(kp->x - pp->posx, kp->y - pp->posy); - - delta_q16ang = GetDeltaQ16Angle(q16ang2, pp->q16ang); - pp->q16ang = NORM_Q16ANGLE(pp->q16ang + (delta_q16ang >> 4)); + if (!cl_syncinput) + { + SET(pp->Flags2, PF2_INPUT_CAN_TURN); + } + playerAddAngle(pp, GetDeltaQ16Angle(gethiq16angle(kp->x - pp->posx, kp->y - pp->posy), pp->q16ang) / (double)(FRACUNIT << 4)); } } } @@ -7439,7 +7443,7 @@ domovethings(void) // auto tracking mode for single player multi-game if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex) { - Player[screenpeek].q16ang = IntToFixed(getangle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy)); + playerSetAngle(&Player[screenpeek], gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy) / (double)(FRACUNIT)); } if (!TEST(pp->Flags, PF_DEAD)) diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index 37a15a414..05112c290 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -1676,7 +1676,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 - pp->q16ang = NORM_Q16ANGLE(pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng)); + playerSetAngle(pp, (pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng)) / (double)(FRACUNIT)); UpdatePlayerSprite(pp); }