Set the changed flag in CellStore::search (Fixes #3089)

This commit is contained in:
scrawl 2015-12-17 22:37:18 +01:00
parent 04b6571d7d
commit 2fe2f53b02
4 changed files with 27 additions and 10 deletions

View file

@ -347,7 +347,7 @@ namespace MWWorld
return std::binary_search (mIds.begin(), mIds.end(), id); return std::binary_search (mIds.begin(), mIds.end(), id);
/// \todo address const-issues /// \todo address const-issues
return const_cast<CellStore *> (this)->search (id).isEmpty(); return searchConst (id).isEmpty();
} }
struct SearchVisitor struct SearchVisitor
@ -367,16 +367,21 @@ namespace MWWorld
Ptr CellStore::search (const std::string& id) Ptr CellStore::search (const std::string& id)
{ {
bool oldState = mHasState;
SearchVisitor searchVisitor; SearchVisitor searchVisitor;
searchVisitor.mIdToFind = id; searchVisitor.mIdToFind = id;
forEach(searchVisitor); forEach(searchVisitor);
mHasState = oldState;
return searchVisitor.mFound; return searchVisitor.mFound;
} }
Ptr CellStore::searchConst (const std::string& id) const
{
bool oldState = mHasState;
/// \todo address const-issues
Ptr result = const_cast<CellStore*>(this)->search(id);
const_cast<CellStore*>(this)->mHasState = oldState;
return result;
}
Ptr CellStore::searchViaActorId (int id) Ptr CellStore::searchViaActorId (int id)
{ {
if (Ptr ptr = ::searchViaActorId (mNpcs, id, this, mMovedToAnotherCell)) if (Ptr ptr = ::searchViaActorId (mNpcs, id, this, mMovedToAnotherCell))

View file

@ -212,6 +212,12 @@ namespace MWWorld
Ptr search (const std::string& id); Ptr search (const std::string& id);
///< Will return an empty Ptr if cell is not loaded. Does not check references in ///< Will return an empty Ptr if cell is not loaded. Does not check references in
/// containers. /// 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); Ptr searchViaActorId (int id);
///< Will return an empty Ptr if cell is not loaded. ///< Will return an empty Ptr if cell is not loaded.

View file

@ -166,14 +166,20 @@ namespace MWWorld
void RefData::enable() void RefData::enable()
{ {
mChanged = !mEnabled; if (!mEnabled)
mEnabled = true; {
mChanged = true;
mEnabled = true;
}
} }
void RefData::disable() void RefData::disable()
{ {
mChanged = mEnabled; if (mEnabled)
mEnabled = false; {
mChanged = true;
mEnabled = false;
}
} }
void RefData::setPosition(const ESM::Position& pos) void RefData::setPosition(const ESM::Position& pos)

View file

@ -2828,7 +2828,7 @@ namespace MWWorld
checkedCells.insert( *i ); checkedCells.insert( *i );
if ( !next ) continue; if ( !next ) continue;
closestMarker = next->search( id ); closestMarker = next->searchConst( id );
if ( !closestMarker.isEmpty() ) if ( !closestMarker.isEmpty() )
{ {
return closestMarker; return closestMarker;