From db1428de18450600a08b7c6a05eba85a66f3cd64 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 14 Apr 2021 23:03:35 +0400 Subject: [PATCH] Move container unresolving to the separate method --- apps/openmw/mwworld/containerstore.cpp | 41 +++++++++++++------------- apps/openmw/mwworld/containerstore.hpp | 1 + 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 86c5ec331..d921c0a20 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -75,27 +75,13 @@ namespace MWWorld::ResolutionListener::~ResolutionListener() { - if(!mStore.mModified && mStore.mResolved && !mStore.mPtr.isEmpty()) + try { - try - { - for(const auto&& ptr : mStore) - ptr.getRefData().setCount(0); - } - catch(const std::exception& e) - { - Log(Debug::Warning) << "Failed to clear temporary container contents of " << mStore.mPtr.get()->mBase->mId << ": " << e.what(); - } - mStore.fillNonRandom(mStore.mPtr.get()->mBase->mInventory, "", mStore.mSeed); - try - { - addScripts(mStore, mStore.mPtr.mCell); - } - catch(const std::exception& e) - { - Log(Debug::Warning) << "Failed to restart item scripts inside " << mStore.mPtr.get()->mBase->mId << ": " << e.what(); - } - mStore.mResolved = false; + mStore.unresolve(); + } + catch(const std::exception& e) + { + Log(Debug::Error) << "Failed to clear temporary container contents of " << mStore.mPtr.get()->mBase->mId << ": " << e.what(); } } @@ -662,6 +648,21 @@ MWWorld::ResolutionHandle MWWorld::ContainerStore::resolveTemporarily() return {listener}; } +void MWWorld::ContainerStore::unresolve() +{ + if (mModified) + return; + + if (mResolved && !mPtr.isEmpty()) + { + for(const auto&& ptr : *this) + ptr.getRefData().setCount(0); + fillNonRandom(mPtr.get()->mBase->mInventory, "", mSeed); + addScripts(*this, mPtr.mCell); + mResolved = false; + } +} + float MWWorld::ContainerStore::getWeight() const { if (!mWeightUpToDate) diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index bb8ca5273..5044b0f45 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -250,6 +250,7 @@ namespace MWWorld void resolve(); ResolutionHandle resolveTemporarily(); + void unresolve(); friend class ContainerStoreIteratorBase; friend class ContainerStoreIteratorBase;