Merge branch 'fix_lua_teleport' into 'master'
Some checks are pending
Build and test / Ubuntu (push) Waiting to run
Build and test / MacOS (push) Waiting to run
Build and test / Read .env file and expose it as output (push) Waiting to run
Build and test / Windows (2019) (push) Blocked by required conditions
Build and test / Windows (2022) (push) Blocked by required conditions

Merge deleted refs when unloading a cell (#8311)

Closes #8311

See merge request OpenMW/openmw!4575
This commit is contained in:
Alexei Kotov 2025-03-09 15:51:01 +03:00
commit a49a900a7b
2 changed files with 13 additions and 13 deletions

View file

@ -337,13 +337,13 @@ namespace
// helper function for forEachInternal // helper function for forEachInternal
template <class Visitor, class List> template <class Visitor, class List>
bool forEachImp(Visitor& visitor, List& list, MWWorld::CellStore* cellStore) bool forEachImp(Visitor& visitor, List& list, MWWorld::CellStore& cellStore, bool includeDeleted)
{ {
for (typename List::List::iterator iter(list.mList.begin()); iter != list.mList.end(); ++iter) for (auto& v : list.mList)
{ {
if (!MWWorld::CellStore::isAccessible(iter->mData, iter->mRef)) if (!includeDeleted && !MWWorld::CellStore::isAccessible(v.mData, v.mRef))
continue; continue;
if (!visitor(MWWorld::Ptr(&*iter, cellStore))) if (!visitor(MWWorld::Ptr(&v, &cellStore)))
return false; return false;
} }
return true; return true;
@ -399,12 +399,12 @@ namespace MWWorld
// listing only objects owned by this cell. Internal use only, you probably want to use forEach() so that moved // listing only objects owned by this cell. Internal use only, you probably want to use forEach() so that moved
// objects are accounted for. // objects are accounted for.
template <class Visitor> template <class Visitor>
static bool forEachInternal(Visitor& visitor, MWWorld::CellStore& cellStore) static bool forEachInternal(Visitor& visitor, MWWorld::CellStore& cellStore, bool includeDeleted)
{ {
bool returnValue = true; bool returnValue = true;
Misc::tupleForEach(cellStore.mCellStoreImp->mRefLists, [&visitor, &returnValue, &cellStore](auto& store) { Misc::tupleForEach(cellStore.mCellStoreImp->mRefLists, [&](auto& store) {
returnValue = returnValue && forEachImp(visitor, store, &cellStore); returnValue = returnValue && forEachImp(visitor, store, cellStore, includeDeleted);
}); });
return returnValue; return returnValue;
@ -583,11 +583,11 @@ namespace MWWorld
mMergedRefsNeedsUpdate = true; mMergedRefsNeedsUpdate = true;
} }
void CellStore::updateMergedRefs() const void CellStore::updateMergedRefs(bool includeDeleted) const
{ {
mMergedRefs.clear(); mMergedRefs.clear();
MergeVisitor visitor(mMergedRefs, mMovedHere, mMovedToAnotherCell); MergeVisitor visitor(mMergedRefs, mMovedHere, mMovedToAnotherCell);
CellStoreImp::forEachInternal(visitor, const_cast<CellStore&>(*this)); CellStoreImp::forEachInternal(visitor, const_cast<CellStore&>(*this), includeDeleted);
visitor.merge(); visitor.merge();
mMergedRefsNeedsUpdate = false; mMergedRefsNeedsUpdate = false;
} }

View file

@ -219,7 +219,7 @@ namespace MWWorld
return false; return false;
if (mMergedRefsNeedsUpdate) if (mMergedRefsNeedsUpdate)
updateMergedRefs(); updateMergedRefs(includeDeleted);
if (mMergedRefs.empty()) if (mMergedRefs.empty())
return true; return true;
@ -248,7 +248,7 @@ namespace MWWorld
return false; return false;
if (mMergedRefsNeedsUpdate) if (mMergedRefsNeedsUpdate)
updateMergedRefs(); updateMergedRefs(includeDeleted);
for (const LiveCellRefBase* mergedRef : mMergedRefs) for (const LiveCellRefBase* mergedRef : mMergedRefs)
{ {
@ -273,7 +273,7 @@ namespace MWWorld
return false; return false;
if (mMergedRefsNeedsUpdate) if (mMergedRefsNeedsUpdate)
updateMergedRefs(); updateMergedRefs(includeDeleted);
if (mMergedRefs.empty()) if (mMergedRefs.empty())
return true; return true;
@ -403,7 +403,7 @@ namespace MWWorld
/// Repopulate mMergedRefs. /// Repopulate mMergedRefs.
void requestMergedRefsUpdate(); void requestMergedRefsUpdate();
void updateMergedRefs() const; void updateMergedRefs(bool includeDeleted = false) const;
// (item, max charge) // (item, max charge)
typedef std::vector<std::pair<LiveCellRefBase*, float>> TRechargingItems; typedef std::vector<std::pair<LiveCellRefBase*, float>> TRechargingItems;