From 6f247d1fa09ce55cd96bb0fd75315fdd4e385c50 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Mon, 11 Apr 2011 16:47:03 +0200 Subject: 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! --- src/localplayer.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3-70-g09d2