diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-15 23:09:17 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-15 23:09:17 +0100 |
commit | 29259f72663e0eb1820b4d4a0f018acef61bfb2c (patch) | |
tree | ec5b5874e2860200b1330c9cb7ca6675f4430170 /src/net/tmwa/beinghandler.cpp | |
parent | 2f48ff6c56db96fb2c0a51d9e4a6522e07ab1339 (diff) | |
download | mana-29259f72663e0eb1820b4d4a0f018acef61bfb2c.tar.gz mana-29259f72663e0eb1820b4d4a0f018acef61bfb2c.tar.bz2 mana-29259f72663e0eb1820b4d4a0f018acef61bfb2c.tar.xz mana-29259f72663e0eb1820b4d4a0f018acef61bfb2c.zip |
Made the tA Beinghandler avoid dealing with flawed coordinates.
Also fixed again a condition in Being::logic().
I'll beautify the code in tmwAthena:Beinghandler once everything
will be working better.
Note: I also suspect current clients to flood the server with
keyboard messages, hence blocking the animation when they are remote.
I'll need to test that with someone having the same client than here..
Diffstat (limited to 'src/net/tmwa/beinghandler.cpp')
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 132 |
1 files changed, 81 insertions, 51 deletions
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 40c1107b..40dfe083 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -216,31 +216,40 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - dstBeing->setAction(Being::STAND); - Vector pos(srcX * tileWidth + tileWidth / 2, - srcY * tileHeight + tileHeight / 2); - - 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); + //dstBeing->setAction(Being::STAND); Useless + // Avoid dealing with flawed destination + if (srcX && srcY && dstX && dstY) + { + 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(dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs(dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + // We turn the destination back to a pixel one. + dstBeing->setDestination(dest.x, dest.y); + } } else { Uint8 dir; Uint16 x, y; msg.readCoordinates(x, y, dir); - Vector pos(x * tileWidth + tileWidth / 2, - y * tileHeight + tileHeight / 2); - dstBeing->setPosition(pos); - dstBeing->setDirection(dir); + + // Avoid dealing with flawed destination + if (x && y) + { + Vector pos(x * tileWidth + tileWidth / 2, + y * tileHeight + tileHeight / 2); + dstBeing->setPosition(pos); + dstBeing->setDirection(dir); + } } msg.readInt8(); // unknown @@ -281,20 +290,23 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) msg.readCoordinatePair(srcX, srcY, dstX, dstY); msg.readInt32(); // Server tick - //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->setAction(Being::STAND); // Useless. + // Avoid dealing with flawed destination + if (srcX && srcY && dstX && dstY) + { + 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(dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs(dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); - dstBeing->setDestination(dest.x, dest.y); + dstBeing->setDestination(dest.x, dest.y); + } } break; @@ -603,28 +615,39 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) { Uint16 srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY); - 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); + //dstBeing->setAction(Being::STAND); // Useless. + // Avoid dealing with flawed destination + if (srcX && srcY && dstX && dstY) + { + 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(dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE + || std::abs(dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE) + dstBeing->setPosition(pos); + + dstBeing->setDestination(dest.x, dest.y); + } } else { Uint8 dir; Uint16 x, y; msg.readCoordinates(x, y, dir); - dstBeing->setPosition(Vector(x * tileWidth + tileWidth / 2, - y * tileHeight + tileHeight / 2)); - dstBeing->setDirection(dir); + // Avoid dealing with flawed destination + if (x && y) + { + Vector pos(x * tileWidth + tileWidth / 2, + y * tileHeight + tileHeight / 2); + dstBeing->setPosition(pos); + dstBeing->setDirection(dir); + } } gmstatus = msg.readInt16(); @@ -681,10 +704,17 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) Uint16 x, y; x = msg.readInt16(); y = msg.readInt16(); - dstBeing->setPosition(Vector(x * tileWidth + tileWidth / 2, - y * tileHeight + tileHeight / 2)); - if (dstBeing->getCurrentAction() == Being::MOVE) - dstBeing->setAction(Being::STAND); + // Avoid dealing with flawed destination + if (x && y) + { + Vector pos(x * tileWidth + tileWidth / 2, + y * tileHeight + tileHeight / 2); + dstBeing->setPosition(pos); + if (dstBeing->getCurrentAction() == Being::MOVE) + { + dstBeing->setAction(Being::STAND); + } + } } } break; |