diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-15 15:33:33 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-04-18 01:15:22 +0200 |
commit | a8489adc8c4f6fe8355ea1abbfb7be12d0e73b27 (patch) | |
tree | fbfb89e8740d61526bf07932953cc9645b8d7302 /src | |
parent | 88934303761ba950be56eac8b60de2dede88a29f (diff) | |
download | mana-client-a8489adc8c4f6fe8355ea1abbfb7be12d0e73b27.tar.gz mana-client-a8489adc8c4f6fe8355ea1abbfb7be12d0e73b27.tar.bz2 mana-client-a8489adc8c4f6fe8355ea1abbfb7be12d0e73b27.tar.xz mana-client-a8489adc8c4f6fe8355ea1abbfb7be12d0e73b27.zip |
Added a client-side position tolerance check.
This is based on the information given by the server which now
permit resyncs when necessary.
Reviewed-by: Thorbjorn.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/manaserv/beinghandler.cpp | 34 | ||||
-rw-r--r-- | src/net/manaserv/manaserv_protocol.h | 2 |
2 files changed, 26 insertions, 10 deletions
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 6e9b3645..414f914d 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -40,6 +40,8 @@ #include "utils/gettext.h" +#define POSITION_DIFF_TOLERANCE 48 + namespace ManaServ { BeingHandler::BeingHandler() @@ -217,20 +219,27 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) int id = msg.readInt16(); int flags = msg.readInt8(); Being *being = actorSpriteManager->findBeing(id); - int sx = 0; - int sy = 0; - int speed = 0; + int sx, sy, dx, dy, speed = 0; + + if ((!flags & (MOVING_POSITION | MOVING_DESTINATION))) + continue; if (flags & MOVING_POSITION) { sx = msg.readInt16(); sy = msg.readInt16(); - speed = msg.readInt8(); } - if (!being || !(flags & (MOVING_POSITION | MOVING_DESTINATION))) + + if (flags & MOVING_DESTINATION) { - continue; + dx = msg.readInt16(); + dy = msg.readInt16(); + speed = msg.readInt8(); } + + if (!being) + continue; + if (speed) { /* @@ -241,18 +250,25 @@ void BeingHandler::handleBeingsMoveMessage(Net::MessageIn &msg) * with the Being::logic() function calls * @see MILLISECONDS_IN_A_TICK */ - being->setWalkSpeed( - giveSpeedInPixelsPerTicks((float) speed / 10)); + being->setWalkSpeed(giveSpeedInPixelsPerTicks((float) speed / 10)); } // Ignore messages from the server for the local player if (being == player_node) continue; + // If the position differs too much from the actual one, we resync + // the being position if (flags & MOVING_POSITION) { - being->setDestination(sx, sy); + Vector serverPos(sx, sy); + if (serverPos.length() + - being->getPosition().length() > POSITION_DIFF_TOLERANCE) + being->setPosition(serverPos); } + + if (flags & MOVING_DESTINATION) + being->setDestination(dx, dy); } } diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h index 5726ab92..b5023a42 100644 --- a/src/net/manaserv/manaserv_protocol.h +++ b/src/net/manaserv/manaserv_protocol.h @@ -118,7 +118,7 @@ enum { PGMSG_DIRECTION_CHANGE = 0x0272, // B Direction GPMSG_BEING_DIR_CHANGE = 0x0273, // W being id, B direction GPMSG_BEING_HEALTH_CHANGE = 0x0274, // W being id, W hp, W max hp - GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, W*2 position, B speed] }* + GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, [W*2 position,] W*2 destination, B speed] }* GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* PGMSG_ATTACK = 0x0290, // W being id GPMSG_BEING_ATTACK = 0x0291, // W being id, B direction, B attacktype |