diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-15 19:18:46 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-15 19:18:46 +0100 |
commit | d61c66a34b1fbb88267cf2ef9adf8bc03d52cb84 (patch) | |
tree | d999d3eb022287e611afec03cb151ce3e5d71d5d /src/net/tmwa/beinghandler.cpp | |
parent | 6265ef44e8308ac9a27abec68839c2a884a8f09e (diff) | |
download | mana-d61c66a34b1fbb88267cf2ef9adf8bc03d52cb84.tar.gz mana-d61c66a34b1fbb88267cf2ef9adf8bc03d52cb84.tar.bz2 mana-d61c66a34b1fbb88267cf2ef9adf8bc03d52cb84.tar.xz mana-d61c66a34b1fbb88267cf2ef9adf8bc03d52cb84.zip |
Add a tolerance check on current position to limit desyncs.
Also removed dead code.
Diffstat (limited to 'src/net/tmwa/beinghandler.cpp')
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index ddb15428..40c1107b 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -39,9 +39,13 @@ #include "resources/emotedb.h" #include <iostream> +#include <cmath> namespace TmwAthena { +// Number of pixels where we decide that the position doesn't need to be reset. +static const float POS_DEST_DIFF_TOLERANCE = 48.0f; + BeingHandler::BeingHandler(bool enableSync): mSync(enableSync) { @@ -215,10 +219,17 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) dstBeing->setAction(Being::STAND); Vector pos(srcX * tileWidth + tileWidth / 2, srcY * tileHeight + tileHeight / 2); - dstBeing->setPosition(pos); - // We turn the destination back to a pixel one. + dstX = dstX * tileWidth + tileWidth / 2; dstY = dstY * tileHeight + tileHeight / 2; + // Don't set the position as the movement algorithm can guess + // it and it would break the animation played, when we're + // close enough. + if (std::abs((float)dstX - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs((float)dstY - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + // We turn the destination back to a pixel one. dstBeing->setDestination(dstX, dstY); } else @@ -249,6 +260,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_BEING_MOVE2: + { /* * A simplified movement packet, used by the * later versions of eAthena for both mobs and @@ -269,11 +281,21 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) msg.readCoordinatePair(srcX, srcY, dstX, dstY); msg.readInt32(); // Server tick - dstBeing->setAction(Being::STAND); - dstBeing->setPosition(Vector(srcX * tileWidth + tileWidth / 2, - srcY * tileHeight + tileHeight / 2)); - dstBeing->setDestination(dstX * tileWidth + tileWidth / 2, - dstY * tileHeight + tileHeight / 2); + //dstBeing->setAction(Being::STAND); <-- Not needed anymore. + + Vector pos(srcX * tileWidth + tileWidth / 2, + srcY * tileHeight + tileHeight / 2); + Vector dest(dstX * tileWidth + tileWidth / 2, + dstY * tileHeight + tileHeight / 2); + // Don't set the position as the movement algorithm can guess + // it and it would break the animation played, when we're + // close enough. + if (std::abs((float)dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs((float)dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + dstBeing->setDestination(dest.x, dest.y); + } break; case SMSG_BEING_REMOVE: @@ -581,10 +603,19 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - dstBeing->setPosition(Vector(srcX * tileWidth + tileWidth / 2, - srcY * tileHeight + tileHeight / 2)); - dstBeing->setDestination(dstX * tileWidth + tileWidth / 2, - dstY * tileHeight + tileHeight / 2); + Vector pos(srcX * tileWidth + tileWidth / 2, + srcY * tileHeight + tileHeight / 2); + Vector dest(dstX * tileWidth + tileWidth / 2, + dstY * tileHeight + tileHeight / 2); + + // Don't set the position as the movement algorithm can guess + // it and it would break the animation played, when we're + // close enough. + if (std::abs((float)dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs((float)dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + dstBeing->setDestination(dest.x, dest.y); } else { |