diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 6b8d2f3f2..5ce9a66ab 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -60,7 +60,7 @@ namespace MWClass CreatureCustomData() = default; CreatureCustomData(const CreatureCustomData& other); - CreatureCustomData(CreatureCustomData&& other) noexcept = default; + CreatureCustomData(CreatureCustomData&& other) = default; CreatureCustomData& asCreatureCustomData() override { diff --git a/apps/openmw/mwmechanics/spelllist.cpp b/apps/openmw/mwmechanics/spelllist.cpp index 891b28619..d8fbcf25a 100644 --- a/apps/openmw/mwmechanics/spelllist.cpp +++ b/apps/openmw/mwmechanics/spelllist.cpp @@ -153,23 +153,23 @@ namespace MWMechanics void SpellList::addListener(Spells* spells) { - for(const auto ptr : mListeners) - { - if(ptr == spells) - return; - } + if (std::find(mListeners.begin(), mListeners.end(), spells) != mListeners.end()) + return; mListeners.push_back(spells); } void SpellList::removeListener(Spells* spells) { - for(auto it = mListeners.begin(); it != mListeners.end(); it++) - { - if(*it == spells) - { - mListeners.erase(it); - break; - } - } + const auto it = std::find(mListeners.begin(), mListeners.end(), spells); + if (it != mListeners.end()) + mListeners.erase(it); + } + + void SpellList::updateListener(Spells* before, Spells* after) + { + const auto it = std::find(mListeners.begin(), mListeners.end(), before); + if (it == mListeners.end()) + return mListeners.push_back(after); + *it = after; } } diff --git a/apps/openmw/mwmechanics/spelllist.hpp b/apps/openmw/mwmechanics/spelllist.hpp index b01722fe8..c95ee812b 100644 --- a/apps/openmw/mwmechanics/spelllist.hpp +++ b/apps/openmw/mwmechanics/spelllist.hpp @@ -61,6 +61,8 @@ namespace MWMechanics void removeListener(Spells* spells); + void updateListener(Spells* before, Spells* after); + const std::vector getSpells() const; }; } diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index 0af74e01b..b87137600 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -32,6 +32,15 @@ namespace MWMechanics mSpellList->addListener(this); } + Spells::Spells(Spells&& spells) : mSpellList(std::move(spells.mSpellList)), mSpells(std::move(spells.mSpells)), + mSelectedSpell(std::move(spells.mSelectedSpell)), mUsedPowers(std::move(spells.mUsedPowers)), + mSpellsChanged(std::move(spells.mSpellsChanged)), mEffects(std::move(spells.mEffects)), + mSourcedEffects(std::move(spells.mSourcedEffects)) + { + if (mSpellList) + mSpellList->updateListener(&spells, this); + } + std::map::const_iterator Spells::begin() const { return mSpells.begin(); diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 3df89a537..055339795 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -59,7 +59,7 @@ namespace MWMechanics Spells(const Spells&); - Spells(const Spells&&) = delete; + Spells(Spells&& spells); ~Spells();