summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-04 18:24:47 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-08 21:03:44 +0200
commitd9a6aa323b00e23e7c858e1feeacfd3ee26bc298 (patch)
treec5fb35d658cdfd7c376a2ae2cf8f2523406aaeeb /src/localplayer.cpp
parent573df67919ec5f65a6b2ad51ed8aed31c9cfe4a6 (diff)
downloadmana-d9a6aa323b00e23e7c858e1feeacfd3ee26bc298.tar.gz
mana-d9a6aa323b00e23e7c858e1feeacfd3ee26bc298.tar.bz2
mana-d9a6aa323b00e23e7c858e1feeacfd3ee26bc298.tar.xz
mana-d9a6aa323b00e23e7c858e1feeacfd3ee26bc298.zip
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.
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp30
1 files changed, 20 insertions, 10 deletions
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();