diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 20f5d8c7da..41c69a0691 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -75,7 +75,7 @@ namespace MWClass return "Item Apparatus Down"; } - std::string Apparatus::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Apparatus::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index d3ca9e6d69..43e85a9be6 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -42,7 +42,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 4c36103a1f..f3df6d37e4 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -181,7 +181,7 @@ namespace MWClass return "Item Armor Heavy Down"; } - std::string Armor::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Armor::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); @@ -247,14 +247,14 @@ namespace MWClass return info; } - std::string Armor::getEnchantment (const MWWorld::ConstPtr& ptr) const + std::string_view Armor::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); return ref->mBase->mEnchant; } - std::string Armor::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const std::string& Armor::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 30a9f5fc57..8906a22e52 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -56,13 +56,13 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override; + std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; + const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index f631772fa4..ae31a69b80 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -92,7 +92,7 @@ namespace MWClass return "Item Book Down"; } - std::string Book::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Book::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); @@ -126,14 +126,14 @@ namespace MWClass return info; } - std::string Book::getEnchantment (const MWWorld::ConstPtr& ptr) const + std::string_view Book::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); return ref->mBase->mEnchant; } - std::string Book::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const std::string& Book::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 976b6bcb58..0cb6c48a59 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -40,13 +40,13 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override; + std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; + const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index b17c2261b2..a6f7c79713 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -139,7 +139,7 @@ namespace MWClass return "Item Clothes Down"; } - std::string Clothing::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Clothing::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); @@ -175,14 +175,14 @@ namespace MWClass return info; } - std::string Clothing::getEnchantment (const MWWorld::ConstPtr& ptr) const + std::string_view Clothing::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); return ref->mBase->mEnchant; } - std::string Clothing::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const std::string& Clothing::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 731291fdd9..6b014a188d 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -48,13 +48,13 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override; + std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; + const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 887347771c..0d4e98e5ac 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -87,7 +87,7 @@ namespace MWClass return "Item Ingredient Down"; } - std::string Ingredient::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Ingredient::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 4dc3961ee4..11a6e56944 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -43,7 +43,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::string getModel(const MWWorld::ConstPtr &ptr) const override; diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 31675a4ee1..da96024ed0 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -133,7 +133,7 @@ namespace MWClass } - std::string Light::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Light::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index d4aba148db..8fd2f24d70 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -54,7 +54,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 61a7db55ca..e19b998f4c 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -86,7 +86,7 @@ namespace MWClass return "Item Lockpick Down"; } - std::string Lockpick::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Lockpick::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 7521a4c04c..ff2d07a9fc 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -44,7 +44,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 7144c51242..03dde913e0 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -118,7 +118,7 @@ namespace MWClass return "Item Misc Down"; } - std::string Miscellaneous::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Miscellaneous::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index 62caa52cc9..bd6107d45c 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -40,7 +40,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::string getModel(const MWWorld::ConstPtr &ptr) const override; diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 01dcfbecc1..cf4b667488 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -79,7 +79,7 @@ namespace MWClass return "Item Potion Down"; } - std::string Potion::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Potion::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index 49a7a9bf87..23fc2d1059 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -43,7 +43,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::string getModel(const MWWorld::ConstPtr &ptr) const override; diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 32c7da313a..105ee7e937 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -86,7 +86,7 @@ namespace MWClass return "Item Probe Down"; } - std::string Probe::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Probe::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index c4ae01ccac..d45a870f97 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -44,7 +44,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index bd0071e234..0c2233cfdf 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -76,7 +76,7 @@ namespace MWClass return "Item Repair Down"; } - std::string Repair::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Repair::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 61d63a2cea..6f84ecd854 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -40,7 +40,7 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. std::string getModel(const MWWorld::ConstPtr &ptr) const override; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 109ba94774..7f2347a988 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -135,7 +135,7 @@ namespace MWClass return MWMechanics::getWeaponType(type)->mSoundIdDown; } - std::string Weapon::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Weapon::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); @@ -250,14 +250,14 @@ namespace MWClass return info; } - std::string Weapon::getEnchantment (const MWWorld::ConstPtr& ptr) const + std::string_view Weapon::getEnchantment(const MWWorld::ConstPtr& ptr) const { const MWWorld::LiveCellRef *ref = ptr.get(); return ref->mBase->mEnchant; } - std::string Weapon::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const std::string& Weapon::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { const MWWorld::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index d067430a1b..deef3ef5e0 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -54,13 +54,13 @@ namespace MWClass std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; ///< Return the put down sound Id - std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override; + const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override; + std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string - std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; + const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; diff --git a/apps/openmw/mwgui/itemchargeview.cpp b/apps/openmw/mwgui/itemchargeview.cpp index 62d1d069e1..a8a0452d62 100644 --- a/apps/openmw/mwgui/itemchargeview.cpp +++ b/apps/openmw/mwgui/itemchargeview.cpp @@ -184,7 +184,7 @@ namespace MWGui line.mItemPtr.getClass().getItemMaxHealth(line.mItemPtr)); break; case DisplayMode_EnchantmentCharge: - std::string enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr); + std::string_view enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr); if (enchId.empty()) break; const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get().search(enchId); diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 7f74d3fb5a..165e9ba2aa 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -16,7 +16,7 @@ namespace MWGui , mCount(count) , mBase(base) { - if (base.getClass().getEnchantment(base) != "") + if (!base.getClass().getEnchantment(base).empty()) mFlags |= Flag_Enchanted; if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(base)) diff --git a/apps/openmw/mwgui/itemwidget.cpp b/apps/openmw/mwgui/itemwidget.cpp index 3f0ac39693..ffe854a72b 100644 --- a/apps/openmw/mwgui/itemwidget.cpp +++ b/apps/openmw/mwgui/itemwidget.cpp @@ -112,11 +112,11 @@ namespace MWGui void ItemWidget::setIcon(const MWWorld::Ptr &ptr) { - std::string invIcon = ptr.getClass().getInventoryIcon(ptr); - if (invIcon.empty()) - invIcon = "default icon.tga"; + std::string_view icon = ptr.getClass().getInventoryIcon(ptr); + if (icon.empty()) + icon = "default icon.tga"; const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); - invIcon = Misc::ResourceHelpers::correctIconPath(invIcon, vfs); + std::string invIcon = Misc::ResourceHelpers::correctIconPath(icon, vfs); if (!vfs->exists(invIcon)) { Log(Debug::Error) << "Failed to open image: '" << invIcon << "' not found, falling back to 'default-icon.tga'"; diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 3b02a48283..650257736f 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -281,7 +281,7 @@ namespace MWGui if (!(item.mFlags & ItemStack::Flag_Enchanted)) return false; - std::string enchId = base.getClass().getEnchantment(base); + std::string_view enchId = base.getClass().getEnchantment(base); const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get().search(enchId); if (!ench) { diff --git a/apps/openmw/mwgui/spellmodel.cpp b/apps/openmw/mwgui/spellmodel.cpp index b241570cfd..fb7f4a718d 100644 --- a/apps/openmw/mwgui/spellmodel.cpp +++ b/apps/openmw/mwgui/spellmodel.cpp @@ -127,7 +127,7 @@ namespace MWGui for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { MWWorld::Ptr item = *it; - const std::string enchantId = item.getClass().getEnchantment(item); + const std::string_view enchantId = item.getClass().getEnchantment(item); if (enchantId.empty()) continue; const ESM::Enchantment* enchant = esmStore.get().search(enchantId); diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index e8cbfedecf..18f8d4eb16 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -209,7 +209,7 @@ namespace MWMechanics auto slot = store.getSlot(slotIndex); if(slot == store.end()) continue; - const auto& enchantmentId = slot->getClass().getEnchantment(*slot); + const std::string_view enchantmentId = slot->getClass().getEnchantment(*slot); if(enchantmentId.empty()) continue; const ESM::Enchantment* enchantment = world->getStore().get().find(enchantmentId); diff --git a/apps/openmw/mwmechanics/aicombataction.cpp b/apps/openmw/mwmechanics/aicombataction.cpp index 5c546f0715..3092363537 100644 --- a/apps/openmw/mwmechanics/aicombataction.cpp +++ b/apps/openmw/mwmechanics/aicombataction.cpp @@ -344,7 +344,7 @@ namespace MWMechanics } else if (!selectedEnchItem.isEmpty()) { - std::string enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem); + std::string_view enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem); if (!enchId.empty()) { const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get().find(enchId); diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index bc680602bc..5ecbd78ad6 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -39,7 +39,7 @@ namespace MWMechanics bool applyOnStrikeEnchantment(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, const MWWorld::Ptr& object, const osg::Vec3f& hitPosition, const bool fromProjectile) { - std::string enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : ""; + std::string_view enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : ""; if (!enchantmentName.empty()) { const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().find( diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 7ed58f0d25..256e1bd871 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -98,7 +98,7 @@ namespace MWMechanics enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment); // Apply the enchantment - std::string newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); + const std::string& newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); // Add the new item to player inventory and remove the old one store.remove(mOldItemPtr, count, player); diff --git a/apps/openmw/mwmechanics/recharge.cpp b/apps/openmw/mwmechanics/recharge.cpp index b61a77f493..315495ac67 100644 --- a/apps/openmw/mwmechanics/recharge.cpp +++ b/apps/openmw/mwmechanics/recharge.cpp @@ -54,7 +54,7 @@ bool rechargeItem(const MWWorld::Ptr &item, const MWWorld::Ptr &gem) int roll = Misc::Rng::roll0to99(prng); if (roll < x) { - std::string soul = gem.getCellRef().getSoul(); + const std::string& soul = gem.getCellRef().getSoul(); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get().find(soul); float restored = creature->mData.mSoul * (roll / x); diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index b0cc26c975..f31e1baa86 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -210,7 +210,7 @@ namespace MWMechanics bool CastSpell::cast(const MWWorld::Ptr &item, int slot, bool launchProjectile) { - std::string enchantmentName = item.getClass().getEnchantment(item); + std::string_view enchantmentName = item.getClass().getEnchantment(item); if (enchantmentName.empty()) throw std::runtime_error("can't cast an item without an enchantment"); diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index aedf9c6c90..eb674e247a 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -1195,10 +1195,10 @@ namespace MWWorld void MWWorld::CellStore::checkItem(const Ptr& ptr) { - if (ptr.getClass().getEnchantment(ptr).empty()) + std::string_view enchantmentId = ptr.getClass().getEnchantment(ptr); + if (enchantmentId.empty()) return; - std::string enchantmentId = ptr.getClass().getEnchantment(ptr); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().search(enchantmentId); if (!enchantment) { diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index bbc6f2f703..928383698f 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -271,7 +271,7 @@ namespace MWWorld throw std::runtime_error("class does not support soundgen look up"); } - std::string Class::getInventoryIcon (const MWWorld::ConstPtr& ptr) const + const std::string& Class::getInventoryIcon(const MWWorld::ConstPtr& ptr) const { throw std::runtime_error ("class does not have any inventory icon"); } @@ -294,7 +294,7 @@ namespace MWWorld return true; } - std::string Class::getEnchantment (const ConstPtr& ptr) const + std::string_view Class::getEnchantment(const ConstPtr& ptr) const { return {}; } @@ -320,7 +320,7 @@ namespace MWWorld models.push_back(model); } - std::string Class::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const + const std::string& Class::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const { throw std::runtime_error ("class can't be enchanted"); } @@ -505,7 +505,7 @@ namespace MWWorld osg::Vec4f Class::getEnchantmentColor(const MWWorld::ConstPtr& item) const { osg::Vec4f result(1,1,1,1); - std::string enchantmentName = item.getClass().getEnchantment(item); + std::string_view enchantmentName = item.getClass().getEnchantment(item); if (enchantmentName.empty()) return result; diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index ceba5ce86b..e6e656299d 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -252,10 +252,10 @@ namespace MWWorld virtual float getArmorRating (const MWWorld::Ptr& ptr) const; ///< @return combined armor rating of this actor - virtual std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const; + virtual const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const; ///< Return name of inventory icon. - virtual std::string getEnchantment (const MWWorld::ConstPtr& ptr) const; + virtual std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string /// (default implementation: return empty string) @@ -278,7 +278,7 @@ namespace MWWorld virtual void getModelsToPreload(const MWWorld::Ptr& ptr, std::vector& models) const; ///< Get a list of models to preload that this object may use (directly or indirectly). default implementation: list getModel(). - virtual std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; + virtual const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. virtual std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const; diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 552a5c2388..e6a5581f44 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -444,7 +444,7 @@ void MWWorld::ContainerStore::updateRechargingItems() mRechargingItems.clear(); for (ContainerStoreIterator it = begin(); it != end(); ++it) { - const std::string& enchantmentId = it->getClass().getEnchantment(*it); + std::string_view enchantmentId = it->getClass().getEnchantment(*it); if (!enchantmentId.empty()) { const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get().search(enchantmentId); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index f214c71bda..2228f72847 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1868,7 +1868,7 @@ namespace MWWorld const MWWorld::Ptr& selectedEnchantItem = MWBase::Environment::get().getWindowManager()->getSelectedEnchantItem(); if (!selectedEnchantItem.isEmpty()) { - std::string enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem); + std::string_view enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem); if (!enchantId.empty()) { const ESM::Enchantment* ench = mStore.get().search(enchantId); @@ -1879,7 +1879,7 @@ namespace MWWorld const MWWorld::Ptr& selectedWeapon = MWBase::Environment::get().getWindowManager()->getSelectedWeapon(); if (!selectedWeapon.isEmpty()) { - std::string enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon); + std::string_view enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon); if (!enchantId.empty()) { const ESM::Enchantment* ench = mStore.get().search(enchantId); diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index 40f9a00338..6c8a732c78 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -48,26 +48,22 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path) return changeExtension(path, ".dds"); } -std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs) { /* Bethesda at some point converted all their BSA * textures from tga to dds for increased load speed, but all * texture file name references were kept as .tga. */ - std::string prefix1 = topLevelDirectory + '\\'; - std::string prefix2 = topLevelDirectory + '/'; - - std::string correctedPath = resPath; - Misc::StringUtils::lowerCaseInPlace(correctedPath); + std::string correctedPath = Misc::StringUtils::lowerCase(resPath); // Apparently, leading separators are allowed while (correctedPath.size() && (correctedPath[0] == '/' || correctedPath[0] == '\\')) correctedPath.erase(0, 1); - if(correctedPath.compare(0, prefix1.size(), prefix1.data()) != 0 && - correctedPath.compare(0, prefix2.size(), prefix2.data()) != 0) - correctedPath = prefix1 + correctedPath; + if(!correctedPath.starts_with(topLevelDirectory) || correctedPath.size() <= topLevelDirectory.size() || + (correctedPath[topLevelDirectory.size()] != '/' && correctedPath[topLevelDirectory.size()] != '\\')) + correctedPath = std::string{topLevelDirectory} + '\\' + correctedPath; std::string origExt = correctedPath; @@ -82,13 +78,17 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev return origExt; // fall back to a resource in the top level directory if it exists - std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath); + std::string fallback{topLevelDirectory}; + fallback += '\\'; + fallback += getBasename(correctedPath); if (vfs->exists(fallback)) return fallback; if (changedToDds) { - fallback = topLevelDirectory + "\\" + getBasename(origExt); + fallback = topLevelDirectory; + fallback += '\\'; + fallback += getBasename(origExt); if (vfs->exists(fallback)) return fallback; } @@ -96,27 +96,22 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev return correctedPath; } -std::string Misc::ResourceHelpers::correctTexturePath(const std::string &resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctTexturePath(std::string_view resPath, const VFS::Manager* vfs) { - static const std::string dir = "textures"; - return correctResourcePath(dir, resPath, vfs); + return correctResourcePath("textures", resPath, vfs); } -std::string Misc::ResourceHelpers::correctIconPath(const std::string &resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, const VFS::Manager* vfs) { - static const std::string dir = "icons"; - return correctResourcePath(dir, resPath, vfs); + return correctResourcePath("icons", resPath, vfs); } -std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, const VFS::Manager* vfs) { - static const std::string dir = "bookart"; - std::string image = correctResourcePath(dir, resPath, vfs); - - return image; + return correctResourcePath("bookart", resPath, vfs); } -std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, int width, int height, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, int width, int height, const VFS::Manager* vfs) { std::string image = correctBookartPath(resPath, vfs); @@ -152,14 +147,16 @@ std::string Misc::ResourceHelpers::correctMeshPath(const std::string &resPath, c return "meshes\\" + resPath; } -std::string Misc::ResourceHelpers::correctSoundPath(const std::string& resPath, const VFS::Manager* vfs) +std::string Misc::ResourceHelpers::correctSoundPath(std::string_view resPath, const VFS::Manager* vfs) { - std::string sound = resPath; // Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav. - if (!vfs->exists(sound)) + if (!vfs->exists(resPath)) + { + std::string sound{resPath}; changeExtension(sound, ".mp3"); - - return vfs->normalizeFilename(sound); + return vfs->normalizeFilename(sound); + } + return vfs->normalizeFilename(resPath); } diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp index 0be1076d7d..18a69c9419 100644 --- a/components/misc/resourcehelpers.hpp +++ b/components/misc/resourcehelpers.hpp @@ -17,16 +17,16 @@ namespace Misc namespace ResourceHelpers { bool changeExtensionToDds(std::string &path); - std::string correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs); - std::string correctTexturePath(const std::string &resPath, const VFS::Manager* vfs); - std::string correctIconPath(const std::string &resPath, const VFS::Manager* vfs); - std::string correctBookartPath(const std::string &resPath, const VFS::Manager* vfs); - std::string correctBookartPath(const std::string &resPath, int width, int height, const VFS::Manager* vfs); + std::string correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs); + std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs); + std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs); + std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs); + std::string correctBookartPath(std::string_view resPath, int width, int height, const VFS::Manager* vfs); /// Use "xfoo.nif" instead of "foo.nif" if available std::string correctActorModelPath(const std::string &resPath, const VFS::Manager* vfs); std::string correctMeshPath(const std::string &resPath, const VFS::Manager* vfs); - std::string correctSoundPath(const std::string& resPath, const VFS::Manager* vfs); + std::string correctSoundPath(std::string_view resPath, const VFS::Manager* vfs); /// marker objects that have a hardcoded function in the game logic, should be hidden from the player bool isHiddenMarker(std::string_view id);