summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-09-02 13:05:06 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-09-02 13:05:06 +0000
commit0f3f5ed0b20a34dfa787365e224ba3f49bbc9995 (patch)
tree37ad2a3aebeca57d859cffe0cbb92822a40349c4
parent379c0e936e090a19d295d8514cf94b4fb367eae6 (diff)
downloadmanaserv-0f3f5ed0b20a34dfa787365e224ba3f49bbc9995.tar.gz
manaserv-0f3f5ed0b20a34dfa787365e224ba3f49bbc9995.tar.bz2
manaserv-0f3f5ed0b20a34dfa787365e224ba3f49bbc9995.tar.xz
manaserv-0f3f5ed0b20a34dfa787365e224ba3f49bbc9995.zip
Removed pixel-based synchronisation. Added variable length move messages.
-rw-r--r--ChangeLog4
-rw-r--r--src/defines.h11
-rw-r--r--src/messageout.cpp12
-rw-r--r--src/messageout.h5
-rw-r--r--src/state.cpp26
5 files changed, 52 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index d0260c13..cccf08a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,10 @@
src/player.cpp, src/object.h, src/state.cpp, src/state.cpp,
src/defines.h, src/player.h, src/gamehandler.cpp: Decorrelated moving
object IDs from character database IDs. Switched to short IDs instead.
+ * src/messageout.cpp, src/messageout.h, src/state.cpp, src/defines.h:
+ Removed pixel-based synchronisation. Added variable length move
+ messages. Changed default buffer size of outgoing packets.
+
2006-08-28 Eugenio Favalli <elvenprogrammer@gmail.com>
diff --git a/src/defines.h b/src/defines.h
index 8f8988d2..335631c3 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -109,6 +109,7 @@ const unsigned int MAX_CLIENTS = 1024,
* - 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
@@ -149,7 +150,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
@@ -242,4 +243,12 @@ enum {
OBJECT_PLAYER // A normal being
};
+// Moving object flags
+enum {
+ // Payload contains the current position.
+ MOVING_POSITION = 1,
+ // Payload contains the destination.
+ MOVING_DESTINATION = 2
+};
+
#endif // _TMWSERV_DEFINES_H_
diff --git a/src/messageout.cpp b/src/messageout.cpp
index 71e81542..7b547bb1 100644
--- a/src/messageout.cpp
+++ b/src/messageout.cpp
@@ -30,7 +30,7 @@
#include <enet/enet.h>
/** Initial amount of bytes allocated for the messageout data buffer. */
-const unsigned int INITIAL_DATA_CAPACITY = 2;
+const unsigned int INITIAL_DATA_CAPACITY = 16;
/** Factor by which the messageout data buffer is increased when too small. */
const unsigned int CAPACITY_GROW_FACTOR = 2;
@@ -97,6 +97,16 @@ MessageOut::writeLong(long value)
mPos += 4;
}
+void MessageOut::writeCoordinates(int x, int y)
+{
+ expand(mPos + 3);
+ char *p = mData + mPos;
+ p[0] = x & 0x00FF;
+ p[1] = ((x & 0x0700) >> 8) | ((y & 0x001F) << 3);
+ p[2] = (y & 0x07E0) >> 5;
+ mPos += 3;
+}
+
void
MessageOut::writeString(const std::string &string, int length)
{
diff --git a/src/messageout.h b/src/messageout.h
index 19997a0b..8ec6b171 100644
--- a/src/messageout.h
+++ b/src/messageout.h
@@ -57,6 +57,11 @@ class MessageOut
writeLong(long value); /**< Writes a long. */
/**
+ * Writes a 3-byte block containing tile-based coordinates.
+ */
+ void writeCoordinates(int x, int y);
+
+ /**
* Writes a string. If a fixed length is not given (-1), it is stored
* as a short at the start of the string.
*/
diff --git a/src/state.cpp b/src/state.cpp
index e3f833a8..f2f5b090 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -102,6 +102,8 @@ State::update()
!(*p)->isNew() && !(*o)->isNew();
bool willBeInRange = (*p)->getNextPosition().inRangeOf(on);
+ int flags = 0;
+
if (!wereInRange)
{
// o was outside p's range.
@@ -110,6 +112,7 @@ State::update()
// Nothing to report: o will not be inside p's range.
continue;
}
+ flags |= MOVING_DESTINATION;
int type = (*o)->getType();
MessageOut msg2(GPMSG_BEING_ENTER);
@@ -149,12 +152,27 @@ State::update()
/* At this point, either o has entered p's range, either o is
moving inside p's range. Report o's movements. */
+
Point od = (*o)->getDestination();
+ if (on.x != od.x || on.y != od.y)
+ {
+ flags |= MOVING_POSITION;
+ }
+
+ // TODO: updates destination only on changes.
+ flags |= MOVING_DESTINATION;
+
msg.writeShort((*o)->getPublicID());
- msg.writeShort(on.x);
- msg.writeShort(on.y);
- msg.writeShort(od.x);
- msg.writeShort(od.y);
+ msg.writeByte(flags);
+ if (flags & MOVING_POSITION)
+ {
+ msg.writeCoordinates(on.x / 32, on.y / 32);
+ }
+ if (flags & MOVING_DESTINATION)
+ {
+ msg.writeShort(od.x);
+ msg.writeShort(od.y);
+ }
}
// Don't send a packet if nothing happened in p's range.