diff options
Diffstat (limited to 'src/resources')
36 files changed, 155 insertions, 155 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index bfc130c8..c35498a4 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -36,7 +36,7 @@ Action::~Action() Animation *Action::getAnimation(int direction) const { - Animations::const_iterator i = mAnimations.find(direction); + auto i = mAnimations.find(direction); // When the given direction is not available, return the first one. // (either DEFAULT, or more usually DOWN). diff --git a/src/resources/action.h b/src/resources/action.h index 1d85bf62..bf229abd 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -43,8 +43,8 @@ class Action Animation *getAnimation(int direction) const; protected: - typedef std::map<int, Animation*> Animations; - typedef Animations::iterator AnimationIterator; + using Animations = std::map<int, Animation *>; + using AnimationIterator = Animations::iterator; Animations mAnimations; }; diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index e4837e44..8ab7cc44 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -37,10 +37,10 @@ void Animation::addFrame(Image *image, int delay, int offsetX, int offsetY) void Animation::addTerminator() { - addFrame(NULL, 0, 0, 0); + addFrame(nullptr, 0, 0, 0); } bool Animation::isTerminator(const Frame &candidate) { - return (candidate.image == NULL); + return (candidate.image == nullptr); } diff --git a/src/resources/attributes.cpp b/src/resources/attributes.cpp index 58bff6f1..82871b2f 100644 --- a/src/resources/attributes.cpp +++ b/src/resources/attributes.cpp @@ -40,7 +40,7 @@ namespace Attributes { - typedef struct + using Attribute = struct { unsigned int id; std::string name; @@ -51,14 +51,14 @@ namespace Attributes { std::string scope; /** The playerInfo core Id the attribute is linked with or -1 if not */ int playerInfoId; - } Attribute; + }; /** Map for attributes. */ - typedef std::map<unsigned int, Attribute> AttributeMap; + using AttributeMap = std::map<unsigned int, Attribute>; static AttributeMap attributes; /** tags = effects on attributes. */ - typedef std::map< std::string, std::string > TagMap; + using TagMap = std::map<std::string, std::string>; static TagMap tags; /** List of modifiable attribute names used at character's creation. */ @@ -355,7 +355,7 @@ namespace Attributes { fillLabels(); // Sanity checks on starting points - float modifiableAttributeCount = (float) attributeLabels.size(); + auto modifiableAttributeCount = (float) attributeLabels.size(); float averageValue = ((float) creationPoints) / modifiableAttributeCount; if (averageValue > attributeMaximum || averageValue < attributeMinimum || creationPoints < 1) diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 5a277770..539254ac 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -86,20 +86,20 @@ const std::string &BeingInfo::getSound(SoundEvent event) const { static const std::string empty; - SoundEvents::const_iterator i = mSounds.find(event); + auto i = mSounds.find(event); return (i == mSounds.end()) ? empty : i->second->at(rand() % i->second->size()); } const Attack *BeingInfo::getAttack(int id) const { - static Attack *empty = new Attack(SpriteAction::ATTACK, + static auto *empty = new Attack(SpriteAction::ATTACK, -1, // Default strike effect on monster paths.getIntValue("hitEffectId"), paths.getIntValue("criticalHitEffectId"), std::string()); - Attacks::const_iterator it = mAttacks.find(id); + auto it = mAttacks.find(id); return (it == mAttacks.end()) ? empty : it->second; } @@ -107,7 +107,7 @@ void BeingInfo::addAttack(int id, std::string action, int effectId, int hitEffectId, int criticalHitEffectId, const std::string &missileParticleFilename) { - Attacks::iterator it = mAttacks.find(id); + auto it = mAttacks.find(id); if (it != mAttacks.end()) delete it->second; diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index b2cae5e2..3fa5b8b6 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -47,7 +47,7 @@ struct Attack { } }; -typedef std::map<int, Attack*> Attacks; +using Attacks = std::map<int, Attack *>; enum SoundEvent { @@ -57,7 +57,7 @@ enum SoundEvent SOUND_EVENT_DIE }; -typedef std::map<SoundEvent, std::vector<std::string>* > SoundEvents; +using SoundEvents = std::map<SoundEvent, std::vector<std::string> *>; /** * Holds information about a certain type of monster. This includes the name @@ -128,7 +128,7 @@ class BeingInfo Map::BlockType mBlockType; }; -typedef std::map<int, BeingInfo*> BeingInfos; -typedef BeingInfos::iterator BeingInfoIterator; +using BeingInfos = std::map<int, BeingInfo *>; +using BeingInfoIterator = BeingInfos::iterator; #endif // BEINGINFO_H diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 4e4016e4..ba2ad4b5 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -179,7 +179,7 @@ void DyePalette::getColor(double intensity, int color[3]) const Dye::Dye(const std::string &description) { for (int i = 0; i < 7; ++i) - mDyePalettes[i] = 0; + mDyePalettes[i] = nullptr; if (description.empty()) return; diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 04dd4bbb..fde7030a 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -60,7 +60,7 @@ void EmoteDB::readEmoteNode(xmlNodePtr node, const std::string &filename) return; } - Emote *currentEmote = new Emote; + auto *currentEmote = new Emote; currentEmote->name = XML::getProperty(node, "name", "unknown"); currentEmote->effect = XML::getProperty(node, "effectid", -1); diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h index 33195d82..cdcb5cf6 100644 --- a/src/resources/emotedb.h +++ b/src/resources/emotedb.h @@ -36,7 +36,7 @@ struct Emote int effect; }; -typedef std::map<int, Emote*> Emotes; +using Emotes = std::map<int, Emote *>; /** * Emote information database. @@ -55,7 +55,7 @@ namespace EmoteDB int getLast(); - typedef Emotes::iterator EmotesIterator; + using EmotesIterator = Emotes::iterator; } #endif // EMOTE_DB_H diff --git a/src/resources/hairdb.cpp b/src/resources/hairdb.cpp index 2e9747a2..4ca4fa5c 100644 --- a/src/resources/hairdb.cpp +++ b/src/resources/hairdb.cpp @@ -96,7 +96,7 @@ const std::string &HairDB::getHairColor(int id) std::vector<int> HairDB::getHairStyleIds(int maxId) const { std::vector<int> hairStylesIds; - for (HairStylesConstIterator it = mHairStyles.begin(), + for (auto it = mHairStyles.begin(), it_end = mHairStyles.end(); it != it_end; ++it) { // Don't give ids higher than the requested maximum. @@ -110,7 +110,7 @@ std::vector<int> HairDB::getHairStyleIds(int maxId) const std::vector<int> HairDB::getHairColorIds(int maxId) const { std::vector<int> hairColorsIds; - for (ColorConstIterator it = mHairColors.begin(), + for (auto it = mHairColors.begin(), it_end = mHairColors.end(); it != it_end; ++it) { // Don't give ids higher than the requested maximum. diff --git a/src/resources/hairdb.h b/src/resources/hairdb.h index 502d7c21..48354243 100644 --- a/src/resources/hairdb.h +++ b/src/resources/hairdb.h @@ -88,14 +88,14 @@ class HairDB void loadHairStylesNode(xmlNodePtr stylesNode); // Hair colors Db - typedef std::map<int, std::string> Colors; - typedef Colors::iterator ColorIterator; - typedef Colors::const_iterator ColorConstIterator; + using Colors = std::map<int, std::string>; + using ColorIterator = Colors::iterator; + using ColorConstIterator = Colors::const_iterator; Colors mHairColors; - typedef std::set<int> HairStyles; - typedef HairStyles::iterator HairStylesIterator; - typedef HairStyles::const_iterator HairStylesConstIterator; + using HairStyles = std::set<int>; + using HairStylesIterator = HairStyles::iterator; + using HairStylesConstIterator = HairStyles::const_iterator; HairStyles mHairStyles; bool mLoaded; diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 6f2609b0..c05b03aa 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -69,7 +69,7 @@ Image::Image(SDL_Texture *texture, int width, int height): #ifdef USE_OPENGL Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight): mAlpha(1.0f), - mTexture(0), + mTexture(nullptr), mGLImage(glimage), mTexWidth(texWidth), mTexHeight(texHeight) @@ -102,7 +102,7 @@ Resource *Image::load(SDL_RWops *rw) if (!tmpImage) { logger->log("Error, image load failed: %s", IMG_GetError()); - return NULL; + return nullptr; } Image *image = load(tmpImage); @@ -118,11 +118,11 @@ Resource *Image::load(SDL_RWops *rw, Dye const &dye) if (!tmpImage) { logger->log("Error, image load failed: %s", IMG_GetError()); - return NULL; + return nullptr; } SDL_PixelFormat rgba; - rgba.palette = NULL; + rgba.palette = nullptr; rgba.BitsPerPixel = 32; rgba.BytesPerPixel = 4; rgba.Rmask = 0xFF000000; rgba.Rloss = 0; rgba.Rshift = 24; @@ -133,7 +133,7 @@ Resource *Image::load(SDL_RWops *rw, Dye const &dye) SDL_Surface *surf = SDL_ConvertSurface(tmpImage, &rgba, 0); SDL_FreeSurface(tmpImage); - Uint32 *pixels = static_cast< Uint32 * >(surf->pixels); + auto *pixels = static_cast< Uint32 * >(surf->pixels); for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) { int alpha = *pixels & 255; @@ -167,7 +167,7 @@ void Image::unload() if (mTexture) { SDL_DestroyTexture(mTexture); - mTexture = NULL; + mTexture = nullptr; } #ifdef USE_OPENGL @@ -210,7 +210,7 @@ void Image::setAlpha(float alpha) Image *Image::_SDLload(SDL_Surface *image) { if (!image || !mRenderer) - return NULL; + return nullptr; SDL_Texture *texture = SDL_CreateTextureFromSurface(mRenderer, image); return new Image(texture, image->w, image->h); @@ -269,12 +269,12 @@ Image *Image::_GLload(SDL_Surface *image) if (!image) { logger->log("Error, image convert failed: out of memory"); - return NULL; + return nullptr; } // Make sure the alpha channel is not used, but copied to destination SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE); - SDL_BlitSurface(oldImage, NULL, image, NULL); + SDL_BlitSurface(oldImage, nullptr, image, nullptr); } GLuint texture; @@ -325,7 +325,7 @@ Image *Image::_GLload(SDL_Surface *image) break; } logger->log("Error: Image GL import failed: %s", errmsg.c_str()); - return NULL; + return nullptr; } return new Image(texture, width, height, realWidth, realHeight); diff --git a/src/resources/image.h b/src/resources/image.h index efe2262e..66c3ff78 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -51,7 +51,7 @@ class Image : public Resource #endif public: - virtual ~Image(); + ~Image() override; /** * Loads an image from an SDL_RWops structure. @@ -224,7 +224,7 @@ class SubImage : public Image int width, int height, int texWidth, int textHeight); #endif - ~SubImage(); + ~SubImage() override; private: Image *mParent; diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 9fe75395..74b4034f 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -53,7 +53,7 @@ Image* ImageSet::get(size_type i) const if (i >= mImages.size()) { logger->log("Warning: No sprite %d in this image set", (int) i); - return NULL; + return nullptr; } else { diff --git a/src/resources/imageset.h b/src/resources/imageset.h index 5d9bdc2e..c73e7e37 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -39,7 +39,7 @@ class ImageSet : public Resource */ ImageSet(Image *img, int w, int h, int margin = 0, int spacing = 0); - ~ImageSet(); + ~ImageSet() override; /** * Returns the width of the images in the image set. @@ -51,7 +51,7 @@ class ImageSet : public Resource */ int getHeight() const { return mHeight; } - typedef std::vector<Image*>::size_type size_type; + using size_type = std::vector<Image *>::size_type; Image* get(size_type i) const; size_type size() const { return mImages.size(); } diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index 7257e1b9..ddf1fbee 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -39,7 +39,7 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (!png_ptr) { logger->log("Had trouble creating png_structp"); @@ -49,14 +49,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, (png_infopp)nullptr); logger->log("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, (png_infopp)nullptr); logger->log("problem writing to %s", filename.c_str()); return false; } @@ -100,7 +100,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, (png_infopp)nullptr); if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 8c1a8d15..225bdb71 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -180,7 +180,7 @@ void ItemDB::unload() logger->log("Unloading item database..."); delete mUnknown; - mUnknown = NULL; + mUnknown = nullptr; delete_all(mItemInfos); mItemInfos.clear(); @@ -330,7 +330,7 @@ void TaItemDB::init() void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename) { - TaItemInfo *itemInfo = new TaItemInfo; + auto *itemInfo = new TaItemInfo; loadCommonRef(itemInfo, node, filename); @@ -348,7 +348,7 @@ void TaItemDB::readItemNode(xmlNodePtr node, const std::string &filename) continue; effect.push_back(strprintf(gettext(fields[i][1]), value)); } - for (std::list<ItemStat>::iterator it = extraStats.begin(); + for (auto it = extraStats.begin(); it != extraStats.end(); it++) { int value = XML::getProperty(node, it->mTag.c_str(), 0); @@ -421,7 +421,7 @@ void ManaServItemDB::init() void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename) { - ManaServItemInfo *itemInfo = new ManaServItemInfo; + auto *itemInfo = new ManaServItemInfo; loadCommonRef(itemInfo, node, filename); diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 2f19339d..016e6194 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -74,7 +74,7 @@ class ItemDB { public: ItemDB() : - mUnknown(0), + mUnknown(nullptr), mLoaded(false) {} @@ -147,8 +147,8 @@ class ItemDB void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); // Items database - typedef std::map<int, ItemInfo*> ItemInfos; - typedef std::map<std::string, ItemInfo*> NamedItemInfos; + using ItemInfos = std::map<int, ItemInfo *>; + using NamedItemInfos = std::map<std::string, ItemInfo *>; ItemInfos mItemInfos; NamedItemInfos mNamedItemInfos; @@ -167,14 +167,14 @@ class TaItemDB: public ItemDB TaItemDB() : ItemDB() { } - ~TaItemDB() + ~TaItemDB() override { unload(); } - virtual void init(); + void init() override; - virtual void readItemNode(xmlNodePtr node, const std::string &filename); + void readItemNode(xmlNodePtr node, const std::string &filename) override; - virtual void checkStatus(); + void checkStatus() override; private: /** * Check items id specific hard limits and log errors found. @@ -183,7 +183,7 @@ class TaItemDB: public ItemDB void checkHairWeaponsRacesSpecialIds() {} - void checkItemInfo(ItemInfo* itemInfo); + void checkItemInfo(ItemInfo* itemInfo) override; }; } // namespace TmwAthena @@ -201,17 +201,17 @@ class ManaServItemDB: public ItemDB ManaServItemDB() : ItemDB() { } - ~ManaServItemDB() + ~ManaServItemDB() override { unload(); } - virtual void init(); + void init() override; - virtual void readItemNode(xmlNodePtr node, const std::string &filename); + void readItemNode(xmlNodePtr node, const std::string &filename) override; - virtual void checkStatus(); + void checkStatus() override; private: - void checkItemInfo(ItemInfo* itemInfo); + void checkItemInfo(ItemInfo* itemInfo) override; }; } // namespace ManaServ diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 3583bb27..9e7fd6b7 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -34,7 +34,7 @@ const std::string &ItemInfo::getSprite(Gender gender) const else { static const std::string empty; - std::map<int, std::string>::const_iterator i = + auto i = mAnimationFiles.find(gender); return (i != mAnimationFiles.end()) ? i->second : empty; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index b2642ae8..af41da12 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -68,7 +68,7 @@ static std::string resolveRelativePath(std::string base, std::string relative) Map *MapReader::readMap(const std::string &filename) { logger->log("Attempting to read map %s", filename.c_str()); - Map *map = NULL; + Map *map = nullptr; XML::Document doc(filename); @@ -111,7 +111,7 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) logger->log("MapReader: Warning: " "Unitialized tile width or height value for map: %s", path.c_str()); - return 0; + return nullptr; } Map *map = new Map(w, h, tilew, tileh); @@ -237,7 +237,7 @@ static void setTile(Map *map, MapLayer *layer, int x, int y, unsigned gid) if (layer) { // Set regular tile on a layer - Image * const img = set ? set->get(gid - set->getFirstGid()) : 0; + Image * const img = set ? set->get(gid - set->getFirstGid()) : nullptr; layer->setTile(x, y, img); } else @@ -261,7 +261,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) const bool isFringeLayer = (name.substr(0,6) == "fringe"); const bool isCollisionLayer = (name.substr(0,9) == "collision"); - MapLayer *layer = 0; + MapLayer *layer = nullptr; if (!isCollisionLayer) { @@ -300,7 +300,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) continue; int len = strlen((const char*)dataChild->content) + 1; - unsigned char *charData = new unsigned char[len + 1]; + auto *charData = new unsigned char[len + 1]; const char *charStart = (const char*) xmlNodeGetContent(dataChild); unsigned char *charIndex = charData; @@ -440,8 +440,8 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, unsigned firstGid = XML::getProperty(node, "firstgid", 0); int margin = XML::getProperty(node, "margin", 0); int spacing = XML::getProperty(node, "spacing", 0); - XML::Document* doc = NULL; - Tileset *set = NULL; + XML::Document* doc = nullptr; + Tileset *set = nullptr; std::string pathDir(path); if (xmlHasProp(node, BAD_CAST "source")) @@ -507,7 +507,7 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, // create animation if (!set) continue; - Animation *ani = new Animation; + auto *ani = new Animation; for (int i = 0; ;i++) { std::map<std::string, int>::iterator iFrame, iDelay; diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 8415b6ae..5fd74c24 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -63,7 +63,7 @@ void MonsterDB::init() */ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename) { - BeingInfo *currentInfo = new BeingInfo; + auto *currentInfo = new BeingInfo; currentInfo->setWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER @@ -171,7 +171,7 @@ void MonsterDB::unload() BeingInfo *MonsterDB::get(int id) { - BeingInfoIterator i = mMonsterInfos.find(id); + auto i = mMonsterInfos.find(id); if (i == mMonsterInfos.end()) { diff --git a/src/resources/music.cpp b/src/resources/music.cpp index 73ef2f85..c6760865 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -49,7 +49,7 @@ Resource *Music::load(SDL_RWops *rw) } #else SDL_FreeRW(rw); - return 0; + return nullptr; #endif } diff --git a/src/resources/music.h b/src/resources/music.h index d370f0a5..0c445b2b 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -32,7 +32,7 @@ class Music : public Resource { public: - virtual ~Music(); + ~Music() override; /** * Loads a music from a buffer in memory. diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 7d0f72b0..fa12eced 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -52,7 +52,7 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename) return; } - BeingInfo *currentInfo = new BeingInfo; + auto *currentInfo = new BeingInfo; currentInfo->setTargetCursorSize(XML::getProperty(node, "targetCursor", "medium")); @@ -94,7 +94,7 @@ void NPCDB::unload() BeingInfo *NPCDB::get(int id) { - BeingInfoIterator i = mNPCInfos.find(id); + auto i = mNPCInfos.find(id); if (i == mNPCInfos.end()) { diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a9e7e565..46e1ab30 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -43,7 +43,7 @@ #include <sys/time.h> -ResourceManager *ResourceManager::instance = NULL; +ResourceManager *ResourceManager::instance = nullptr; ResourceManager::ResourceManager() : mOldestOrphan(0) @@ -56,13 +56,13 @@ ResourceManager::~ResourceManager() mResources.insert(mOrphanedResources.begin(), mOrphanedResources.end()); // Release any remaining spritedefs first because they depend on image sets - ResourceIterator iter = mResources.begin(); + auto iter = mResources.begin(); while (iter != mResources.end()) { - if (dynamic_cast<SpriteDef*>(iter->second) != 0) + if (dynamic_cast<SpriteDef*>(iter->second) != nullptr) { cleanUp(iter->second); - ResourceIterator toErase = iter; + auto toErase = iter; ++iter; mResources.erase(toErase); } @@ -76,10 +76,10 @@ ResourceManager::~ResourceManager() iter = mResources.begin(); while (iter != mResources.end()) { - if (dynamic_cast<ImageSet*>(iter->second) != 0) + if (dynamic_cast<ImageSet*>(iter->second) != nullptr) { cleanUp(iter->second); - ResourceIterator toErase = iter; + auto toErase = iter; ++iter; mResources.erase(toErase); } @@ -115,7 +115,7 @@ void ResourceManager::cleanUp(Resource *res) void ResourceManager::cleanOrphans() { timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); // Delete orphaned resources after 30 seconds. time_t oldest = tv.tv_sec; time_t threshold = oldest - 30; @@ -123,7 +123,7 @@ void ResourceManager::cleanOrphans() if (mOrphanedResources.empty() || mOldestOrphan >= threshold) return; - ResourceIterator iter = mOrphanedResources.begin(); + auto iter = mOrphanedResources.begin(); while (iter != mOrphanedResources.end()) { Resource *res = iter->second; @@ -137,7 +137,7 @@ void ResourceManager::cleanOrphans() else { logger->log("ResourceManager::release(%s)", res->mIdPath.c_str()); - ResourceIterator toErase = iter; + auto toErase = iter; ++iter; mOrphanedResources.erase(toErase); delete res; // delete only after removal from list, to avoid issues in recursion @@ -239,20 +239,20 @@ bool ResourceManager::addResource(const std::string &idPath, Resource *ResourceManager::get(const std::string &idPath) { - ResourceIterator resIter = mResources.find(idPath); + auto resIter = mResources.find(idPath); if (resIter != mResources.end()) { resIter->second->incRef(); return resIter->second; } - return 0; + return nullptr; } Resource *ResourceManager::get(const std::string &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. - ResourceIterator resIter = mResources.find(idPath); + auto resIter = mResources.find(idPath); if (resIter != mResources.end()) { resIter->second->incRef(); @@ -291,10 +291,10 @@ struct ResourceLoader static Resource *load(void *v) { - ResourceLoader *l = static_cast< ResourceLoader * >(v); + auto *l = static_cast< ResourceLoader * >(v); SDL_RWops *rw = PHYSFSRWOPS_openRead(l->path.c_str()); if (!rw) - return NULL; + return nullptr; Resource *res = l->fun(rw); return res; } @@ -322,10 +322,10 @@ struct DyedImageLoader std::string path; static Resource *load(void *v) { - DyedImageLoader *l = static_cast< DyedImageLoader * >(v); + auto *l = static_cast< DyedImageLoader * >(v); std::string path = l->path; std::string::size_type p = path.find('|'); - Dye *d = NULL; + Dye *d = nullptr; if (p != std::string::npos) { d = new Dye(path.substr(p + 1)); @@ -335,7 +335,7 @@ struct DyedImageLoader if (!rw) { delete d; - return NULL; + return nullptr; } Resource *res = d ? Image::load(rw, *d) : Image::load(rw); @@ -357,10 +357,10 @@ struct ImageSetLoader int w, h; static Resource *load(void *v) { - ImageSetLoader *l = static_cast< ImageSetLoader * >(v); + auto *l = static_cast< ImageSetLoader * >(v); Image *img = l->manager->getImage(l->path); - if (!img) return NULL; - ImageSet *res = new ImageSet(img, l->w, l->h); + if (!img) return nullptr; + auto *res = new ImageSet(img, l->w, l->h); img->decRef(); return res; } @@ -381,7 +381,7 @@ struct SpriteDefLoader int variant; static Resource *load(void *v) { - SpriteDefLoader *l = static_cast< SpriteDefLoader * >(v); + auto *l = static_cast< SpriteDefLoader * >(v); return SpriteDef::load(l->path, l->variant); } }; @@ -396,13 +396,13 @@ SpriteDef *ResourceManager::getSprite(const std::string &path, int variant) void ResourceManager::release(Resource *res) { - ResourceIterator resIter = mResources.find(res->mIdPath); + auto resIter = mResources.find(res->mIdPath); // The resource has to exist assert(resIter != mResources.end() && resIter->second == res); timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); time_t timestamp = tv.tv_sec; res->mTimeStamp = timestamp; @@ -429,7 +429,7 @@ ResourceManager *ResourceManager::getInstance() void ResourceManager::deleteInstance() { delete instance; - instance = NULL; + instance = nullptr; } void *ResourceManager::loadFile(const std::string &filename, int &filesize, @@ -439,11 +439,11 @@ void *ResourceManager::loadFile(const std::string &filename, int &filesize, PHYSFS_file *file = PHYSFS_openRead(filename.c_str()); // If the handler is an invalid pointer indicate failure - if (file == NULL) + if (file == nullptr) { logger->log("Warning: Failed to load %s: %s", filename.c_str(), PHYSFS_getLastError()); - return NULL; + return nullptr; } // Log the real dir of the file @@ -471,11 +471,11 @@ void *ResourceManager::loadFile(const std::string &filename, int &filesize, inflateMemory((unsigned char*) buffer, filesize, inflated); free(buffer); - if (inflated == NULL) + if (inflated == nullptr) { logger->log("Could not decompress file: %s", filename.c_str()); - return NULL; + return nullptr; } filesize = inflatedSize; @@ -539,7 +539,7 @@ std::vector<std::string> ResourceManager::loadTextFile( SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) { - SDL_Surface *surface = 0; + SDL_Surface *surface = nullptr; if (SDL_RWops *rw = PHYSFSRWOPS_openRead(filename.c_str())) surface = IMG_Load_RW(rw, 1); return surface; @@ -552,7 +552,7 @@ void ResourceManager::scheduleDelete(SDL_Surface* surface) void ResourceManager::clearScheduled() { - for (std::set<SDL_Surface*>::iterator i = mDeletedSurfaces.begin(), + for (auto i = mDeletedSurfaces.begin(), i_end = mDeletedSurfaces.end(); i != i_end; ++i) { SDL_FreeSurface(*i); diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 5abc81e2..a087082d 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -47,8 +47,8 @@ class ResourceManager public: - typedef Resource *(*loader)(SDL_RWops *); - typedef Resource *(*generator)(void *); + using loader = Resource *(*)(SDL_RWops *); + using generator = Resource *(*)(void *); ResourceManager(); @@ -249,8 +249,8 @@ class ResourceManager void cleanOrphans(); static ResourceManager *instance; - typedef std::map<std::string, Resource*> Resources; - typedef Resources::iterator ResourceIterator; + using Resources = std::map<std::string, Resource *>; + using ResourceIterator = Resources::iterator; std::set<SDL_Surface*> mDeletedSurfaces; Resources mResources; Resources mOrphanedResources; diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index d1b0227b..782d79d1 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -40,7 +40,7 @@ Resource *SoundEffect::load(SDL_RWops *rw) else { logger->log("Error, failed to load sound effect: %s", Mix_GetError()); - return NULL; + return nullptr; } } diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 38d58681..eada80b5 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -32,7 +32,7 @@ class SoundEffect : public Resource { public: - virtual ~SoundEffect(); + ~SoundEffect() override; /** * Loads a sample from a buffer in memory. diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index 6601b586..b72c059f 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -55,7 +55,7 @@ void SpecialDB::readSpecialSetNode(xmlNodePtr node, const std::string &filename) { if (xmlStrEqual(special->name, BAD_CAST "special")) { - SpecialInfo *info = new SpecialInfo(); + auto *info = new SpecialInfo(); int id = XML::getProperty(special, "id", 0); info->id = id; info->set = setName; @@ -98,16 +98,16 @@ void SpecialDB::unload() SpecialInfo *SpecialDB::get(int id) { - SpecialInfos::iterator i = mSpecialInfos.find(id); + auto i = mSpecialInfos.find(id); if (i == mSpecialInfos.end()) { - return NULL; + return nullptr; } else { return i->second; } - return NULL; + return nullptr; } diff --git a/src/resources/specialdb.h b/src/resources/specialdb.h index f6987b71..71aae0ba 100644 --- a/src/resources/specialdb.h +++ b/src/resources/specialdb.h @@ -65,6 +65,6 @@ namespace SpecialDB SpecialInfo::TargetMode targetModeFromString(const std::string& str); } -typedef std::map<int, SpecialInfo *> SpecialInfos; +using SpecialInfos = std::map<int, SpecialInfo *>; #endif diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 7ccf1ff6..f33ade55 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -41,12 +41,12 @@ std::set<std::string> processedFiles; Action *SpriteDef::getAction(const std::string &action) const { - Actions::const_iterator i = mActions.find(action); + auto i = mActions.find(action); if (i == mActions.end()) { logger->log("Warning: no action \"%s\" defined!", action.c_str()); - return NULL; + return nullptr; } return i->second; @@ -77,11 +77,11 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) } else { - return NULL; + return nullptr; } } - SpriteDef *def = new SpriteDef; + auto *def = new SpriteDef; def->loadSprite(rootNode, variant, palettes); def->substituteActions(); return def; @@ -91,7 +91,7 @@ void SpriteDef::substituteAction(std::string complete, std::string with) { if (mActions.find(complete) == mActions.end()) { - Actions::iterator i = mActions.find(with); + auto i = mActions.find(with); if (i != mActions.end()) { mActions[complete] = i->second; @@ -175,7 +175,7 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); - ImageSetIterator si = mImageSets.find(imageSetName); + auto si = mImageSets.find(imageSetName); if (si == mImageSets.end()) { logger->log("Warning: imageset \"%s\" not defined in %s", @@ -190,7 +190,7 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) actionName.c_str(), getIdPath().c_str()); return; } - Action *action = new Action; + auto *action = new Action; mActions[actionName] = action; // When first action set it as default direction @@ -224,7 +224,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, return; } - Animation *animation = new Animation; + auto *animation = new Animation; action->setAnimation(directionType, animation); // Get animation frames @@ -327,13 +327,13 @@ SpriteDef::~SpriteDef() actions.insert(i->second); } - for (std::set< Action * >::const_iterator i = actions.begin(), + for (auto i = actions.begin(), i_end = actions.end(); i != i_end; ++i) { delete *i; } - for (ImageSetIterator i = mImageSets.begin(); + for (auto i = mImageSets.begin(); i != mImageSets.end(); ++i) { i->second->decRef(); diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 5ece1308..b044e7b6 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -53,7 +53,7 @@ struct SpriteDisplay std::list<std::string> particles; }; -typedef std::list<SpriteReference>::const_iterator SpriteRefs; +using SpriteRefs = std::list<SpriteReference>::const_iterator; /* * Remember those are the main action. @@ -115,7 +115,7 @@ class SpriteDef : public Resource private: SpriteDef() {} - ~SpriteDef(); + ~SpriteDef() override; /** * Loads a sprite element. @@ -156,10 +156,10 @@ class SpriteDef : public Resource */ void substituteAction(std::string complete, std::string with); - typedef std::map<std::string, ImageSet*> ImageSets; - typedef ImageSets::iterator ImageSetIterator; + using ImageSets = std::map<std::string, ImageSet *>; + using ImageSetIterator = ImageSets::iterator; - typedef std::map<std::string, Action*> Actions; + using Actions = std::map<std::string, Action *>; ImageSets mImageSets; Actions mActions; diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index 1490dbf5..c44b7401 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -42,7 +42,7 @@ static std::string defaultThemePath; std::string Theme::mThemePath; -Theme *Theme::mInstance = 0; +Theme *Theme::mInstance = nullptr; // Set the theme path... static void initDefaultThemePath() @@ -144,7 +144,7 @@ Theme *Theme::instance() void Theme::deleteInstance() { delete mInstance; - mInstance = 0; + mInstance = nullptr; } gcn::Color Theme::getProgressColor(int type, float progress) @@ -160,7 +160,7 @@ gcn::Color Theme::getProgressColor(int type, float progress) Skin *Theme::load(const std::string &filename, const std::string &defaultPath) { // Check if this skin was already loaded - SkinIterator skinIterator = mSkins.find(filename); + auto skinIterator = mSkins.find(filename); if (mSkins.end() != skinIterator) { skinIterator->second->instances++; @@ -204,7 +204,7 @@ void Theme::setMinimumOpacity(float minimumOpacity) void Theme::updateAlpha() { - for (SkinIterator iter = mSkins.begin(); iter != mSkins.end(); ++iter) + for (auto iter = mSkins.begin(); iter != mSkins.end(); ++iter) iter->second->updateAlpha(mMinimumOpacity); } @@ -221,7 +221,7 @@ void Theme::event(Event::Channel channel, const Event &event) Skin *Theme::readSkin(const std::string &filename) { if (filename.empty()) - return 0; + return nullptr; logger->log("Loading skin '%s'.", filename.c_str()); @@ -229,14 +229,14 @@ Skin *Theme::readSkin(const std::string &filename) xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - return 0; + return nullptr; const std::string skinSetImage = XML::getProperty(rootNode, "image", ""); if (skinSetImage.empty()) { logger->log("Theme::readSkin(): Skinset does not define an image!"); - return 0; + return nullptr; } logger->log("Theme::load(): <skinset> defines '%s' as a skin image.", diff --git a/src/resources/theme.h b/src/resources/theme.h index b2dd10de..9e7c4c3e 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -218,17 +218,17 @@ class Theme : public Palette, public EventListener */ void setMinimumOpacity(float minimumOpacity); - void event(Event::Channel channel, const Event &event); + void event(Event::Channel channel, const Event &event) override; private: Theme(); - ~Theme(); + ~Theme() override; Skin *readSkin(const std::string &filename); // Map containing all window skins - typedef std::map<std::string, Skin*> Skins; - typedef Skins::iterator SkinIterator; + using Skins = std::map<std::string, Skin *>; + using SkinIterator = Skins::iterator; Skins mSkins; @@ -245,7 +245,7 @@ class Theme : public Palette, public EventListener */ float mMinimumOpacity; - typedef std::vector<DyePalette*> ProgressColors; + using ProgressColors = std::vector<DyePalette *>; ProgressColors mProgressColors; }; diff --git a/src/resources/userpalette.cpp b/src/resources/userpalette.cpp index 073f5b03..8bc681b3 100644 --- a/src/resources/userpalette.cpp +++ b/src/resources/userpalette.cpp @@ -115,7 +115,7 @@ UserPalette::UserPalette(): UserPalette::~UserPalette() { - for (Colors::iterator col = mColors.begin(), + for (auto col = mColors.begin(), colEnd = mColors.end(); col != colEnd; ++col) { const std::string &configName = ColorTypeNames[col->type]; @@ -176,7 +176,7 @@ std::string UserPalette::getElementAt(int i) void UserPalette::commit(bool commitNonStatic) { - for (Colors::iterator i = mColors.begin(), iEnd = mColors.end(); + for (auto i = mColors.begin(), iEnd = mColors.end(); i != iEnd; ++i) { i->committedGrad = i->grad; @@ -194,7 +194,7 @@ void UserPalette::commit(bool commitNonStatic) void UserPalette::rollback() { - for (Colors::iterator i = mColors.begin(), iEnd = mColors.end(); + for (auto i = mColors.begin(), iEnd = mColors.end(); i != iEnd; ++i) { if (i->grad != i->committedGrad) diff --git a/src/resources/userpalette.h b/src/resources/userpalette.h index fa295f40..93056867 100644 --- a/src/resources/userpalette.h +++ b/src/resources/userpalette.h @@ -58,7 +58,7 @@ class UserPalette : public Palette, public gcn::ListModel UserPalette(); - ~UserPalette(); + ~UserPalette() override; /** * Gets the committed color associated with the specified type. @@ -123,7 +123,7 @@ class UserPalette : public Palette, public gcn::ListModel * * @return the number of colors known */ - int getNumberOfElements() { return mColors.size(); } + int getNumberOfElements() override { return mColors.size(); } /** * Returns the name of the ith color. @@ -132,7 +132,7 @@ class UserPalette : public Palette, public gcn::ListModel * * @return the name of the color */ - std::string getElementAt(int i); + std::string getElementAt(int i) override; /** * Commit the colors |