From f98d003e354a1792117b7cbc771d1dd91475a156 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 18 Mar 2011 17:48:29 +0200 Subject: Fix most old style cast except manaserv and libxml2 defines. --- src/net/download.cpp | 3 ++- src/net/messagein.cpp | 19 +++++++++++-------- src/net/messageout.cpp | 2 +- src/net/tmwa/beinghandler.cpp | 13 +++++++------ src/net/tmwa/messagein.cpp | 2 +- src/net/tmwa/messageout.cpp | 10 +++++----- src/net/tmwa/network.cpp | 8 ++++---- src/net/tmwa/playerhandler.cpp | 5 +++-- 8 files changed, 34 insertions(+), 28 deletions(-) (limited to 'src/net') diff --git a/src/net/download.cpp b/src/net/download.cpp index 40d7c872a..aa2793ddb 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -92,7 +92,8 @@ unsigned long Download::fadler32(FILE *file) char *buffer = static_cast(malloc(fileSize)); const size_t read = fread(buffer, 1, fileSize, file); unsigned long adler = adler32(0L, Z_NULL, 0); - adler = adler32(static_cast(adler), (Bytef*)buffer, read); + adler = adler32(static_cast(adler), + reinterpret_cast(buffer), read); free(buffer); return adler; diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index e39a443f1..9ffc052f6 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -30,8 +30,8 @@ #include "utils/stringutils.h" #define MAKEWORD(low, high) \ - ((unsigned short)(((unsigned char)(low)) | \ - ((unsigned short)((unsigned char)(high))) << 8)) + (static_cast((static_cast(low)) | \ + (static_cast(static_cast(high))) << 8)) namespace Net { @@ -121,14 +121,16 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) break; } default: - logger->log("incorrect direction: %d", (int)direction); + logger->log("incorrect direction: %d", + static_cast(direction)); // OOPSIE! Impossible or unknown direction = 0; } } mPos += 3; PacketCounters::incInBytes(3); - DEBUGLOG("readCoordinates: " + toString((int)x) + "," + toString((int)y)); + DEBUGLOG("readCoordinates: " + toString(static_cast(x)) + + "," + toString(static_cast(y))); } void MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY, @@ -151,9 +153,10 @@ void MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY, srcY = static_cast(temp >> 4); } mPos += 5; - DEBUGLOG("readCoordinatePair: " + toString((int)srcX) + "," - + toString((int)srcY) + " " + toString((int)dstX) + "," - + toString((int)dstY)); + DEBUGLOG("readCoordinatePair: " + toString(static_cast(srcX)) + "," + + toString(static_cast(srcY)) + " " + + toString(static_cast(dstX)) + "," + + toString(static_cast(dstY))); PacketCounters::incInBytes(5); } @@ -161,7 +164,7 @@ void MessageIn::skip(unsigned int length) { mPos += length; PacketCounters::incInBytes(length); - DEBUGLOG("skip: " + toString((int)length)); + DEBUGLOG("skip: " + toString(static_cast(length))); } std::string MessageIn::readString(int length) diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 82123a2df..db7f4842e 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -45,7 +45,7 @@ MessageOut::MessageOut(short id _UNUSED_): void MessageOut::writeInt8(Sint8 value) { - DEBUGLOG("writeInt8: " + toString((int)value)); + DEBUGLOG("writeInt8: " + toString(static_cast(value))); expand(1); mData[mPos] = value; mPos += 1; diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 74a620ce3..f066db0bd 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -179,7 +179,8 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) speed = msg.readInt16(); stunMode = msg.readInt16(); // opt1 statusEffects = msg.readInt16(); // opt2 - statusEffects |= ((Uint32)msg.readInt16()) << 16; // option + statusEffects |= (static_cast( + msg.readInt16())) << 16; // option job = msg.readInt16(); // class dstBeing = actorSpriteManager->findBeing(id); @@ -500,12 +501,12 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) if (dstBeing) { dstBeing->takeDamage(srcBeing, param1, - (Being::AttackType)type); + static_cast(type)); } if (srcBeing) { srcBeing->handleAttack(dstBeing, param1, - (Being::AttackType)type); + static_cast(type)); if (srcBeing->getType() == Being::PLAYER) srcBeing->setAttackTime(); } @@ -560,7 +561,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) if (!effectManager) return; - id = (Uint32)msg.readInt32(); + id = static_cast(msg.readInt32()); Being* being = actorSpriteManager->findBeing(id); if (!being) break; @@ -843,7 +844,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) speed = msg.readInt16(); stunMode = msg.readInt16(); // opt1; Aethyra use this as cape statusEffects = msg.readInt16(); // opt2; Aethyra use this as misc1 - statusEffects |= ((Uint32) msg.readInt16()) + statusEffects |= (static_cast(msg.readInt16())) << 16; // status.options; Aethyra uses this as misc2 job = msg.readInt16(); @@ -1100,7 +1101,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) stunMode = msg.readInt16(); statusEffects = msg.readInt16(); - statusEffects |= ((Uint32) msg.readInt16()) << 16; + statusEffects |= (static_cast(msg.readInt16())) << 16; msg.readInt8(); // Unused? dstBeing->setStunMode(stunMode); diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 3e079ed75..ca32b1df4 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -60,7 +60,7 @@ Sint16 MessageIn::readInt16() } mPos += 2; PacketCounters::incInBytes(2); - DEBUGLOG("readInt16: " + toString((int)value)); + DEBUGLOG("readInt16: " + toString(static_cast(value))); return value; } diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index c12105581..17314937d 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -55,7 +55,7 @@ void MessageOut::expand(size_t bytes) void MessageOut::writeInt16(Sint16 value) { - DEBUGLOG("writeInt16: " + toString((int)value)); + DEBUGLOG("writeInt16: " + toString(static_cast(value))); expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN Sint16 swap = SDL_Swap16(value); @@ -81,8 +81,8 @@ void MessageOut::writeInt32(Sint32 value) PacketCounters::incOutBytes(4); } -#define LOBYTE(w) ((unsigned char)(w)) -#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8)) +#define LOBYTE(w) (static_cast(w)) +#define HIBYTE(w) (static_cast((static_cast(w)) >> 8)) void MessageOut::writeCoordinates(unsigned short x, unsigned short y, unsigned char direction) @@ -99,7 +99,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y, data[1] = 1; data[2] = 2; data[0] = HIBYTE(temp); - data[1] = (unsigned char) temp; + data[1] = static_cast(temp); temp = y; temp <<= 4; data[1] |= HIBYTE(temp); @@ -134,7 +134,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y, break; default: // OOPSIE! Impossible or unknown - direction = (unsigned char) -1; + direction = static_cast(-1); } data[2] |= direction; PacketCounters::incOutBytes(3); diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index ad8be300c..5beb05c20 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -257,7 +257,7 @@ void Network::flush() SDL_mutexP(mMutex); ret = SDLNet_TCP_Send(mSocket, mOutBuffer, mOutSize); - if (ret < (int)mOutSize) + if (ret < static_cast(mOutSize)) { setError("Error in SDLNet_TCP_Send(): " + std::string(SDLNet_GetError())); @@ -396,7 +396,7 @@ void Network::receive() { // TODO Try to get this to block all the time while still being able // to escape the loop - int numReady = SDLNet_CheckSockets(set, ((Uint32)500)); + int numReady = SDLNet_CheckSockets(set, (static_cast(500))); int ret; switch (numReady) { @@ -476,9 +476,9 @@ void Network::setError(const std::string &error) Uint16 Network::readWord(int pos) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN - return SDL_Swap16((*(Uint16*)(mInBuffer + (pos)))); + return SDL_Swap16((*static_cast(mInBuffer + (pos)))); #else - return (*(Uint16*)(mInBuffer + (pos))); + return (*reinterpret_cast(mInBuffer + (pos))); #endif } diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 8ba323268..55908093f 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -241,8 +241,9 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) // player_node->updateNavigateList(); } - logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX, - (int) scrollOffsetY); + logger->log("Adjust scrolling by %d:%d", + static_cast(scrollOffsetX), + static_cast(scrollOffsetY)); if (viewport) viewport->scrollBy(scrollOffsetX, scrollOffsetY); -- cgit v1.2.3-60-g2f50