From 9cecc92d5ca5db1a6c1b3f288f44494fc41da499 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Tue, 2 Dec 2025 17:35:15 +0300 Subject: [PATCH] Preserve static cell insertion order --- apps/openmw/mwworld/store.cpp | 21 ++++++++------------- apps/openmw/mwworld/store.hpp | 20 +------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index d864bc9595..01305b3d6e 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -639,20 +639,9 @@ namespace MWWorld for (const auto& [_, cell] : mDynamicInt) mCells.erase(cell->mId); mDynamicInt.clear(); - setUp(); - } - void Store::setUp() - { - mSharedInt.clear(); - mSharedInt.reserve(mInt.size()); - for (auto& [_, cell] : mInt) - mSharedInt.push_back(cell); - - mSharedExt.clear(); - mSharedExt.reserve(mExt.size()); - for (auto& [_, cell] : mExt) - mSharedExt.push_back(cell); + mSharedInt.erase(mSharedInt.begin() + mInt.size(), mSharedInt.end()); + mSharedExt.erase(mSharedExt.begin() + mExt.size(), mSharedExt.end()); } RecordId Store::load(ESM::ESMReader& esm) { @@ -685,7 +674,10 @@ namespace MWWorld { cell.loadCell(esm, true); if (newCell) + { mInt[cell.mName] = &cell; + mSharedInt.push_back(&cell); + } } else { @@ -698,7 +690,10 @@ namespace MWWorld // push the new references on the list of references to manage cell.postLoad(esm); if (newCell) + { mExt[std::make_pair(cell.mData.mX, cell.mData.mY)] = &cell; + mSharedExt.push_back(&cell); + } else { // merge lists of leased references, use newer data in case of conflict diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index ba12c8b379..2ccf26f734 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -360,27 +360,10 @@ namespace MWWorld template <> class Store : public DynamicStore { - struct DynamicExtCmp - { - bool operator()(const std::pair& left, const std::pair& right) const - { - if (left.first == right.first && left.second == right.second) - return false; - - if (left.first == right.first) - return left.second > right.second; - - // Exterior cells are listed in descending, row-major order, - // this is a workaround for an ambiguous chargen_plank reference in the vanilla game. - // there is one at -22,16 and one at -2,-9, the latter should be used. - return left.first > right.first; - } - }; - typedef std::unordered_map DynamicInt; - typedef std::map, ESM::Cell*, DynamicExtCmp> DynamicExt; + typedef std::map, ESM::Cell*> DynamicExt; std::unordered_map mCells; @@ -410,7 +393,6 @@ namespace MWWorld const ESM::Cell* find(int x, int y) const; void clearDynamic() override; - void setUp() override; RecordId load(ESM::ESMReader& esm) override;