diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-03-18 17:48:29 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-03-18 17:49:00 +0200 |
commit | f98d003e354a1792117b7cbc771d1dd91475a156 (patch) | |
tree | dc2a297f7c4026394c9954ae4bfd4abd22ef9612 /src/resources | |
parent | bb0a6cb25b2985fd1f74c9d27d5a46f6863e2dee (diff) | |
download | manaplus-f98d003e354a1792117b7cbc771d1dd91475a156.tar.gz manaplus-f98d003e354a1792117b7cbc771d1dd91475a156.tar.bz2 manaplus-f98d003e354a1792117b7cbc771d1dd91475a156.tar.xz manaplus-f98d003e354a1792117b7cbc771d1dd91475a156.zip |
Fix most old style cast except manaserv and libxml2 defines.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/emotedb.cpp | 18 | ||||
-rw-r--r-- | src/resources/image.cpp | 44 | ||||
-rw-r--r-- | src/resources/imageset.cpp | 3 | ||||
-rw-r--r-- | src/resources/imagewriter.cpp | 10 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 18 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 23 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 11 | ||||
-rw-r--r-- | src/resources/npcdb.cpp | 8 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 7 | ||||
-rw-r--r-- | src/resources/wallpaper.cpp | 2 |
10 files changed, 77 insertions, 67 deletions
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<const char*>( + 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<const char*>( + 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<const char*>( + 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<const char*>( + 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<float>(sourceAlpha) * mAlpha); + a = static_cast<Uint8>(static_cast<float>( + sourceAlpha) * mAlpha); // Here is the pixel we want to set (static_cast<Uint32 *>(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<Uint32*>( + surface->pixels))[surface_offset]; + cur_pix = (static_cast<Uint32*>( + mSDLSurface->pixels))[current_offset]; // Retreiving each channel of the pixel using pixel format - r = (Uint8)(((surface_pix & surface_fmt->Rmask) >> + r = static_cast<Uint8>(((surface_pix & surface_fmt->Rmask) >> surface_fmt->Rshift) << surface_fmt->Rloss); - g = (Uint8)(((surface_pix & surface_fmt->Gmask) >> + g = static_cast<Uint8>(((surface_pix & surface_fmt->Gmask) >> surface_fmt->Gshift) << surface_fmt->Gloss); - b = (Uint8)(((surface_pix & surface_fmt->Bmask) >> + b = static_cast<Uint8>(((surface_pix & surface_fmt->Bmask) >> surface_fmt->Bshift) << surface_fmt->Bloss); - a = (Uint8)(((surface_pix & surface_fmt->Amask) >> + a = static_cast<Uint8>(((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<Uint8>(((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<Uint32 *>(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<double>(a) / 255.0; f_ca = 1.0 - f_a; f_pa = static_cast<double>(p_a) / 255.0; - p_r = (Uint8)(((cur_pix & current_fmt->Rmask) >> + p_r = static_cast<Uint8>(((cur_pix & current_fmt->Rmask) >> current_fmt->Rshift) << current_fmt->Rloss); - p_g = (Uint8)(((cur_pix & current_fmt->Gmask) >> + p_g = static_cast<Uint8>(((cur_pix & current_fmt->Gmask) >> current_fmt->Gshift) << current_fmt->Gloss); - p_b = (Uint8)(((cur_pix & current_fmt->Bmask) >> + p_b = static_cast<Uint8>(((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<Uint8>(static_cast<double>(p_r) * f_ca + * f_pa + static_cast<double>(r) * f_a); + g = static_cast<Uint8>(static_cast<double>(p_g) * f_ca + * f_pa + static_cast<double>(g) * f_a); + b = static_cast<Uint8>(static_cast<double>(p_b) * f_ca + * f_pa + static_cast<double>(b) * f_a); a = (a > p_a ? a : p_a); - ((Uint32 *)(surface->pixels))[current_offset] = + (static_cast<Uint32 *>(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<double>(width) / getWidth(), + static_cast<double>(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<Uint32*>(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<int>(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<png_infopp>(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<png_infopp>(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<png_bytep>(static_cast<Uint8 *>( + 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<png_infopp>(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<const char*>( + 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<const char*>( + 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<const char*>( + 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<const char*>( + 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<unsigned char*>(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<unsigned char*>(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<unsigned char*>(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<unsigned char*>(buffer); inflatedSize = fileSize; } - XML::Document doc((char*) inflated, inflatedSize); + XML::Document doc(reinterpret_cast<char*>(inflated), inflatedSize); free(inflated); xmlNodePtr node = doc.rootNode(); @@ -456,9 +456,10 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) continue; int len = static_cast<int>(strlen( - (const char*)dataChild->content) + 1); + reinterpret_cast<const char*>(dataChild->content)) + 1); unsigned char *charData = new unsigned char[len + 1]; - const char *charStart = (const char*) xmlNodeGetContent(dataChild); + const char *charStart = reinterpret_cast<const char*>( + 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<int>(strlen((char*)charData)), &binLen); + static_cast<int>(strlen(reinterpret_cast<char*>( + 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<const char*>( + 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<const char*>( + 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<const char*>( + 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<const char*>( + 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<const char*>( + 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<const char*>( + 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<bool>(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<bool>(PHYSFS_mkdir(path.c_str())); } bool ResourceManager::exists(const std::string &path) @@ -611,7 +611,8 @@ std::vector<std::string> ResourceManager::loadTextFile( const std::string &fileName) { int contentsLength; - char *fileContents = (char*)loadFile(fileName, contentsLength); + char *fileContents = static_cast<char*>( + loadFile(fileName, contentsLength)); std::vector<std::string> 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<unsigned>(time(0))); return wallPaperVector[int(static_cast<double>( wallPaperVector.size()) * rand() / (RAND_MAX + 1.0))]; } |