diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-09-02 13:03:20 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-09-02 13:03:20 +0000 |
commit | 3bce14c324e1d7bbd058e18072acc7bd953d6475 (patch) | |
tree | e51a4c8fd00bd0be1c63faae4984aaf72a72a6bc /src | |
parent | 2b322bf18d80acb464a9dc1820e581e7204cca1e (diff) | |
download | mana-client-3bce14c324e1d7bbd058e18072acc7bd953d6475.tar.gz mana-client-3bce14c324e1d7bbd058e18072acc7bd953d6475.tar.bz2 mana-client-3bce14c324e1d7bbd058e18072acc7bd953d6475.tar.xz mana-client-3bce14c324e1d7bbd058e18072acc7bd953d6475.zip |
Removed pixel-based synchronisation. Added variable length move messages.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/beinghandler.cpp | 30 | ||||
-rw-r--r-- | src/net/messagein.cpp | 11 | ||||
-rw-r--r-- | src/net/messagein.h | 13 | ||||
-rw-r--r-- | src/net/protocol.h | 11 |
4 files changed, 59 insertions, 6 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 8ccd3dd6..eb5ccb57 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -442,13 +442,33 @@ void BeingHandler::handleBeingLeaveMessage(MessageIn &msg) void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) { - for (int nb = (msg.getLength() - 2) / (2 + 4 * 2); nb > 0; --nb) + while (msg.getUnreadLength()) { Uint16 id = msg.readShort(); + Uint8 flags = msg.readByte(); Being *being = beingManager->findBeing(id); - if (!being) continue; - int sx = msg.readShort(), sy = msg.readShort(), - dx = msg.readShort(), dy = msg.readShort(); + int sx = 0, sy = 0, dx = 0, dy = 0; + if (flags & MOVING_POSITION) + { + Uint16 sx2, sy2; + msg.readCoordinates(sx2, sy2); + sx = sx2 * 32 + 16; + sy = sy2 * 32 + 16; + } + if (flags & MOVING_DESTINATION) + { + dx = msg.readShort(); + dy = msg.readShort(); + if (!(flags & MOVING_POSITION)) + { + sx = dx; + sy = dy; + } + } + if (!being || !(flags & (MOVING_POSITION | MOVING_DESTINATION))) + { + continue; + } bool update = being != player_node; // the local player already knows where he wants to go if (abs(being->mX - sx) + abs(being->mY - sy) > 4 * 32) { @@ -457,7 +477,7 @@ void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) being->mY = sy; update = true; } - if (update) + if (update && (flags & MOVING_DESTINATION)) { being->setDestination(dx, dy); } diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 2c452a4d..a1707e06 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -77,6 +77,17 @@ long MessageIn::readLong() return value; } +void MessageIn::readCoordinates(Uint16 &x, Uint16 &y) +{ + if (mPos + 3 <= mLength) + { + unsigned char const *p = reinterpret_cast< unsigned char const * >(mData + mPos); + x = p[0] | ((p[1] & 0x07) << 8); + y = (p[1] >> 3) | ((p[2] & 0x3F) << 5); + } + mPos += 3; +} + std::string MessageIn::readString(int length) { // Get string length diff --git a/src/net/messagein.h b/src/net/messagein.h index d5a7593f..68bbb933 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -26,6 +26,8 @@ #include <string> +#include <SDL_types.h> + /** * Used for parsing an incoming message. */ @@ -49,6 +51,11 @@ class MessageIn long readLong(); /**< Reads a long. */ /** + * Reads a 3-byte block containing tile-based coordinates. + */ + void readCoordinates(Uint16 &x, Uint16 &y); + + /** * Reads a string. If a length is not given (-1), it is assumed * that the length of the string is stored in a short at the * start of the string. @@ -61,6 +68,12 @@ class MessageIn unsigned int getLength() { return mLength; } + /** + * Returns the length of unread data. + */ + unsigned int + getUnreadLength() { return mLength - mPos; } + private: const char* mData; /**< The message data. */ unsigned int mLength; /**< The length of the data. */ diff --git a/src/net/protocol.h b/src/net/protocol.h index f056f003..07b5c926 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -113,6 +113,7 @@ * - PGMSG_*: from client to game server * - GPMSG_*: from game server to client * Components: B byte, W word, D double word, S variable-size string + * C tile-based coordinates (B*3) */ enum { // Login/Register @@ -157,7 +158,7 @@ enum { // monster: W type id GPMSG_BEING_LEAVE = 0x0201, // W being id PGMSG_WALK = 0x0260, // W*2 destination - GPMSG_BEINGS_MOVE = 0x0280, // { W being id, W*2 position, W*2 destination }* + GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position] [, W*2 destination] }* PGMSG_SAY = 0x02A0, // S text GPMSG_SAY = 0x02A1, // W being id, S text PGMSG_USE_ITEM = 0x0300, // L item id @@ -238,4 +239,12 @@ enum { OBJECT_PLAYER }; +// Moving object flags +enum { + // Payload contains the current position. + MOVING_POSITION = 1, + // Payload contains the destination. + MOVING_DESTINATION = 2 +}; + #endif |