From 43f531e9a5da9746eee09b142c6fa74387a28a5c Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 15 Apr 2022 21:24:48 +0300 Subject: [PATCH] [Client] Reuse Pathgrid records from base Cells when creating new Cells --- apps/openmw/mwmp/RecordHelper.cpp | 8 ++++++++ apps/openmw/mwworld/esmstore.hpp | 16 ++++++++++++++- apps/openmw/mwworld/store.cpp | 33 ++++++++++++++++++++++++++++++- apps/openmw/mwworld/store.hpp | 13 +++++++++++- 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index 4735d50bb..8f67b71ff 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -368,6 +368,14 @@ void RecordHelper::overrideRecord(const mwmp::CellRecord& record) world->unloadCell(finalData); world->clearCellStore(finalData); world->getModifiableStore().overrideRecord(finalData); + + // Create a Pathgrid record for this new Cell based on the base Cell's Pathgrid + // Note: This has to be done after the new Cell has been created so the Pathgrid override + // can correctly determine whether the Cell is an interior or an exterior + const ESM::Pathgrid* basePathgrid = world->getStore().get().search(record.baseId); + ESM::Pathgrid finalPathgrid = *basePathgrid; + finalPathgrid.mCell = recordData.mName; + world->getModifiableStore().overrideRecord(finalPathgrid); } else { diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 55528aed2..f9498e06a 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -276,7 +276,7 @@ namespace MWWorld /* Start of tes3mp addition - Make it possible to override a cell record similarly to how + Make it possible to override a Cell record similarly to how other types of records can be overridden */ template <> @@ -287,6 +287,20 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to override a Pathgrid record similarly to how + other types of records can be overridden + */ + template <> + inline const ESM::Pathgrid* ESMStore::overrideRecord(const ESM::Pathgrid& pathgrid) { + return mPathgrids.override(pathgrid); + } + /* + End of tes3mp addition + */ + template <> inline const ESM::Cell *ESMStore::insert(const ESM::Cell &cell) { return mCells.insert(cell); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 22da74811..66c6be35b 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -796,7 +796,7 @@ namespace MWWorld /* Start of tes3mp addition - Make it possible to override a cell record similarly to how + Make it possible to override a Cell record similarly to how other types of records can be overridden */ ESM::Cell *Store::override(const ESM::Cell &cell) @@ -949,6 +949,37 @@ namespace MWWorld return RecordId("", isDeleted); } + /* + Start of tes3mp addition + + Make it possible to override a Pathgrid record similarly to how + other types of records can be overridden + */ + ESM::Pathgrid* Store::override(const ESM::Pathgrid& pathgrid) + { + bool interior = mCells->search(pathgrid.mCell) != nullptr; + + // 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; + + return &ret.first->second; + } + 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; + + return &ret.first->second; + } + } + /* + End of tes3mp addition + */ size_t Store::getSize() const { return mInt.size() + mExt.size(); diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 8a964f982..19f77c3f0 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -325,7 +325,7 @@ namespace MWWorld /* Start of tes3mp addition - Make it possible to override a cell record similarly to how + Make it possible to override a Cell record similarly to how other types of records can be overridden */ ESM::Cell *override(const ESM::Cell &cell); @@ -362,6 +362,17 @@ namespace MWWorld void setUp() override; + /* + Start of tes3mp addition + + Make it possible to override a Pathgrid record similarly to how + other types of records can be overridden + */ + ESM::Pathgrid* override(const ESM::Pathgrid& pathgrid); + /* + End of tes3mp addition + */ + const ESM::Pathgrid *search(int x, int y) const; const ESM::Pathgrid *search(const std::string& name) const; const ESM::Pathgrid *find(int x, int y) const;