summaryrefslogtreecommitdiff
path: root/src/net/tmwa/messageout.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2011-06-02 23:49:49 -0700
committerJared Adams <jaxad0127@gmail.com>2011-06-03 11:03:25 -0600
commit894038adf52a3e2b42542239a147d6c1cc1ad204 (patch)
treeb881994e4605bcf0ba2d1df68068a78fb21ecf01 /src/net/tmwa/messageout.cpp
parentd50f35d13e73b72eae1d744971657bd665aa1f33 (diff)
downloadmana-894038adf52a3e2b42542239a147d6c1cc1ad204.tar.gz
mana-894038adf52a3e2b42542239a147d6c1cc1ad204.tar.bz2
mana-894038adf52a3e2b42542239a147d6c1cc1ad204.tar.xz
mana-894038adf52a3e2b42542239a147d6c1cc1ad204.zip
Cleanup network code to use unsigned integers of the relevant size
Diffstat (limited to 'src/net/tmwa/messageout.cpp')
-rw-r--r--src/net/tmwa/messageout.cpp47
1 files changed, 17 insertions, 30 deletions
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index 8b407c47..71b8f756 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -31,7 +31,7 @@
namespace TmwAthena {
-MessageOut::MessageOut(short id):
+MessageOut::MessageOut(Uint16 id):
Net::MessageOut(id)
{
mNetwork = TmwAthena::Network::instance();
@@ -44,52 +44,39 @@ void MessageOut::expand(size_t bytes)
mNetwork->mOutSize += bytes;
}
-void MessageOut::writeInt16(Sint16 value)
+void MessageOut::writeInt16(Uint16 value)
{
expand(2);
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- Sint16 swap=SDL_Swap16(value);
- memcpy(mData + mPos, &swap, sizeof(Sint16));
-#else
- memcpy(mData + mPos, &value, sizeof(Sint16));
-#endif
+ mData[mPos] = value;
+ mData[mPos + 1] = value >> 8;
mPos += 2;
}
-void MessageOut::writeInt32(Sint32 value)
+void MessageOut::writeInt32(Uint32 value)
{
expand(4);
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- Sint32 swap=SDL_Swap32(value);
- memcpy(mData + mPos, &swap, sizeof(Sint32));
-#else
- memcpy(mData + mPos, &value, sizeof(Sint32));
-#endif
+ mData[mPos] = value;
+ mData[mPos + 1] = value >> 8;
+ mData[mPos + 2] = value >> 16;
+ mData[mPos + 3] = value >> 24;
mPos += 4;
}
-#define LOBYTE(w) ((unsigned char)(w))
-#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8))
-
-void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
- unsigned char direction)
+void MessageOut::writeCoordinates(Uint16 x, Uint16 y, Uint8 direction)
{
char *data = mData + mPos;
mNetwork->mOutSize += 3;
mPos += 3;
- short temp;
- temp = x;
+ Uint16 temp = x;
temp <<= 6;
- data[0] = 0;
- data[1] = 1;
- data[2] = 2;
- data[0] = HIBYTE(temp);
- data[1] = (unsigned char) temp;
+ data[0] = temp >> 8;
+ data[1] = temp;
+
temp = y;
temp <<= 4;
- data[1] |= HIBYTE(temp);
- data[2] = LOBYTE(temp);
+ data[1] |= temp << 8;
+ data[2] = temp;
// Translate direction to eAthena format
switch (direction)
@@ -120,7 +107,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
break;
default:
// OOPSIE! Impossible or unknown
- direction = (unsigned char) -1;
+ direction = 15;
}
data[2] |= direction;
}