From f89de74b1ac1cd9a02a70dab9221d601296da8cd Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 2 Nov 2015 17:23:32 +0300 Subject: Add intmap defines. --- src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/being/being.cpp | 9 ++++----- src/being/playerinfo.h | 4 ++-- src/gui/windows/questswindow.cpp | 6 ++---- src/gui/windows/questswindow.h | 3 ++- src/resources/db/itemdb.cpp | 14 ++++++-------- src/resources/iteminfo.cpp | 6 +++--- src/resources/iteminfo.h | 10 ++++++---- src/utils/intmap.h | 30 ++++++++++++++++++++++++++++++ 10 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 src/utils/intmap.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 75ff6fe9b..4a34b1c90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -763,6 +763,7 @@ SET(SRCS utils/gettexthelper.h utils/glxhelper.cpp utils/glxhelper.h + utils/intmap.h utils/langs.cpp utils/langs.h utils/mathutils.h diff --git a/src/Makefile.am b/src/Makefile.am index 7b1e9cffb..0f9670331 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -409,6 +409,7 @@ SRC += events/actionevent.h \ utils/gettexthelper.h \ utils/glxhelper.cpp \ utils/glxhelper.h \ + utils/intmap.h \ utils/langs.cpp \ utils/langs.h \ utils/mathutils.h \ diff --git a/src/being/being.cpp b/src/being/being.cpp index 686b73f54..7a937ceaf 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -2972,7 +2972,7 @@ void Being::recalcSpritesOrder() return; std::vector slotRemap; - std::map itemSlotRemap; + IntMap itemSlotRemap; std::vector::iterator it; int oldHide[20]; @@ -3018,7 +3018,7 @@ void Being::recalcSpritesOrder() FOR_EACHP (SpriteToItemMapCIter, itr, spriteToItems) { const int remSprite = itr->first; - const std::map &itemReplacer = itr->second; + const IntMap &itemReplacer = itr->second; if (remSprite >= 0) { // slot known if (itemReplacer.empty()) @@ -3027,7 +3027,7 @@ void Being::recalcSpritesOrder() } else if (mSpriteHide[remSprite] != 1) { - std::map::const_iterator repIt + IntMapCIter repIt = itemReplacer.find(mSpriteIDs[remSprite]); if (repIt == itemReplacer.end()) { @@ -3169,8 +3169,7 @@ void Being::recalcSpritesOrder() int idx1 = -1; // logger->log("item %d, id=%d", slot, id); int reorder = 0; - const std::map::const_iterator - orderIt = itemSlotRemap.find(id); + const IntMapCIter orderIt = itemSlotRemap.find(id); if (orderIt != itemSlotRemap.end()) reorder = orderIt->second; diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h index cba86bd79..3a74754e1 100644 --- a/src/being/playerinfo.h +++ b/src/being/playerinfo.h @@ -35,7 +35,8 @@ #include "enums/simpletypes/sfx.h" #include "enums/simpletypes/trading.h" -#include +#include "utils/intmap.h" + #ifdef EATHENA_SUPPORT #include #endif @@ -51,7 +52,6 @@ struct Stat final int expNeed; }; -typedef std::map IntMap; typedef std::map AtrIntMap; typedef std::map StatMap; diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp index 690781cea..8d4d1eebb 100644 --- a/src/gui/windows/questswindow.cpp +++ b/src/gui/windows/questswindow.cpp @@ -295,8 +295,7 @@ void QuestsWindow::rebuild(const bool playSound) int updatedQuest = -1; int newCompleteStatus = -1; - for (std::map::const_iterator it = mVars.begin(), - it_end = mVars.end(); it != it_end; ++ it) + FOR_EACH (IntMapCIter, it, mVars) { const int var = (*it).first; const int val = (*it).second; @@ -454,8 +453,7 @@ void QuestsWindow::updateEffects() const QuestEffect *const effect = *it; if (effect) { - const std::map::const_iterator - varIt = mVars.find(effect->var); + const IntMapCIter varIt = mVars.find(effect->var); if (varIt != mVars.end()) { const std::set &vals = effect->values; diff --git a/src/gui/windows/questswindow.h b/src/gui/windows/questswindow.h index 031f239cd..d016a6a25 100644 --- a/src/gui/windows/questswindow.h +++ b/src/gui/windows/questswindow.h @@ -27,6 +27,7 @@ #include "gui/widgets/window.h" +#include "utils/intmap.h" #include "utils/xml.h" #include "listeners/actionlistener.h" @@ -87,7 +88,7 @@ class QuestsWindow final : public Window, Image *mCompleteIcon; Image *mIncompleteIcon; // quest variables: var, value - std::map mVars; + IntMap mVars; // quests: var, quests std::map > mQuests; std::vector mAllEffects; diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index da3444c0e..9de6b307e 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -589,11 +589,10 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) itr_end = spriteToItems->end(); itr != itr_end; ++ itr) { const int remSprite = itr->first; - const std::map &itemReplacer = itr->second; + const IntMap &itemReplacer = itr->second; logger->log("sprite: %d", remSprite); - for (std::map::const_iterator - repIt = itemReplacer.begin(), + for (IntMapCIter repIt = itemReplacer.begin(), repIt_end = itemReplacer.end(); repIt != repIt_end; ++ repIt) { @@ -934,8 +933,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, { // replace only given sprites for (int f = 0; f < 10; f ++) { - std::map *const mapList - = itemInfo->addReplaceSprite( + IntMap *const mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), f); if (!mapList) continue; @@ -969,7 +967,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, { const int from = XML::getProperty(itemNode, "from", 0); const int to = XML::getProperty(itemNode, "to", 1); - std::map *mapList = itemInfo->addReplaceSprite( + IntMap *mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), SpriteDirection::DOWN); if (mapList) (*mapList)[from] = to; @@ -1002,7 +1000,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, { const int from = XML::getProperty(itemNode, "from", 0); const int to = XML::getProperty(itemNode, "to", 1); - std::map *mapList = itemInfo->addReplaceSprite( + IntMap *mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), SpriteDirection::UP); if (mapList) (*mapList)[from] = to; @@ -1022,7 +1020,7 @@ static void loadReplaceSprite(ItemInfo *const itemInfo, } default: { - std::map *const mapList = itemInfo->addReplaceSprite( + IntMap *const mapList = itemInfo->addReplaceSprite( parseSpriteName(removeSprite), direction); if (!mapList) return; diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 56b2e1fe0..9e3e4acfa 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -165,8 +165,8 @@ const SoundInfo &ItemInfo::getSound(const ItemSoundEvent::Type event) const % i->second.size()] : empty; } -std::map *ItemInfo::addReplaceSprite(const int sprite, - const int direction) +IntMap *ItemInfo::addReplaceSprite(const int sprite, + const int direction) { if (direction < 0 || direction >= 10) return nullptr; @@ -183,7 +183,7 @@ std::map *ItemInfo::addReplaceSprite(const int sprite, SpriteToItemMap::iterator it = spMap->find(sprite); if (it == spMap->end()) { - std::map tmp; + IntMap tmp; (*mSpriteToItemReplaceMap[direction])[sprite] = tmp; it = mSpriteToItemReplaceMap[direction]->find(sprite); } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index ebc267e15..1233daf73 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -33,13 +33,15 @@ #include "resources/soundinfo.h" #include "resources/spritedisplay.h" +#include "utils/intmap.h" + namespace ColorDB { class ItemColorData; } // sprite, -typedef std::map > SpriteToItemMap; +typedef std::map SpriteToItemMap; typedef SpriteToItemMap::const_iterator SpriteToItemMapCIter; /** @@ -202,7 +204,7 @@ class ItemInfo final void setDrawPriority(const int direction, const int n); - const std::map &getTags() const A_WARN_UNUSED + const IntMap &getTags() const A_WARN_UNUSED { return mTags; } void addTag(const int tag) @@ -239,8 +241,8 @@ class ItemInfo final int getReplaceToSpriteId(int id) const A_WARN_UNUSED; - std::map *addReplaceSprite(const int sprite, - const int direction); + IntMap *addReplaceSprite(const int sprite, + const int direction); const SpriteToItemMap *getSpriteToItemReplaceMap(const int directions) const A_WARN_UNUSED; diff --git a/src/utils/intmap.h b/src/utils/intmap.h new file mode 100644 index 000000000..1657181c1 --- /dev/null +++ b/src/utils/intmap.h @@ -0,0 +1,30 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef UTILS_INTMAP_H +#define UTILS_INTMAP_H + +#include + +typedef std::map IntMap; +typedef IntMap::iterator IntMapIter; +typedef IntMap::const_iterator IntMapCIter; + +#endif // UTILS_INTMAP_H -- cgit v1.2.3-70-g09d2