From ca7add0624699736fd3d6c8b53b002e64a1bef1f Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 23 Apr 2021 23:48:55 +0200 Subject: [PATCH] Add move constructor to MWMechanics::Spells --- apps/openmw/mwmechanics/spelllist.cpp | 8 ++++++++ apps/openmw/mwmechanics/spelllist.hpp | 2 ++ apps/openmw/mwmechanics/spells.cpp | 9 +++++++++ apps/openmw/mwmechanics/spells.hpp | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/spelllist.cpp b/apps/openmw/mwmechanics/spelllist.cpp index b87b98573..d8fbcf25a 100644 --- a/apps/openmw/mwmechanics/spelllist.cpp +++ b/apps/openmw/mwmechanics/spelllist.cpp @@ -164,4 +164,12 @@ namespace MWMechanics 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();