diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-09 01:14:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-09 01:14:05 +0300 |
commit | 8d1a43609fcf67bbffb26ab52fdb07f095f602b8 (patch) | |
tree | 7a9e548023cdf4f705a3a042aefb66d47645f74a /src | |
parent | d9c62405db9a3f8bffaa5789bd63f59a65e29e3a (diff) | |
download | manaplus-8d1a43609fcf67bbffb26ab52fdb07f095f602b8.tar.gz manaplus-8d1a43609fcf67bbffb26ab52fdb07f095f602b8.tar.bz2 manaplus-8d1a43609fcf67bbffb26ab52fdb07f095f602b8.tar.xz manaplus-8d1a43609fcf67bbffb26ab52fdb07f095f602b8.zip |
improve messageout class.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/eathena/messageout.cpp | 18 | ||||
-rw-r--r-- | src/net/eathena/messageout.h | 11 | ||||
-rw-r--r-- | src/net/messageout.cpp | 6 | ||||
-rw-r--r-- | src/net/tmwa/messageout.cpp | 18 | ||||
-rw-r--r-- | src/net/tmwa/messageout.h | 11 |
5 files changed, 33 insertions, 31 deletions
diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp index f25666526..734ce4057 100644 --- a/src/net/eathena/messageout.cpp +++ b/src/net/eathena/messageout.cpp @@ -39,7 +39,7 @@ namespace EAthena { -MessageOut::MessageOut(short id): +MessageOut::MessageOut(const short id): Net::MessageOut(id), mNetwork(EAthena::Network::instance()) { @@ -49,15 +49,15 @@ MessageOut::MessageOut(short id): writeInt16(id); } -void MessageOut::expand(size_t bytes) +void MessageOut::expand(const size_t bytes) { mNetwork->mOutSize += static_cast<unsigned>(bytes); PacketCounters::incOutBytes(static_cast<int>(bytes)); } -void MessageOut::writeInt16(int16_t value) +void MessageOut::writeInt16(const int16_t value) { - DEBUGLOG("writeInt16: " + toString(static_cast<int>(value))); + DEBUGLOG("writeInt16: " + toStringPrint(static_cast<int>(value))); expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap = SDL_Swap16(value); @@ -69,9 +69,9 @@ void MessageOut::writeInt16(int16_t value) PacketCounters::incOutBytes(2); } -void MessageOut::writeInt32(int32_t value) +void MessageOut::writeInt32(const int32_t value) { - DEBUGLOG("writeInt32: " + toString(value)); + DEBUGLOG("writeInt32: " + toStringPrint(value)); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); @@ -87,7 +87,8 @@ void MessageOut::writeInt32(int32_t value) #define HIBYTE(w) (static_cast<unsigned char>(( \ static_cast<unsigned short>(w)) >> 8)) -void MessageOut::writeCoordinates(unsigned short x, unsigned short y, +void MessageOut::writeCoordinates(const unsigned short x, + const unsigned short y, unsigned char direction) { DEBUGLOG(strprintf("writeCoordinates: %u,%u %u", x, y, direction)); @@ -95,8 +96,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y, mNetwork->mOutSize += 3; mPos += 3; - short temp; - temp = x; + short temp = x; temp <<= 6; data[0] = 0; data[1] = 1; diff --git a/src/net/eathena/messageout.h b/src/net/eathena/messageout.h index 7f8b6cd45..05c82b6f5 100644 --- a/src/net/eathena/messageout.h +++ b/src/net/eathena/messageout.h @@ -46,25 +46,26 @@ class MessageOut final : public Net::MessageOut /** * Constructor. */ - MessageOut(short id); + MessageOut(const short id); A_DELETE_COPY(MessageOut) - void writeInt16(int16_t value); /**< Writes a short. */ + void writeInt16(const int16_t value); /**< Writes a short. */ - void writeInt32(int32_t value); /**< Writes a long. */ + void writeInt32(const int32_t value); /**< Writes a long. */ /** * Encodes coordinates and direction in 3 bytes. */ - void writeCoordinates(unsigned short x, unsigned short y, + void writeCoordinates(const unsigned short x, + const unsigned short y, unsigned char direction); void resetPos() { mPos = 0; } private: - void expand(size_t size); + void expand(const size_t size); Network *mNetwork; }; diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 80255297e..3c20bce00 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -47,7 +47,7 @@ MessageOut::MessageOut(short id A_UNUSED): void MessageOut::writeInt8(int8_t value) { - DEBUGLOG("writeInt8: " + toString(static_cast<int>(value))); + DEBUGLOG("writeInt8: " + toStringPrint(static_cast<int>(value))); expand(1); mData[mPos] = value; mPos += 1; @@ -56,7 +56,6 @@ void MessageOut::writeInt8(int8_t value) void MessageOut::writeString(const std::string &string, int length) { - DEBUGLOG("writeString: " + string); int stringLength = static_cast<int>(string.length()); if (length < 0) { @@ -79,12 +78,12 @@ void MessageOut::writeString(const std::string &string, int length) memset(mData + mPos + stringLength, '\0', length - stringLength); mPos += length; + DEBUGLOG("writeString: " + string); PacketCounters::incOutBytes(length); } void MessageOut::writeStringNoLog(const std::string &string, int length) { - DEBUGLOG("writeString: ***"); int stringLength = static_cast<int>(string.length()); if (length < 0) { @@ -107,6 +106,7 @@ void MessageOut::writeStringNoLog(const std::string &string, int length) memset(mData + mPos + stringLength, '\0', length - stringLength); mPos += length; + DEBUGLOG("writeString: ***"); PacketCounters::incOutBytes(length); } diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 1caa53d0d..d520b407e 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -39,7 +39,7 @@ namespace TmwAthena { -MessageOut::MessageOut(short id): +MessageOut::MessageOut(const short id): Net::MessageOut(id), mNetwork(TmwAthena::Network::instance()) { @@ -49,15 +49,15 @@ MessageOut::MessageOut(short id): writeInt16(id); } -void MessageOut::expand(size_t bytes) +void MessageOut::expand(const size_t bytes) { mNetwork->mOutSize += static_cast<unsigned>(bytes); PacketCounters::incOutBytes(static_cast<int>(bytes)); } -void MessageOut::writeInt16(int16_t value) +void MessageOut::writeInt16(const int16_t value) { - DEBUGLOG("writeInt16: " + toString(static_cast<int>(value))); + DEBUGLOG("writeInt16: " + toStringPrint(static_cast<int>(value))); expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap = SDL_Swap16(value); @@ -69,9 +69,9 @@ void MessageOut::writeInt16(int16_t value) PacketCounters::incOutBytes(2); } -void MessageOut::writeInt32(int32_t value) +void MessageOut::writeInt32(const int32_t value) { - DEBUGLOG("writeInt32: " + toString(value)); + DEBUGLOG("writeInt32: " + toStringPrint(value)); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); @@ -87,7 +87,8 @@ void MessageOut::writeInt32(int32_t value) #define HIBYTE(w) (static_cast<unsigned char>(( \ static_cast<unsigned short>(w)) >> 8)) -void MessageOut::writeCoordinates(unsigned short x, unsigned short y, +void MessageOut::writeCoordinates(const unsigned short x, + const unsigned short y, unsigned char direction) { DEBUGLOG(strprintf("writeCoordinates: %u,%u %u", @@ -97,8 +98,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y, mNetwork->mOutSize += 3; mPos += 3; - short temp; - temp = x; + short temp = x; temp <<= 6; data[0] = 0; data[1] = 1; diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index 370651659..285e333d0 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -46,25 +46,26 @@ class MessageOut final : public Net::MessageOut /** * Constructor. */ - MessageOut(short id); + MessageOut(const short id); A_DELETE_COPY(MessageOut) - void writeInt16(int16_t value); /**< Writes a short. */ + void writeInt16(const int16_t value); /**< Writes a short. */ - void writeInt32(int32_t value); /**< Writes a long. */ + void writeInt32(const int32_t value); /**< Writes a long. */ /** * Encodes coordinates and direction in 3 bytes. */ - void writeCoordinates(unsigned short x, unsigned short y, + void writeCoordinates(const unsigned short x, + const unsigned short y, unsigned char direction); void resetPos() { mPos = 0; } private: - void expand(size_t size); + void expand(const size_t size); Network *mNetwork; }; |