From 1a7b4283e7e06fa046ae66542d45b80408d2544c Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 23 Jul 2023 18:24:55 +0200 Subject: [PATCH 1/2] Avoid duplicated emplace for interior cell store --- apps/openmw/mwworld/worldmodel.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 65eabadaa1..6e72d25978 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -32,10 +32,10 @@ namespace MWWorld CellStore& emplaceCellStore(ESM::RefId id, const T& cell, ESMStore& store, ESM::ReadersCache& readers, std::unordered_map& cells) { - return cells - .emplace(std::piecewise_construct, std::forward_as_tuple(id), - std::forward_as_tuple(Cell(cell), store, readers)) - .first->second; + const auto [it, inserted] = cells.emplace( + std::piecewise_construct, std::forward_as_tuple(id), std::forward_as_tuple(Cell(cell), store, readers)); + assert(inserted); + return it->second; } const ESM::Cell* createEsmCell(ESM::ExteriorCellLocation location, ESMStore& store) @@ -205,6 +205,7 @@ namespace MWWorld cellStore = &emplaceCellStore(cell4->mId, *cell4, mStore, mReaders, mCells); else return nullptr; + mInteriors.emplace(name, cellStore); } else { From 8ceb79caf5f5c8f843328ae242f841c8f8654a9d Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 23 Jul 2023 18:25:20 +0200 Subject: [PATCH 2/2] Load present cell store when requested --- apps/openmw/mwworld/worldmodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 6e72d25978..20067afefe 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -231,7 +231,12 @@ namespace MWWorld { auto it = mCells.find(id); if (it != mCells.end()) - return &it->second; + { + CellStore& cellStore = it->second; + if (forceLoad && cellStore.getState() != CellStore::State_Loaded) + cellStore.load(); + return &cellStore; + } if (id == draftCellId) {