From ea1abf8485c19e72f2e2ce5bba7e72f38e98f4aa Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Apr 2023 20:18:11 +0200 Subject: [PATCH 1/2] Unify pathgrid store containers --- apps/openmw/mwworld/store.cpp | 66 +++++++---------------------------- apps/openmw/mwworld/store.hpp | 8 +---- 2 files changed, 14 insertions(+), 60 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 79142b44f0..2d084e70ce 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -896,72 +896,38 @@ namespace MWWorld bool interior = pathgrid.mData.mX == 0 && pathgrid.mData.mY == 0 && mCells->search(pathgrid.mCell.getRefIdString()) != nullptr; + ESM::RefId cell + = interior ? pathgrid.mCell : ESM::RefId::esm3ExteriorCell(pathgrid.mData.mX, pathgrid.mData.mY); // deal with mods that have empty pathgrid records (Issue #6209) // we assume that these records are empty on purpose (i.e. to remove old pathgrid on an updated cell) if (isDeleted || pathgrid.mPoints.empty() || pathgrid.mEdges.empty()) { - if (interior) - { - Interior::iterator it = mInt.find(pathgrid.mCell); - if (it != mInt.end()) - mInt.erase(it); - } - else - { - Exterior::iterator it = mExt.find(std::make_pair(pathgrid.mData.mX, pathgrid.mData.mY)); - if (it != mExt.end()) - mExt.erase(it); - } + auto it = mStatic.find(cell); + if (it != mStatic.end()) + mStatic.erase(it); return RecordId(ESM::RefId(), isDeleted); } // Try to overwrite existing record - if (interior) - { - std::pair ret = mInt.insert(std::make_pair(pathgrid.mCell, pathgrid)); - if (!ret.second) - ret.first->second = pathgrid; - } - else - { - std::pair ret - = mExt.insert(std::make_pair(std::make_pair(pathgrid.mData.mX, pathgrid.mData.mY), pathgrid)); - if (!ret.second) - ret.first->second = pathgrid; - } + auto ret = mStatic.emplace(cell, pathgrid); + if (!ret.second) + ret.first->second = pathgrid; return RecordId(ESM::RefId(), isDeleted); } size_t Store::getSize() const { - return mInt.size() + mExt.size(); + return mStatic.size(); } void Store::setUp() {} - const ESM::Pathgrid* Store::search(int x, int y) const - { - Exterior::const_iterator it = mExt.find(std::make_pair(x, y)); - if (it != mExt.end()) - return &(it->second); - return nullptr; - } const ESM::Pathgrid* Store::search(const ESM::RefId& name) const { - Interior::const_iterator it = mInt.find(ESM::RefId(name)); - if (it != mInt.end()) + auto it = mStatic.find(name); + if (it != mStatic.end()) return &(it->second); return nullptr; } - const ESM::Pathgrid* Store::find(int x, int y) const - { - const ESM::Pathgrid* pathgrid = search(x, y); - if (!pathgrid) - { - const std::string msg = "Pathgrid in cell '" + std::to_string(x) + " " + std::to_string(y) + "' not found"; - throw std::runtime_error(msg); - } - return pathgrid; - } const ESM::Pathgrid* Store::find(const ESM::RefId& name) const { const ESM::Pathgrid* pathgrid = search(name); @@ -971,10 +937,7 @@ namespace MWWorld } const ESM::Pathgrid* Store::search(const ESM::Cell& cell) const { - if (!(cell.mData.mFlags & ESM::Cell::Interior)) - return search(cell.mData.mX, cell.mData.mY); - else - return search(ESM::RefId::stringRefId(cell.mName)); + return search(cell.mId); } const ESM::Pathgrid* Store::search(const MWWorld::Cell& cellVariant) const { @@ -986,10 +949,7 @@ namespace MWWorld } const ESM::Pathgrid* Store::find(const ESM::Cell& cell) const { - if (!(cell.mData.mFlags & ESM::Cell::Interior)) - return find(cell.mData.mX, cell.mData.mY); - else - return find(ESM::RefId::stringRefId(cell.mName)); + return find(cell.mId); } // Skill diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index a3a54ac3ff..4494b71bc6 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -414,12 +414,8 @@ namespace MWWorld class Store : public DynamicStore { private: - typedef std::unordered_map Interior; - typedef std::map, ESM::Pathgrid> Exterior; - - Interior mInt; - Exterior mExt; + std::unordered_map mStatic; Store* mCells; public: @@ -431,9 +427,7 @@ namespace MWWorld void setUp() override; - const ESM::Pathgrid* search(int x, int y) const; const ESM::Pathgrid* search(const ESM::RefId& name) const; - const ESM::Pathgrid* find(int x, int y) const; const ESM::Pathgrid* find(const ESM::RefId& name) const; const ESM::Pathgrid* search(const ESM::Cell& cell) const; const ESM::Pathgrid* search(const MWWorld::Cell& cell) const; From 9368941f62d8bb72ac68b9db51f429a3111ff19c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Apr 2023 02:31:40 +0200 Subject: [PATCH 2/2] Address feedback --- apps/openmw/mwworld/store.cpp | 4 +--- apps/openmw/mwworld/store.hpp | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 2d084e70ce..280c682d70 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -902,9 +902,7 @@ namespace MWWorld // we assume that these records are empty on purpose (i.e. to remove old pathgrid on an updated cell) if (isDeleted || pathgrid.mPoints.empty() || pathgrid.mEdges.empty()) { - auto it = mStatic.find(cell); - if (it != mStatic.end()) - mStatic.erase(it); + mStatic.erase(cell); return RecordId(ESM::RefId(), isDeleted); } diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 4494b71bc6..58636acdb6 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -414,7 +414,6 @@ namespace MWWorld class Store : public DynamicStore { private: - std::unordered_map mStatic; Store* mCells;