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/resources/emotedb.cpp | 18 ++++++++-------- src/resources/image.cpp | 44 ++++++++++++++++++++++----------------- src/resources/imageset.cpp | 3 ++- src/resources/imagewriter.cpp | 10 ++++----- src/resources/itemdb.cpp | 18 +++++++--------- src/resources/mapreader.cpp | 23 +++++++++++--------- src/resources/monsterdb.cpp | 11 +++++----- src/resources/npcdb.cpp | 8 +++---- src/resources/resourcemanager.cpp | 7 ++++--- src/resources/wallpaper.cpp | 2 +- 10 files changed, 77 insertions(+), 67 deletions(-) (limited to 'src/resources') diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 6084f6092..d0cb84b90 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -83,17 +83,17 @@ void EmoteDB::load() { EmoteSprite *currentSprite = new EmoteSprite; std::string file = paths.getStringValue("sprites") - + (std::string) (const char*) - spriteNode->xmlChildrenNode->content; + + (std::string) reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentSprite->sprite = AnimatedSprite::load(file, - XML::getProperty(spriteNode, "variant", 0)); + XML::getProperty(spriteNode, "variant", 0)); currentSprite->name = XML::getProperty(spriteNode, "name", ""); currentInfo->sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { - std::string particlefx = (const char*)( - spriteNode->xmlChildrenNode->content); + std::string particlefx = reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentInfo->particles.push_back(particlefx); } } @@ -138,8 +138,8 @@ void EmoteDB::load() { EmoteSprite *currentSprite = new EmoteSprite; std::string file = paths.getStringValue("sprites") - + (std::string) (const char*) - spriteNode->xmlChildrenNode->content; + + (std::string) reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentSprite->sprite = AnimatedSprite::load(file, XML::getProperty(spriteNode, "variant", 0)); currentSprite->name = XML::getProperty(spriteNode, "name", ""); @@ -147,8 +147,8 @@ void EmoteDB::load() } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { - std::string particlefx = (const char*)( - spriteNode->xmlChildrenNode->content); + std::string particlefx = reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentInfo->particles.push_back(particlefx); } } diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 86c5956ea..0cb8779ff 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -341,7 +341,8 @@ void Image::setAlpha(float alpha) mSDLSurface->format, &r, &g, &b, &a); - a = (Uint8) (static_cast(sourceAlpha) * mAlpha); + a = static_cast(static_cast( + sourceAlpha) * mAlpha); // Here is the pixel we want to set (static_cast(mSDLSurface->pixels))[i] = @@ -392,27 +393,29 @@ Image* Image::SDLmerge(Image *image, int x, int y) surface_offset = offset_y * surface->w + offset_x; // Retrieving a pixel to merge - surface_pix = ((Uint32*) surface->pixels)[surface_offset]; - cur_pix = ((Uint32*) mSDLSurface->pixels)[current_offset]; + surface_pix = (static_cast( + surface->pixels))[surface_offset]; + cur_pix = (static_cast( + mSDLSurface->pixels))[current_offset]; // Retreiving each channel of the pixel using pixel format - r = (Uint8)(((surface_pix & surface_fmt->Rmask) >> + r = static_cast(((surface_pix & surface_fmt->Rmask) >> surface_fmt->Rshift) << surface_fmt->Rloss); - g = (Uint8)(((surface_pix & surface_fmt->Gmask) >> + g = static_cast(((surface_pix & surface_fmt->Gmask) >> surface_fmt->Gshift) << surface_fmt->Gloss); - b = (Uint8)(((surface_pix & surface_fmt->Bmask) >> + b = static_cast(((surface_pix & surface_fmt->Bmask) >> surface_fmt->Bshift) << surface_fmt->Bloss); - a = (Uint8)(((surface_pix & surface_fmt->Amask) >> + a = static_cast(((surface_pix & surface_fmt->Amask) >> surface_fmt->Ashift) << surface_fmt->Aloss); // Retreiving previous alpha value - p_a = (Uint8)(((cur_pix & current_fmt->Amask) >> + p_a = static_cast(((cur_pix & current_fmt->Amask) >> current_fmt->Ashift) << current_fmt->Aloss); // new pixel with no alpha or nothing on previous pixel if (a == SDL_ALPHA_OPAQUE || (p_a == 0 && a > 0)) { - ((Uint32 *)(surface->pixels))[current_offset] = + (static_cast(surface->pixels))[current_offset] = SDL_MapRGBA(current_fmt, r, g, b, a); } else if (a > 0) @@ -420,17 +423,20 @@ Image* Image::SDLmerge(Image *image, int x, int y) f_a = static_cast(a) / 255.0; f_ca = 1.0 - f_a; f_pa = static_cast(p_a) / 255.0; - p_r = (Uint8)(((cur_pix & current_fmt->Rmask) >> + p_r = static_cast(((cur_pix & current_fmt->Rmask) >> current_fmt->Rshift) << current_fmt->Rloss); - p_g = (Uint8)(((cur_pix & current_fmt->Gmask) >> + p_g = static_cast(((cur_pix & current_fmt->Gmask) >> current_fmt->Gshift) << current_fmt->Gloss); - p_b = (Uint8)(((cur_pix & current_fmt->Bmask) >> + p_b = static_cast(((cur_pix & current_fmt->Bmask) >> current_fmt->Bshift) << current_fmt->Bloss); - r = (Uint8)((double) p_r * f_ca * f_pa + (double)r * f_a); - g = (Uint8)((double) p_g * f_ca * f_pa + (double)g * f_a); - b = (Uint8)((double) p_b * f_ca * f_pa + (double)b * f_a); + r = static_cast(static_cast(p_r) * f_ca + * f_pa + static_cast(r) * f_a); + g = static_cast(static_cast(p_g) * f_ca + * f_pa + static_cast(g) * f_a); + b = static_cast(static_cast(p_b) * f_ca + * f_pa + static_cast(b) * f_a); a = (a > p_a ? a : p_a); - ((Uint32 *)(surface->pixels))[current_offset] = + (static_cast(surface->pixels))[current_offset] = SDL_MapRGBA(current_fmt, r, g, b, a); } } @@ -459,8 +465,8 @@ Image* Image::SDLgetScaledImage(int width, int height) if (mSDLSurface) { scaledSurface = zoomSurface(mSDLSurface, - (double) width / getWidth(), - (double) height / getHeight(), + static_cast(width) / getWidth(), + static_cast(height) / getHeight(), 1); // The load function takes care of the SDL<->OpenGL implementation @@ -546,7 +552,7 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) for (int i = 0; i < tmpImage->w * tmpImage->h; ++i) { Uint8 r, g, b, a; - SDL_GetRGBA(((Uint32*) tmpImage->pixels)[i], + SDL_GetRGBA((static_cast(tmpImage->pixels))[i], tmpImage->format, &r, &g, &b, &a); if (a != 255) diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index d1fceea69..fa0cef349 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -55,7 +55,8 @@ Image* ImageSet::get(size_type i) const { if (i >= mImages.size()) { - logger->log("Warning: No sprite %d in this image set", (int) i); + logger->log("Warning: No sprite %d in this image set", + static_cast(i)); return NULL; } else diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index bc5fb7905..d5d3de898 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -53,14 +53,14 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + png_destroy_write_struct(&png_ptr, static_cast(NULL)); logger->log1("Could not create png_info"); return false; } if (setjmp(png_jmpbuf(png_ptr))) { - png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + png_destroy_write_struct(&png_ptr, static_cast(NULL)); logger->log("problem writing to %s", filename.c_str()); return false; } @@ -95,8 +95,8 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) for (int i = 0; i < surface->h; i++) { - row_pointers[i] = (png_bytep)(Uint8 *)surface->pixels - + i * surface->pitch; + row_pointers[i] = static_cast(static_cast( + surface->pixels)) + i * surface->pitch; } png_write_image(png_ptr, row_pointers); @@ -106,7 +106,7 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) delete [] row_pointers; - png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + png_destroy_write_struct(&png_ptr, static_cast(NULL)); if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 4ba254cf3..c7515fc6b 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -510,22 +510,20 @@ int parseSpriteName(std::string &name) void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) { std::string gender = XML::getProperty(node, "gender", "unisex"); - std::string filename = (const char*) node->xmlChildrenNode->content; + std::string filename = reinterpret_cast( + node->xmlChildrenNode->content); if (gender == "male" || gender == "unisex") - { itemInfo->setSprite(filename, GENDER_MALE); - } if (gender == "female" || gender == "unisex") - { itemInfo->setSprite(filename, GENDER_FEMALE); - } } void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) { std::string event = XML::getProperty(node, "event", ""); - std::string filename = (const char*) node->xmlChildrenNode->content; + std::string filename = reinterpret_cast( + node->xmlChildrenNode->content); if (event == "hit") { @@ -549,16 +547,16 @@ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode) if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { SpriteReference *currentSprite = new SpriteReference; - currentSprite->sprite - = (const char*)spriteNode->xmlChildrenNode->content; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); display->sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { - std::string particlefx - = (const char*)spriteNode->xmlChildrenNode->content; + std::string particlefx = reinterpret_cast( + spriteNode->xmlChildrenNode->content); display->particles.push_back(particlefx); } } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 7bcb08a0f..d66e2dbe3 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -84,7 +84,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, int ret; z_stream strm; - out = (unsigned char*) malloc(bufferSize); + out = static_cast(malloc(bufferSize)); strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -124,7 +124,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, if (ret != Z_STREAM_END) { - out = (unsigned char*) realloc(out, bufferSize * 2); + out = static_cast(realloc(out, bufferSize * 2)); if (out == NULL) { @@ -200,8 +200,8 @@ Map *MapReader::readMap(const std::string &filename, if (realFilename.find(".gz", realFilename.length() - 3) != std::string::npos) { // Inflate the gzipped map data - inflatedSize = - inflateMemory((unsigned char*) buffer, fileSize, inflated); + inflatedSize = inflateMemory(static_cast(buffer), + fileSize, inflated); free(buffer); if (inflated == NULL) @@ -213,11 +213,11 @@ Map *MapReader::readMap(const std::string &filename, } else { - inflated = (unsigned char*) buffer; + inflated = static_cast(buffer); inflatedSize = fileSize; } - XML::Document doc((char*) inflated, inflatedSize); + XML::Document doc(reinterpret_cast(inflated), inflatedSize); free(inflated); xmlNodePtr node = doc.rootNode(); @@ -456,9 +456,10 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) continue; int len = static_cast(strlen( - (const char*)dataChild->content) + 1); + reinterpret_cast(dataChild->content)) + 1); unsigned char *charData = new unsigned char[len + 1]; - const char *charStart = (const char*) xmlNodeGetContent(dataChild); + const char *charStart = reinterpret_cast( + xmlNodeGetContent(dataChild)); if (!charStart) { delete charData; @@ -481,7 +482,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) int binLen; unsigned char *binData = php3_base64_decode(charData, - static_cast(strlen((char*)charData)), &binLen); + static_cast(strlen(reinterpret_cast( + charData))), &binLen); delete[] charData; @@ -537,7 +539,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) if (!dataChild) continue; - const char *data = (const char*) xmlNodeGetContent(dataChild); + const char *data = reinterpret_cast( + xmlNodeGetContent(dataChild)); if (!data) return; diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 854450bfd..8990d679a 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -104,8 +104,8 @@ void MonsterDB::load() if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { SpriteReference *currentSprite = new SpriteReference; - currentSprite->sprite - = (const char*)spriteNode->xmlChildrenNode->content; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentSprite->variant = XML::getProperty( spriteNode, "variant", 0); @@ -115,7 +115,8 @@ void MonsterDB::load() { std::string event = XML::getProperty(spriteNode, "event", ""); const char *filename; - filename = (const char*) spriteNode->xmlChildrenNode->content; + filename = reinterpret_cast( + spriteNode->xmlChildrenNode->content); if (event == "hit") { @@ -156,8 +157,8 @@ void MonsterDB::load() } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { - display.particles.push_back( - (const char*) spriteNode->xmlChildrenNode->content); + display.particles.push_back(reinterpret_cast( + spriteNode->xmlChildrenNode->content)); } } currentInfo->setDisplay(display); diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 5a1ad9985..5c8c0e8c8 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -85,16 +85,16 @@ void NPCDB::load() if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { SpriteReference *currentSprite = new SpriteReference; - currentSprite->sprite = - (const char*)spriteNode->xmlChildrenNode->content; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { - std::string particlefx = - (const char*)spriteNode->xmlChildrenNode->content; + std::string particlefx = reinterpret_cast( + spriteNode->xmlChildrenNode->content); display.particles.push_back(particlefx); } } diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 3ba99d248..0c1dafe4b 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -199,7 +199,7 @@ void ResourceManager::cleanOrphans() bool ResourceManager::setWriteDir(const std::string &path) { - return (bool) PHYSFS_setWriteDir(path.c_str()); + return static_cast(PHYSFS_setWriteDir(path.c_str())); } bool ResourceManager::addToSearchPath(const std::string &path, bool append) @@ -278,7 +278,7 @@ void ResourceManager::searchAndRemoveArchives(const std::string &path, bool ResourceManager::mkdir(const std::string &path) { - return (bool) PHYSFS_mkdir(path.c_str()); + return static_cast(PHYSFS_mkdir(path.c_str())); } bool ResourceManager::exists(const std::string &path) @@ -611,7 +611,8 @@ std::vector ResourceManager::loadTextFile( const std::string &fileName) { int contentsLength; - char *fileContents = (char*)loadFile(fileName, contentsLength); + char *fileContents = static_cast( + loadFile(fileName, contentsLength)); std::vector lines; if (!fileContents) diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index e7f3b7dc9..936e72ca0 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -158,7 +158,7 @@ std::string Wallpaper::getWallpaper(int width, int height) { // Return randomly a wallpaper between vector[0] and // vector[vector.size() - 1] - srand((unsigned) time(0)); + srand(static_cast(time(0))); return wallPaperVector[int(static_cast( wallPaperVector.size()) * rand() / (RAND_MAX + 1.0))]; } -- cgit v1.2.3-60-g2f50