diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-11 16:47:03 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-16 00:18:39 +0200 |
commit | 6f247d1fa09ce55cd96bb0fd75315fdd4e385c50 (patch) | |
tree | 72628312e231b6f0d7ee57cc07ab02c78af58c4e | |
parent | 3213901def93ebe3fe648fcbf712f4e9450b8daf (diff) | |
download | mana-6f247d1fa09ce55cd96bb0fd75315fdd4e385c50.tar.gz mana-6f247d1fa09ce55cd96bb0fd75315fdd4e385c50.tar.bz2 mana-6f247d1fa09ce55cd96bb0fd75315fdd4e385c50.tar.xz mana-6f247d1fa09ce55cd96bb0fd75315fdd4e385c50.zip |
Fixed player movement desyncs on tile-based implementation.
The new destination wasn't sent correctly since the destination
was centered but checked pixel exact afterward.
Now the destination check has been adapted for tile-wise
implementation, leading to an almost desync free movement.
Hurray!
-rw-r--r-- | src/localplayer.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 8e75333f..ad9d181a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -659,14 +659,39 @@ void LocalPlayer::setTarget(Being *target) void LocalPlayer::setDestination(int x, int y) { + int srcX = x; + int srcY = y; + int dstX = (int)mDest.x; + int dstY = (int)mDest.y; + int tileWidth = mMap->getTileWidth(); + int tileHeight = mMap->getTileHeight(); + if (!Net::getPlayerHandler()->usePixelPrecision()) + { + // For tile-based clients, we accept positions on the same tile. + srcX = srcX / tileWidth; + srcY = srcY / tileHeight; + dstX = dstX / tileWidth; + dstY = dstY / tileHeight; + } + // Only send a new message to the server when destination changes - if (x != mDest.x || y != mDest.y) + if (srcX != dstX || srcY != dstY) { Being::setDestination(x, y); + // Note: Being::setDestination() updates mDest, so we get the new + // destination. + dstX = (int)mDest.x; + dstY = (int)mDest.y; + + if (!Net::getPlayerHandler()->usePixelPrecision()) + { + dstX = dstX / tileWidth; + dstY = dstY / tileHeight; + } // If the destination given to being class is accepted, // we inform the Server. - if ((x == mDest.x && y == mDest.y)) + if (srcX == dstX && srcY == dstY) Net::getPlayerHandler()->setDestination(x, y, mDirection); } |