From 2fe2f53b02a36f2d2aff2d510b63228ac7c29e03 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 Dec 2015 22:37:18 +0100 Subject: [PATCH] Set the changed flag in CellStore::search (Fixes #3089) --- apps/openmw/mwworld/cellstore.cpp | 15 ++++++++++----- apps/openmw/mwworld/cellstore.hpp | 6 ++++++ apps/openmw/mwworld/refdata.cpp | 14 ++++++++++---- apps/openmw/mwworld/worldimp.cpp | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index f8d53bbd9..2429a83a7 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -347,7 +347,7 @@ namespace MWWorld return std::binary_search (mIds.begin(), mIds.end(), id); /// \todo address const-issues - return const_cast (this)->search (id).isEmpty(); + return searchConst (id).isEmpty(); } struct SearchVisitor @@ -367,16 +367,21 @@ namespace MWWorld Ptr CellStore::search (const std::string& id) { - bool oldState = mHasState; - SearchVisitor searchVisitor; searchVisitor.mIdToFind = id; forEach(searchVisitor); - - mHasState = oldState; return searchVisitor.mFound; } + Ptr CellStore::searchConst (const std::string& id) const + { + bool oldState = mHasState; + /// \todo address const-issues + Ptr result = const_cast(this)->search(id); + const_cast(this)->mHasState = oldState; + return result; + } + Ptr CellStore::searchViaActorId (int id) { if (Ptr ptr = ::searchViaActorId (mNpcs, id, this, mMovedToAnotherCell)) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 8f37b6681..7047682fa 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -212,6 +212,12 @@ namespace MWWorld Ptr search (const std::string& id); ///< Will return an empty Ptr if cell is not loaded. Does not check references in /// containers. + /// @note Triggers CellStore hasState flag. + + Ptr searchConst (const std::string& id) const; + ///< Will return an empty Ptr if cell is not loaded. Does not check references in + /// containers. + /// @note Does not trigger CellStore hasState flag. Do not modify the returned Ptr! Ptr searchViaActorId (int id); ///< Will return an empty Ptr if cell is not loaded. diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index 56abba165..f20e104e7 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -166,14 +166,20 @@ namespace MWWorld void RefData::enable() { - mChanged = !mEnabled; - mEnabled = true; + if (!mEnabled) + { + mChanged = true; + mEnabled = true; + } } void RefData::disable() { - mChanged = mEnabled; - mEnabled = false; + if (mEnabled) + { + mChanged = true; + mEnabled = false; + } } void RefData::setPosition(const ESM::Position& pos) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index c9971c6f0..0969df6ca 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2828,7 +2828,7 @@ namespace MWWorld checkedCells.insert( *i ); if ( !next ) continue; - closestMarker = next->search( id ); + closestMarker = next->searchConst( id ); if ( !closestMarker.isEmpty() ) { return closestMarker;