From d9a6aa323b00e23e7c858e1feeacfd3ee26bc298 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Fri, 4 Oct 2024 18:24:47 +0200 Subject: Smoother keyboard movement This change addresses the slight stutter and broken animation playback when walking with the keyboard. Once the end of the path has been reached but a movement key is still held, the LocalPlayer now immediately calculates a new path rather than waiting on the next logic update. --- src/localplayer.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/localplayer.cpp') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5075c44c..40849379 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -700,23 +700,33 @@ void LocalPlayer::setWalkingDir(int dir) // Don't compute a new path before the last one set by keyboard is finished. // This permits to avoid movement glitches and server spamming. - const Vector &pos = getPosition(); - const Vector &dest = getDestination(); - if (!isPathSetByMouse() && (pos.x != dest.x || pos.y != dest.y)) - return; + if (!isPathSetByMouse()) + { + const Vector &pos = getPosition(); + const Vector &dest = getDestination(); + + if (pos.x != dest.x || pos.y != dest.y) + { + mWalkingDir = dir; + return; + } + } // If the player is pressing a key, and its different from what he has // been pressing, stop (do not send this stop to the server) and // start in the new direction - if (dir && (dir != getWalkingDir())) + if (dir && dir != mWalkingDir) + { local_player->stopWalking(false); - - // Else, he is not pressing a key, - // and the current path hasn't been sent by mouse, - // then let the path die (1/2 tile after that.) - // This permit to avoid desyncs with other clients. + } + // Else, he is not pressing a key, and the current path hasn't been sent by + // mouse, then let the path die (1/2 tile after that.) This permit to avoid + // desyncs with other clients. else if (!dir) + { + mWalkingDir = 0; return; + } cancelGoToTarget(); -- cgit v1.2.3-70-g09d2