diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index ae03e8c4e7..ebe6febf72 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -51,10 +51,17 @@ namespace ESM struct BodyPart; } +namespace ESM4 +{ + class Reader; + struct Cell; +} + namespace MWWorld { class ESMStore; struct CellStoreImp; + typedef std::variant CellVariant; using CellStoreTuple = std::tuple, CellRefList, CellRefList, CellRefList, CellRefList, CellRefList, @@ -86,6 +93,7 @@ namespace MWWorld std::unique_ptr mFogState; const ESM::Cell* mCell; + CellVariant mCellVariant; State mState; bool mHasState; std::vector mIds; diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index fb3774bcbf..2265712509 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -1183,6 +1183,31 @@ namespace MWWorld } return name; } + + // ESM4 Cell + //========================================================================= + + const ESM4::Cell* Store::searchCellName(std::string_view cellName) const + { + const auto foundCell = mCellNameIndex.find(cellName); + if (foundCell == mCellNameIndex.end()) + return nullptr; + return foundCell->second; + } + + ESM4::Cell* Store::insert(const ESM4::Cell& item, bool overrideOnly) + { + auto cellPtr = TypedDynamicStore::insert(item, overrideOnly); + mCellNameIndex[cellPtr->mEditorId] = cellPtr; + return cellPtr; + } + + ESM4::Cell* Store::insertStatic(const ESM4::Cell& item) + { + auto cellPtr = TypedDynamicStore::insertStatic(item); + mCellNameIndex[cellPtr->mEditorId] = cellPtr; + return cellPtr; + } } template class MWWorld::TypedDynamicStore; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 0b9ef56113..1b89604e0a 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -268,6 +269,19 @@ namespace MWWorld const ESM::GameSetting* find(const std::string_view id) const; const ESM::GameSetting* search(const std::string_view id) const; }; + + template <> + class Store : public TypedDynamicStore + { + std::unordered_map + mCellNameIndex; + + public: + const ESM4::Cell* searchCellName(std::string_view) const; + ESM4::Cell* insert(const ESM4::Cell& item, bool overrideOnly = false); + ESM4::Cell* insertStatic(const ESM4::Cell& item); + }; + template <> class Store : public DynamicStore { diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 781b5b7ff6..66156a2a5e 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -253,6 +253,17 @@ const ESM::Cell* MWWorld::WorldModel::getESMCellByName(std::string_view name) return cell; } +MWWorld::CellVariant MWWorld::WorldModel::getCellByName(std::string_view name) +{ + const ESM::Cell* cellEsm3 = getESMCellByName(name); + return cellEsm3; + if (!cellEsm3) + { + const ESM4::Cell* cellESM4 = mStore.get().searchCellName(name); + return cellESM4; + } +} + MWWorld::CellStore* MWWorld::WorldModel::getCell(std::string_view name) { const ESM::Cell* cell = getESMCellByName(name); diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index 6536c063fe..9caada64c0 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -21,6 +22,11 @@ namespace ESM struct RefNum; } +namespace ESM4 +{ + struct Cell; +} + namespace Loading { class Listener; @@ -45,8 +51,9 @@ namespace MWWorld WorldModel& operator=(const WorldModel&); const ESM::Cell* getESMCellByName(std::string_view name); - CellStore* getCellStore(const ESM::Cell* cell); + CellVariant getCellByName(std::string_view name); + CellStore* getCellStore(const ESM::Cell* cell); Ptr getPtrAndCache(const ESM::RefId& name, CellStore& cellStore); Ptr getPtr(CellStore& cellStore, const ESM::RefId& id, const ESM::RefNum& refNum);