diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-05 10:13:15 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-06 21:49:14 +0000 |
commit | 3ce39d2b497ab5356290a22b324181386af51c51 (patch) | |
tree | 1b923b8be7e4d2ce8ff70768dc7fff596487935c /src/resources | |
parent | a9df89bda908e3b3d443db7f3ca865b6f12c75e5 (diff) | |
download | mana-3ce39d2b497ab5356290a22b324181386af51c51.tar.gz mana-3ce39d2b497ab5356290a22b324181386af51c51.tar.bz2 mana-3ce39d2b497ab5356290a22b324181386af51c51.tar.xz mana-3ce39d2b497ab5356290a22b324181386af51c51.zip |
General code cleanups
* Use final for all message handlers, Client, LocalPlayer,
Being::getType, Being::setPosition and Being::setMap.
(avoids some warnings about virtual dispatch in constructors)
* Use auto in more places
* Use emplace_back instead of push_back in some places
* Use default member initializers
* Less else after return
* Removed superfluous .c_str()
* Removed type aliases that are only used once
* Removed more unused includes
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/hairdb.h | 9 | ||||
-rw-r--r-- | src/resources/imageset.h | 3 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 22 | ||||
-rw-r--r-- | src/resources/itemdb.h | 20 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 6 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 20 | ||||
-rw-r--r-- | src/resources/spritedef.h | 9 |
7 files changed, 35 insertions, 54 deletions
diff --git a/src/resources/hairdb.h b/src/resources/hairdb.h index 1f75a33a..7da08b8f 100644 --- a/src/resources/hairdb.h +++ b/src/resources/hairdb.h @@ -57,7 +57,7 @@ public: * @param maxId the max permited id. If not 0, the hairDb won't * return ids > to the parameter. */ - std::vector<int> getHairStyleIds(int maxId = 0) const; + std::vector<int> getHairStyleIds(int maxId) const; /** * Returns the available hair color ids @@ -86,11 +86,8 @@ private: void loadHairStylesNode(xmlNodePtr stylesNode); // Hair colors Db - using Colors = std::map<int, std::string>; - Colors mHairColors; - - using HairStyles = std::set<int>; - HairStyles mHairStyles; + std::map<int, std::string> mHairColors; + std::set<int> mHairStyles; bool mLoaded = false; }; diff --git a/src/resources/imageset.h b/src/resources/imageset.h index 6c7d59ab..a6501cc9 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -39,6 +39,9 @@ class ImageSet : public Resource */ ImageSet(Image *img, int w, int h, int margin = 0, int spacing = 0); + ImageSet(const ImageSet&) = delete; + ImageSet& operator=(const ImageSet&) = delete; + ~ImageSet() override; /** diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 77fda11b..6ff3f58c 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -84,12 +84,11 @@ bool ItemDB::exists(int id) const return mItemInfos.find(id) != mItemInfos.end(); } -const ItemInfo &ItemDB::get(int id) +const ItemInfo &ItemDB::get(int id) const { assert(mLoaded); - ItemInfos::const_iterator i = mItemInfos.find(id); - + auto i = mItemInfos.find(id); if (i == mItemInfos.end()) { logger->log("ItemDB: Warning, unknown item ID# %d", id); @@ -99,12 +98,11 @@ const ItemInfo &ItemDB::get(int id) return *(i->second); } -const ItemInfo &ItemDB::get(const std::string &name) +const ItemInfo &ItemDB::get(const std::string &name) const { assert(mLoaded); - NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); - + auto i = mNamedItemInfos.find(normalize(name)); if (i == mNamedItemInfos.end()) { if (!name.empty()) @@ -268,7 +266,7 @@ void ItemDB::addItem(ItemInfo *itemInfo) { std::string temp = normalize(itemName); - NamedItemInfos::const_iterator itr = mNamedItemInfos.find(temp); + auto itr = mNamedItemInfos.find(temp); if (itr == mNamedItemInfos.end()) mNamedItemInfos[temp] = itemInfo; else @@ -448,8 +446,7 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename) if (trigger == "activation") itemInfo->mActivatable = true; - std::map<std::string, const char* >::const_iterator triggerLabel = - triggerTable.find(trigger); + auto triggerLabel = triggerTable.find(trigger); if (triggerLabel == triggerTable.end()) { logger->log("Warning: unknown trigger %s in item %d!", @@ -472,9 +469,8 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename) logger->log("Warning: incomplete modifier definition in %s, skipping.", filename.c_str()); continue; } - std::list<ItemStat>::const_iterator - it = extraStats.begin(), - it_end = extraStats.end(); + auto it = extraStats.cbegin(); + auto it_end = extraStats.cend(); while (it != it_end && !(*it == attribute)) ++it; if (it == extraStats.end()) @@ -495,7 +491,7 @@ void ManaServItemDB::readItemNode(xmlNodePtr node, const std::string &filename) effect.push_back(strprintf("This will be consumed%s.", triggerLabel->second)); else if (xmlStrEqual(effectChild->name, BAD_CAST "label")) - effect.push_back( + effect.emplace_back( (const char*)effectChild->xmlChildrenNode->content); } } diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 6a9988d0..84fcf210 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -75,8 +75,7 @@ class ItemDB public: ItemDB() = default; - virtual ~ItemDB() - {} + virtual ~ItemDB() = default; /** * Frees item data. @@ -91,8 +90,8 @@ class ItemDB bool exists(int id) const; - const ItemInfo &get(int id); - const ItemInfo &get(const std::string &name); + const ItemInfo &get(int id) const; + const ItemInfo &get(const std::string &name) const; virtual void init() = 0; @@ -144,11 +143,8 @@ class ItemDB void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); // Items database - using ItemInfos = std::map<int, ItemInfo *>; - using NamedItemInfos = std::map<std::string, ItemInfo *>; - - ItemInfos mItemInfos; - NamedItemInfos mNamedItemInfos; + std::map<int, ItemInfo *> mItemInfos; + std::map<std::string, ItemInfo *> mNamedItemInfos; }; namespace TmwAthena { @@ -161,8 +157,7 @@ class TaItemInfo; class TaItemDB: public ItemDB { public: - TaItemDB() - { } + TaItemDB() = default; ~TaItemDB() override { unload(); } @@ -196,8 +191,7 @@ class ManaServItemInfo; class ManaServItemDB: public ItemDB { public: - ManaServItemDB() - { } + ManaServItemDB() = default; ~ManaServItemDB() override { unload(); } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 7344d668..5922b6c1 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -229,8 +229,7 @@ class TaItemInfo: public ItemInfo friend class TaItemDB; public: - TaItemInfo() - {} + TaItemInfo() = default; // Declare TmwAthena Specific item info here }; @@ -246,8 +245,7 @@ namespace ManaServ { class ManaServItemInfo: public ItemInfo { public: - ManaServItemInfo() - {} + ManaServItemInfo() = default; // Declare Manaserv Specific item info here }; diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 3a5195cc..ec41aec0 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -75,10 +75,8 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) { return load(errorFile, 0); } - else - { - return nullptr; - } + + return nullptr; } auto *def = new SpriteDef; @@ -162,7 +160,7 @@ void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes) if (!imageSet) { logger->error(strprintf("Couldn't load imageset (%s)!", - imageSrc.c_str()).c_str()); + imageSrc.c_str())); } imageSet->setOffsetX(XML::getProperty(node, "offsetX", 0)); @@ -341,14 +339,14 @@ SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction) { if (direction.empty() || direction == "default") return DIRECTION_DEFAULT; - else if (direction == "up") + if (direction == "up") return DIRECTION_UP; - else if (direction == "left") + if (direction == "left") return DIRECTION_LEFT; - else if (direction == "right") + if (direction == "right") return DIRECTION_RIGHT; - else if (direction == "down") + if (direction == "down") return DIRECTION_DOWN; - else - return DIRECTION_INVALID; + + return DIRECTION_INVALID; } diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index dff3f2a0..fafd6a41 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -156,13 +156,8 @@ class SpriteDef : public Resource */ void substituteAction(std::string complete, std::string with); - using ImageSets = std::map<std::string, ImageSet *>; - using ImageSetIterator = ImageSets::iterator; - - using Actions = std::map<std::string, Action *>; - - ImageSets mImageSets; - Actions mActions; + std::map<std::string, ImageSet *> mImageSets; + std::map<std::string, Action *> mActions; }; #endif // SPRITEDEF_H |