diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 44306c30a5..d158755736 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -583,8 +583,8 @@ namespace MWGui if (!entry.mMapTexture) { if (!mInterior) - requestMapRender( - &MWBase::Environment::get().getWorldModel()->getExterior(entry.mCellX, entry.mCellY)); + requestMapRender(&MWBase::Environment::get().getWorldModel()->getExterior( + entry.mCellX, entry.mCellY, ESM::Cell::sDefaultWorldspaceId)); osg::ref_ptr texture = mLocalMapRender->getMapTexture(entry.mCellX, entry.mCellY); if (texture) @@ -641,7 +641,8 @@ namespace MWGui for (MapEntry& entry : mMaps) { if (!entry.mMapTexture && !widgetCropped(entry.mMapWidget, mLocalMap)) - world->getDoorMarkers(worldModel->getExterior(entry.mCellX, entry.mCellY), doors); + world->getDoorMarkers( + worldModel->getExterior(entry.mCellX, entry.mCellY, ESM::Cell::sDefaultWorldspaceId), doors); } if (doors.empty()) return; diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 55ff9fa601..c01b9361b1 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -130,8 +130,8 @@ namespace MWGui = MWWorld::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); if (cellname.empty()) { - MWWorld::CellStore& cell - = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y()); + MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior( + cellIndex.x(), cellIndex.y(), ESM::Cell::sDefaultWorldspaceId); cellname = MWBase::Environment::get().getWorld()->getCellName(&cell); interior = false; } diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index e05466740c..3e40503fbe 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -113,8 +113,10 @@ namespace MWLua addTimeBindings(api, context, true); api["getCellByName"] = [](std::string_view name) { return GCell{ &MWBase::Environment::get().getWorldModel()->getCell(name) }; }; - api["getExteriorCell"] - = [](int x, int y) { return GCell{ &MWBase::Environment::get().getWorldModel()->getExterior(x, y) }; }; + api["getExteriorCell"] = [](int x, int y) { + return GCell{ &MWBase::Environment::get().getWorldModel()->getExterior( + x, y, ESM::Cell::sDefaultWorldspaceId) }; + }; api["activeActors"] = GObjectList{ worldView->getActorsInScene() }; api["createObject"] = [](std::string_view recordId, sol::optional count) -> GObject { // Doesn't matter which cell to use because the new object will be in disabled state. diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 110309ae1a..4f7a136764 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -402,7 +402,8 @@ namespace MWScript if (store->isExterior()) { const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); - store = &worldModel->getExterior(cellIndex.x(), cellIndex.y()); + store + = &worldModel->getExterior(cellIndex.x(), cellIndex.y(), store->getCell()->getWorldSpace()); } } catch (std::exception&) @@ -417,7 +418,7 @@ namespace MWScript if (!isPlayer) return; const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); - store = &worldModel->getExterior(cellIndex.x(), cellIndex.y()); + store = &worldModel->getExterior(cellIndex.x(), cellIndex.y(), store->getCell()->getWorldSpace()); } if (store) { @@ -473,8 +474,8 @@ namespace MWScript MWWorld::Ptr base = ptr; if (isPlayer) { - MWWorld::CellStore* cell - = &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y()); + MWWorld::CellStore* cell = &MWBase::Environment::get().getWorldModel()->getExterior( + cellIndex.x(), cellIndex.y(), ESM::Cell::sDefaultWorldspaceId); ptr = world->moveObject(ptr, cell, osg::Vec3(x, y, z)); } else @@ -568,7 +569,8 @@ namespace MWScript if (player.getCell()->isExterior()) { const osg::Vec2i cellIndex = MWWorld::positionToCellIndex(x, y); - store = &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex.x(), cellIndex.y()); + store = &MWBase::Environment::get().getWorldModel()->getExterior( + cellIndex.x(), cellIndex.y(), player.getCell()->getCell()->getWorldSpace()); } else store = player.getCell(); diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 38bba75c05..836f4a765a 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -563,7 +563,8 @@ void MWState::StateManager::loadGame(const Character* character, const std::file { // Cell no longer exists (i.e. changed game files), choose a default cell Log(Debug::Warning) << "Warning: Player character's cell no longer exists, changing to the default cell"; - MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(0, 0); + MWWorld::CellStore& cell + = MWBase::Environment::get().getWorldModel()->getExterior(0, 0, ESM::Cell::sDefaultWorldspaceId); float x, y; MWBase::Environment::get().getWorld()->indexToPosition(0, 0, x, y, false); ESM::Position pos; diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index ad1a3ff428..d569b155cb 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 004c456ff1..792ba6f46a 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -42,6 +42,7 @@ namespace ESM4 struct Ingredient; struct MiscItem; struct Weapon; + struct World; } namespace ESM @@ -120,7 +121,7 @@ namespace MWWorld Store, Store, Store, Store, Store, Store, Store, Store, Store, Store, Store, Store, Store, Store, - Store>; + Store, Store>; private: template diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 65dd36c691..c82c3f95b1 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -551,12 +551,13 @@ namespace MWWorld else unloadCell(cell, navigatorUpdateGuard.get()); } - - mNavigator.setWorldspace(Misc::StringUtils::lowerCase(mWorld.getWorldModel() - .getExterior(playerCellX, playerCellY) - .getCell() - ->getWorldSpace() - .serializeText()), + ESM::RefId currentWorldSpace = mCurrentCell->getCell()->getWorldSpace(); + mNavigator.setWorldspace( + Misc::StringUtils::lowerCase(mWorld.getWorldModel() + .getExterior(playerCellX, playerCellY, currentWorldSpace) + .getCell() + ->getWorldSpace() + .serializeText()), navigatorUpdateGuard.get()); mNavigator.updateBounds(pos, navigatorUpdateGuard.get()); @@ -580,7 +581,7 @@ namespace MWWorld { if (!isCellInCollection(x, y, collection)) { - refsToLoad += mWorld.getWorldModel().getExterior(x, y).count(); + refsToLoad += mWorld.getWorldModel().getExterior(x, y, currentWorldSpace).count(); cellsPositionsToLoad.emplace_back(x, y); } } @@ -614,7 +615,7 @@ namespace MWWorld { if (!isCellInCollection(x, y, mActiveCells)) { - CellStore& cell = mWorld.getWorldModel().getExterior(x, y); + CellStore& cell = mWorld.getWorldModel().getExterior(x, y, currentWorldSpace); loadCell(cell, loadingListener, changeEvent, pos, navigatorUpdateGuard.get()); } } @@ -623,7 +624,7 @@ namespace MWWorld navigatorUpdateGuard.reset(); - CellStore& current = mWorld.getWorldModel().getExterior(playerCellX, playerCellY); + CellStore& current = mWorld.getWorldModel().getExterior(playerCellX, playerCellY, currentWorldSpace); MWBase::Environment::get().getWindowManager()->changeCell(¤t); if (changeEvent) @@ -676,7 +677,8 @@ namespace MWWorld loadingListener->setLabel("#{OMWEngine:TestingExteriorCells} (" + std::to_string(i) + "/" + std::to_string(cells.getExtSize()) + ")..."); - CellStore& cell = mWorld.getWorldModel().getExterior(it->mData.mX, it->mData.mY); + CellStore& cell + = mWorld.getWorldModel().getExterior(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId); mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), navigatorUpdateGuard.get()); const osg::Vec3f position @@ -1177,7 +1179,8 @@ namespace MWWorld + mPreloadDistance; if (dist < loadDist) - preloadCell(mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy)); + preloadCell( + mWorld.getWorldModel().getExterior(cellX + dx, cellY + dy, ESM::Cell::sDefaultWorldspaceId)); } } } @@ -1194,7 +1197,8 @@ namespace MWWorld for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy) { mPreloader->preload( - mWorld.getWorldModel().getExterior(x + dx, y + dy), mRendering.getReferenceTime()); + mWorld.getWorldModel().getExterior(x + dx, y + dy, cell.getCell()->getWorldSpace()), + mRendering.getReferenceTime()); if (++numpreloaded >= mPreloader->getMaxCacheSize()) break; } @@ -1277,7 +1281,9 @@ namespace MWWorld { osg::Vec3f pos = dest.mPos.asVec3(); const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y()); - preloadCell(mWorld.getWorldModel().getExterior(cellIndex.x(), cellIndex.y()), true); + preloadCell( + mWorld.getWorldModel().getExterior(cellIndex.x(), cellIndex.y(), ESM::Cell::sDefaultWorldspaceId), + true); exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos))); } } diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 9936b1e999..95cf1bca22 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -1104,10 +1105,32 @@ namespace MWWorld return foundCell->second; } + const ESM4::Cell* Store::searchExterior(int x, int y, ESM::RefId worldSpace) const + { + const auto foundWorldSpace = mExteriors.find(worldSpace); + if (foundWorldSpace == mExteriors.end()) + { + return nullptr; + } + const auto foundCell = foundWorldSpace->second.find(std::make_pair(x, y)); + if (foundCell == foundWorldSpace->second.end()) + return nullptr; + return foundCell->second; + } + + bool Store::exteriorExists(ESM::RefId worldspace) const + { + const auto foundWorldSpace = mExteriors.find(worldspace); + return (foundWorldSpace != mExteriors.end()); + } + ESM4::Cell* Store::insert(const ESM4::Cell& item, bool overrideOnly) { auto cellPtr = TypedDynamicStore::insert(item, overrideOnly); mCellNameIndex[cellPtr->mEditorId] = cellPtr; + if (cellPtr->isExterior()) + mExteriors[cellPtr->mParent][std::make_pair(cellPtr->getGridX(), cellPtr->getGridY())] = cellPtr; + return cellPtr; } @@ -1115,6 +1138,9 @@ namespace MWWorld { auto cellPtr = TypedDynamicStore::insertStatic(item); mCellNameIndex[cellPtr->mEditorId] = cellPtr; + if (cellPtr->isExterior()) + mExteriors[cellPtr->mParent][std::make_pair(cellPtr->getGridX(), cellPtr->getGridY())] = cellPtr; + return cellPtr; } } @@ -1177,3 +1203,4 @@ template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; template class MWWorld::TypedDynamicStore; +template class MWWorld::TypedDynamicStore; diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 79bd4df536..95591d67b8 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -282,9 +282,12 @@ namespace MWWorld { std::unordered_map mCellNameIndex; + std::unordered_map, ESM4::Cell*>> mExteriors; public: const ESM4::Cell* searchCellName(std::string_view) const; + const ESM4::Cell* searchExterior(int x, int y, ESM::RefId worldSpace) const; + bool exteriorExists(ESM::RefId worldspace) const; ESM4::Cell* insert(const ESM4::Cell& item, bool overrideOnly = false); ESM4::Cell* insertStatic(const ESM4::Cell& item); }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 8c13a9a4c0..b5ab3f2b4b 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1266,7 +1266,9 @@ namespace MWWorld const osg::Vec2i index = positionToCellIndex(position.x(), position.y()); CellStore* cell = ptr.getCell(); - CellStore& newCell = mWorldModel.getExterior(index.x(), index.y()); + ESM::RefId worldspaceId + = cell->isExterior() ? cell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; + CellStore& newCell = mWorldModel.getExterior(index.x(), index.y(), worldspaceId); bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() && mWorldScene->isCellActive(newCell); @@ -2069,7 +2071,7 @@ namespace MWWorld if (cell->isExterior()) { const osg::Vec2i index = positionToCellIndex(pos.pos[0], pos.pos[1]); - cell = &mWorldModel.getExterior(index.x(), index.y()); + cell = &mWorldModel.getExterior(index.x(), index.y(), cell->getCell()->getWorldSpace()); } MWWorld::Ptr dropped = object.getClass().copyToCell(object, *cell, pos, count); @@ -2753,7 +2755,7 @@ namespace MWWorld if (xResult.ec == std::errc::result_out_of_range || yResult.ec == std::errc::result_out_of_range) throw std::runtime_error("Cell coordinates out of range."); else if (xResult.ec == std::errc{} && yResult.ec == std::errc{}) - ext = mWorldModel.getExterior(x, y).getCell(); + ext = mWorldModel.getExterior(x, y, ESM::Cell::sDefaultWorldspaceId).getCell(); // ignore std::errc::invalid_argument, as this means that name probably refers to a interior cell // instead of comma separated coordinates } diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 58f47eb8aa..ecc3a97cd3 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -76,11 +76,12 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellStore(const ESM::Cell* cell) } else { + auto& Esm3Exteriors = mExteriors[ESM::Cell::sDefaultWorldspaceId]; std::map, CellStore*>::iterator result - = mExteriors.find(std::make_pair(cell->getGridX(), cell->getGridY())); + = Esm3Exteriors.find(std::make_pair(cell->getGridX(), cell->getGridY())); - if (result == mExteriors.end()) - result = mExteriors.emplace(std::make_pair(cell->getGridX(), cell->getGridY()), cellStore).first; + if (result == Esm3Exteriors.end()) + result = Esm3Exteriors.emplace(std::make_pair(cell->getGridX(), cell->getGridY()), cellStore).first; return *result->second; } @@ -160,31 +161,69 @@ MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCach { } -MWWorld::CellStore& MWWorld::WorldModel::getExterior(int x, int y) +MWWorld::CellStore& MWWorld::WorldModel::getExterior(int x, int y, ESM::RefId exteriorWorldspace) { - std::map, CellStore*>::iterator result = mExteriors.find(std::make_pair(x, y)); - - if (result == mExteriors.end()) + auto foundWorldspace = mExteriors.find(exteriorWorldspace); + std::map, CellStore*>::iterator result; + if (exteriorWorldspace == ESM::Cell::sDefaultWorldspaceId) { - const ESM::Cell* cell = mStore.get().search(x, y); + auto& esm3Exteriors = mExteriors[exteriorWorldspace]; + result = esm3Exteriors.find(std::make_pair(x, y)); - if (!cell) + if (result == esm3Exteriors.end()) { - // Cell isn't predefined. Make one on the fly. - ESM::Cell record; - record.mData.mFlags = ESM::Cell::HasWater; - record.mData.mX = x; - record.mData.mY = y; - record.mWater = 0; - record.mMapColor = 0; - record.updateId(); + const ESM::Cell* cell = mStore.get().search(x, y); - cell = MWBase::Environment::get().getESMStore()->insert(record); + if (!cell) + { + // Cell isn't predefined. Make one on the fly. + ESM::Cell record; + record.mData.mFlags = ESM::Cell::HasWater; + record.mData.mX = x; + record.mData.mY = y; + record.mWater = 0; + record.mMapColor = 0; + record.updateId(); + + cell = MWBase::Environment::get().getESMStore()->insert(record); + } + + CellStore* cellStore + = &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second; + result = esm3Exteriors.emplace(std::make_pair(x, y), cellStore).first; } + } + else + { + const Store& cell4Store = mStore.get(); + if (cell4Store.exteriorExists(exteriorWorldspace)) + { + auto& exteriors = mExteriors[exteriorWorldspace]; - CellStore* cellStore - = &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second; - result = mExteriors.emplace(std::make_pair(x, y), cellStore).first; + result = exteriors.find(std::make_pair(x, y)); + + if (result == exteriors.end()) + { + const ESM4::Cell* cell = cell4Store.searchExterior(x, y, exteriorWorldspace); + if (!cell) + { + ESM4::Cell record; + record.mId = MWBase::Environment::get().getESMStore()->generateId(); + record.mParent = exteriorWorldspace; + record.mX = x; + record.mY = y; + record.mCellFlags = !ESM4::CELL_Interior; + cell = MWBase::Environment::get().getESMStore()->insert(record); + } + CellStore* cellStore + = &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second; + result = exteriors.emplace(std::make_pair(x, y), cellStore).first; + } + } + else + { + throw std::runtime_error("exterior not found: '" + exteriorWorldspace.toDebugString() + "'"); + } } if (result->second->getState() != CellStore::State_Loaded) @@ -232,7 +271,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id) return result->second; if (const auto* exteriorId = id.getIf()) - return getExterior(exteriorId->getX(), exteriorId->getY()); + return getExterior(exteriorId->getX(), exteriorId->getY(), ESM::Cell::sDefaultWorldspaceId); const ESM4::Cell* cell4 = mStore.get().search(id); CellStore* newCellStore = nullptr; @@ -249,7 +288,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id) { std::pair coord = std::make_pair(newCellStore->getCell()->getGridX(), newCellStore->getCell()->getGridY()); - mExteriors.emplace(coord, newCellStore); + mExteriors[newCellStore->getCell()->getWorldSpace()].emplace(coord, newCellStore); } else { @@ -293,7 +332,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(std::string_view name) if (!cell) throw std::runtime_error(std::string("Can't find cell with name ") + std::string(name)); - return getExterior(cell->getGridX(), cell->getGridY()); + return getExterior(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId); } MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition( @@ -302,7 +341,9 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition( if (cellInSameWorldSpace && !cellInSameWorldSpace->isExterior()) return *cellInSameWorldSpace; const osg::Vec2i cellIndex = positionToCellIndex(pos.x(), pos.y()); - return getExterior(cellIndex.x(), cellIndex.y()); + ESM::RefId exteriorWorldspace + = cellInSameWorldSpace ? cellInSameWorldSpace->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; + return getExterior(cellIndex.x(), cellIndex.y(), exteriorWorldspace); } MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name, CellStore& cell) @@ -342,12 +383,14 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name) // Then check cells that are already listed // Search in reverse, 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. - for (std::map, CellStore*>::reverse_iterator iter = mExteriors.rbegin(); - iter != mExteriors.rend(); ++iter) + for (auto iterExt = mExteriors.rbegin(); iterExt != mExteriors.rend(); ++iterExt) { - Ptr ptr = getPtrAndCache(name, *iter->second); - if (!ptr.isEmpty()) - return ptr; + for (auto iter = iterExt->second.rbegin(); iter != iterExt->second.rend(); iter++) + { + Ptr ptr = getPtrAndCache(name, *iter->second); + if (!ptr.isEmpty()) + return ptr; + } } for (auto iter = mInteriors.begin(); iter != mInteriors.end(); ++iter) diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index c9c7cf52ea..464cc89d18 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -42,7 +42,7 @@ namespace MWWorld ESM::ReadersCache& mReaders; mutable std::unordered_map mCells; mutable std::map mInteriors; - mutable std::map, CellStore*> mExteriors; + mutable std::map, CellStore*>> mExteriors; IdCache mIdCache; std::size_t mIdCacheIndex = 0; std::unordered_map mPtrIndex; @@ -63,7 +63,7 @@ namespace MWWorld void clear(); - CellStore& getExterior(int x, int y); + CellStore& getExterior(int x, int y, ESM::RefId exteriorWorldSpace); CellStore& getInterior(std::string_view name); CellStore& getCell(std::string_view name); // interior or named exterior CellStore& getCell(const ESM::RefId& Id); diff --git a/components/esm3/loadcell.cpp b/components/esm3/loadcell.cpp index 73fd8967bd..6bfb0fe8a1 100644 --- a/components/esm3/loadcell.cpp +++ b/components/esm3/loadcell.cpp @@ -40,6 +40,7 @@ namespace ESM namespace ESM { const std::string Cell::sDefaultWorldspace = "sys::default"; + const RefId Cell::sDefaultWorldspaceId = ESM::RefId::stringRefId(Cell::sDefaultWorldspace); // Some overloaded compare operators. bool operator==(const MovedCellRef& ref, const RefNum& refNum) diff --git a/components/esm3/loadcell.hpp b/components/esm3/loadcell.hpp index c889a5a620..c5794aa5a2 100644 --- a/components/esm3/loadcell.hpp +++ b/components/esm3/loadcell.hpp @@ -67,6 +67,7 @@ namespace ESM struct Cell { static const std::string sDefaultWorldspace; + static const ESM::RefId sDefaultWorldspaceId; constexpr static RecNameInts sRecordId = REC_CELL; diff --git a/components/esm4/loadwrld.cpp b/components/esm4/loadwrld.cpp index f421a8e7ff..cc16ab4fa7 100644 --- a/components/esm4/loadwrld.cpp +++ b/components/esm4/loadwrld.cpp @@ -34,8 +34,8 @@ void ESM4::World::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + FormId formid = reader.hdr().record.getFormId(); + reader.adjustFormId(formid); mFlags = reader.hdr().record.flags; // It should be possible to save the current world formId automatically while reading in @@ -45,7 +45,8 @@ void ESM4::World::load(ESM4::Reader& reader) // Alternatively it may be possible to figure it out by examining the group headers, but // apparently the label field is not reliable so the parent world formid may have been // corrupted by the use of ignore flag (TODO: should check to verify). - reader.setCurrWorld(mFormId); // save for CELL later + reader.setCurrWorld(formid); // save for CELL later + mId = ESM::FormIdRefId(formid); std::uint32_t subSize = 0; // for XXXX sub record diff --git a/components/esm4/loadwrld.hpp b/components/esm4/loadwrld.hpp index f5ba010ba8..7dc42cd035 100644 --- a/components/esm4/loadwrld.hpp +++ b/components/esm4/loadwrld.hpp @@ -34,6 +34,9 @@ #include "formid.hpp" #include "grid.hpp" +#include +#include + namespace ESM4 { class Reader; @@ -81,7 +84,7 @@ namespace ESM4 float initialPitch; }; - FormId mFormId; // from the header + ESM::RefId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -129,6 +132,7 @@ namespace ESM4 void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; + static constexpr ESM::RecNameInts sRecordId = ESM::REC_WRLD4; }; }