From 1dd5245158e7ce1e704d5ea1f464153d194bcfba Mon Sep 17 00:00:00 2001 From: staphen Date: Tue, 18 May 2021 23:21:07 -0400 Subject: [PATCH] Fix camera jerking when changing direction on controller. --- Source/controls/plrctrls.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 8dc928c4e..089b40198 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1078,6 +1078,19 @@ bool IsPathBlocked(int x, int y, int dir) return !PosOkPlayer(myplr, d1x, d1y) && !PosOkPlayer(myplr, d2x, d2y); } +bool CanChangeDirection(const PlayerStruct &player) +{ + if (player._pmode == PM_STAND) + return true; + if (player._pmode == PM_ATTACK && player.AnimInfo.CurrentFrame > player._pAFNum) + return true; + if (player._pmode == PM_RATTACK && player.AnimInfo.CurrentFrame > player._pAFNum) + return true; + if (player._pmode == PM_SPELL && player.AnimInfo.CurrentFrame > player._pSFNum) + return true; + return false; +} + void WalkInDir(int playerId, AxisDirection dir) { const int x = plr[playerId].position.future.x; @@ -1092,7 +1105,9 @@ void WalkInDir(int playerId, AxisDirection dir) const direction pdir = FaceDir[static_cast(dir.x)][static_cast(dir.y)]; const int dx = x + Offsets[pdir][0]; const int dy = y + Offsets[pdir][1]; - plr[playerId]._pdir = pdir; + + if (CanChangeDirection(plr[playerId])) + plr[playerId]._pdir = pdir; if (PosOkPlayer(playerId, dx, dy) && IsPathBlocked(x, y, pdir)) return; // Don't start backtrack around obstacles