diff --git a/apps/essimporter/convertplayer.cpp b/apps/essimporter/convertplayer.cpp index 855a473e08..f4238a135b 100644 --- a/apps/essimporter/convertplayer.cpp +++ b/apps/essimporter/convertplayer.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -60,20 +61,19 @@ namespace ESSImport const PCDT::PNAM::MarkLocation& mark = pcdt.mPNAM.mMarkLocation; - ESM::CellId cell; - cell.mPaged = true; - - cell.mIndex.mX = mark.mCellX; - cell.mIndex.mY = mark.mCellY; + ESM::RefId cell; // TODO: Figure out a better way to detect interiors. (0, 0) is a valid exterior cell. if (mark.mCellX == 0 && mark.mCellY == 0) { - cell.mWorldspace = pcdt.mMNAM; - cell.mPaged = false; + cell = ESM::RefId::stringRefId(pcdt.mMNAM); + } + else + { + cell = ESM::Cell::generateIdForExteriorCell(mark.mCellX, mark.mCellY); } - out.mMarkedCell = cell.getCellRefId(); + out.mMarkedCell = cell; out.mMarkedPosition.pos[0] = mark.mX; out.mMarkedPosition.pos[1] = mark.mY; out.mMarkedPosition.pos[2] = mark.mZ; diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index 38ebf41596..76548d16ee 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -419,8 +419,13 @@ namespace ESSImport = static_cast(std::floor(context.mPlayer.mObject.mPosition.pos[1] / Constants::CellSizeInUnits)); cellId.mIndex.mX = cellX; cellId.mIndex.mY = cellY; + + context.mPlayer.mCellId = ESM::Cell::generateIdForExteriorCell(cellX, cellY); + } + else + { + context.mPlayer.mCellId = ESM::RefId::stringRefId(cellId.mWorldspace); } - context.mPlayer.mCellId = cellId.getCellRefId(); context.mPlayer.save(writer); writer.endRecord(ESM::REC_PLAY); diff --git a/apps/essimporter/importercontext.hpp b/apps/essimporter/importercontext.hpp index 9e5d9c0006..788946b762 100644 --- a/apps/essimporter/importercontext.hpp +++ b/apps/essimporter/importercontext.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -59,10 +60,7 @@ namespace ESSImport , mHour(0.f) , mNextActorId(0) { - ESM::CellId playerCellId; - playerCellId.mPaged = true; - playerCellId.mIndex.mX = playerCellId.mIndex.mY = 0; - mPlayer.mCellId = playerCellId.getCellRefId(); + mPlayer.mCellId = ESM::Cell::generateIdForExteriorCell(0, 0); mPlayer.mLastKnownExteriorPosition[0] = mPlayer.mLastKnownExteriorPosition[1] = mPlayer.mLastKnownExteriorPosition[2] = 0.0f; mPlayer.mHasMark = 0; diff --git a/apps/navmeshtool/worldspacedata.cpp b/apps/navmeshtool/worldspacedata.cpp index fd66a46f4c..3de8d2395f 100644 --- a/apps/navmeshtool/worldspacedata.cpp +++ b/apps/navmeshtool/worldspacedata.cpp @@ -264,7 +264,7 @@ namespace NavMeshTool const osg::Vec2i cellPosition(cell.mData.mX, cell.mData.mY); const std::size_t cellObjectsBegin = data.mObjects.size(); const auto cellNameLowerCase - = Misc::StringUtils::lowerCase(cell.isExterior() ? ESM::CellId::sDefaultWorldspace : cell.mName); + = Misc::StringUtils::lowerCase(cell.isExterior() ? ESM::Cell::sDefaultWorldspace : cell.mName); WorldspaceNavMeshInput& navMeshInput = [&]() -> WorldspaceNavMeshInput& { auto it = navMeshInputs.find(cellNameLowerCase); if (it == navMeshInputs.end()) diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 4ec9c301f1..23e772afcd 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include "collectionbase.hpp" @@ -337,7 +337,7 @@ std::pair CSMWorld::IdTable::view(int row) c return std::make_pair(UniversalId::Type_None, ""); if (id[0] == '#') - id = ESM::CellId::sDefaultWorldspace; + id = ESM::Cell::sDefaultWorldspace; return std::make_pair(UniversalId(UniversalId::Type_Scene, id), hint); } diff --git a/apps/opencs/view/world/regionmap.cpp b/apps/opencs/view/world/regionmap.cpp index df5418ba76..4f4a2c6a2b 100644 --- a/apps/opencs/view/world/regionmap.cpp +++ b/apps/opencs/view/world/regionmap.cpp @@ -307,7 +307,7 @@ void CSVWorld::RegionMap::view() } emit editRequest( - CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::CellId::sDefaultWorldspace), hint.str()); + CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::Cell::sDefaultWorldspace), hint.str()); } void CSVWorld::RegionMap::viewInTable() diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index ed2820c542..26127bb961 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -49,7 +49,7 @@ CSVWorld::SceneSubView::SceneSubView(const CSMWorld::UniversalId& id, CSMDoc::Do CSVRender::WorldspaceWidget* worldspaceWidget = nullptr; widgetType whatWidget; - if (Misc::StringUtils::ciEqual(id.getId(), ESM::CellId::sDefaultWorldspace)) + if (Misc::StringUtils::ciEqual(id.getId(), ESM::Cell::sDefaultWorldspace)) { whatWidget = widget_Paged; @@ -170,7 +170,7 @@ void CSVWorld::SceneSubView::cellSelectionChanged(const CSMWorld::UniversalId& i void CSVWorld::SceneSubView::cellSelectionChanged(const CSMWorld::CellSelection& selection) { - setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::CellId::sDefaultWorldspace)); + setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Scene, ESM::Cell::sDefaultWorldspace)); int size = selection.getSize(); std::ostringstream stream; diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 733a564db5..1118fce014 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -351,12 +351,17 @@ namespace MWGui { for (int dY = -mCellDistance; dY <= mCellDistance; ++dY) { - ESM::CellId cellId; - cellId.mPaged = !mInterior; - cellId.mWorldspace = (mInterior ? mPrefix : ESM::CellId::sDefaultWorldspace); - cellId.mIndex.mX = mCurX + dX; - cellId.mIndex.mY = mCurY + dY; - ESM::RefId cellRefId = cellId.getCellRefId(); + ESM::RefId cellRefId; + + if (mInterior) + { + cellRefId = ESM::RefId::stringRefId(mPrefix); + } + else + { + cellRefId = ESM::Cell::generateIdForExteriorCell(mCurX + dX, mCurY + dY); + } + CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(cellRefId); for (CustomMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second; ++it) @@ -885,18 +890,17 @@ namespace MWGui mEditingMarker.mWorldX = worldPos.x(); mEditingMarker.mWorldY = worldPos.y(); - ESM::CellId clickedId; + ESM::RefId clickedId; - clickedId.mPaged = !mInterior; if (mInterior) - clickedId.mWorldspace = LocalMapBase::mPrefix; + { + clickedId = ESM::RefId::stringRefId(LocalMapBase::mPrefix); + } else { - clickedId.mWorldspace = ESM::CellId::sDefaultWorldspace; - clickedId.mIndex.mX = x; - clickedId.mIndex.mY = y; + clickedId = ESM::Cell::generateIdForExteriorCell(x, y); } - mEditingMarker.mCell = clickedId.getCellRefId(); + mEditingMarker.mCell = clickedId; mEditNoteDialog.setVisible(true); mEditNoteDialog.showDeleteButton(false); @@ -1122,12 +1126,7 @@ namespace MWGui void MapWindow::setGlobalMapMarkerTooltip(MyGUI::Widget* markerWidget, int x, int y) { - ESM::CellId cellId; - cellId.mIndex.mX = x; - cellId.mIndex.mY = y; - cellId.mWorldspace = ESM::CellId::sDefaultWorldspace; - cellId.mPaged = true; - ESM::RefId cellRefId = cellId.getCellRefId(); + ESM::RefId cellRefId = ESM::Cell::generateIdForExteriorCell(x, y); CustomMarkerCollection::RangeType markers = mCustomMarkers.getMarkers(cellRefId); std::vector destNotes; for (CustomMarkerCollection::ContainerType::const_iterator it = markers.first; it != markers.second; ++it) diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 7798bf7105..1a70954194 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -195,15 +195,19 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); - ESM::CellId cellId; + ESM::RefId cellId; osg::Vec2i posCell = MWWorld::positionToCellIndex(pos.pos[0], pos.pos[1]); - cellId.mPaged = !interior; - cellId.mWorldspace = Misc::StringUtils::lowerCase(cellname); - cellId.mIndex.mX = posCell.x(); - cellId.mIndex.mY = posCell.y(); + if (interior) + { + cellId = ESM::RefId::stringRefId(cellname); + } + else + { + cellId = ESM::Cell::generateIdForExteriorCell(posCell.x(), posCell.y()); + } // Teleports any followers, too. - MWWorld::ActionTeleport action(cellId.getCellRefId(), pos, true); + MWWorld::ActionTeleport action(cellId, pos, true); action.execute(player); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0); diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index 7680090410..6aecbb827a 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -40,7 +40,7 @@ namespace MWWorld , mNameID(cell.mName) , mRegion(cell.mRegion) , mId(cell.mId) - , mParent(ESM::RefId::stringRefId(ESM::CellId::sDefaultWorldspace)) + , mParent(ESM::RefId::stringRefId(ESM::Cell::sDefaultWorldspace)) , mMood{ .mAmbiantColor = cell.mAmbi.mAmbient, .mDirectionalColor = cell.mAmbi.mSunlight, diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index 49d21f4b0e..cdfc211124 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -90,11 +90,7 @@ namespace MWWorld else { const osg::Vec2i index = positionToCellIndex(ref.mDoorDest.pos[0], ref.mDoorDest.pos[1]); - ESM::CellId cellId; - cellId.mPaged = true; - cellId.mIndex.mX = index.x(); - cellId.mIndex.mY = index.y(); - return cellId.getCellRefId(); + return ESM::Cell::generateIdForExteriorCell(index.x(), index.y()); } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7515404037..163cf624f9 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -380,10 +380,8 @@ namespace MWWorld pos.rot[2] = 0; osg::Vec2i exteriorCellPos = positionToCellIndex(pos.pos[0], pos.pos[1]); - ESM::CellId cellId; - cellId.mPaged = true; - cellId.mIndex = { exteriorCellPos.x(), exteriorCellPos.y() }; - mWorldScene->changeToExteriorCell(cellId.getCellRefId(), pos, true); + ESM::RefId cellId = ESM::Cell::generateIdForExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); + mWorldScene->changeToExteriorCell(cellId, pos, true); } } @@ -979,7 +977,7 @@ namespace MWWorld mPhysics->clearQueuedMovement(); mDiscardMovements = true; - if (changeEvent && mCurrentWorldSpace != ESM::CellId::sDefaultWorldspace) + if (changeEvent && mCurrentWorldSpace != ESM::Cell::sDefaultWorldspace) { // changed worldspace mProjectileManager->clear(); @@ -987,10 +985,8 @@ namespace MWWorld } removeContainerScripts(getPlayerPtr()); osg::Vec2i exteriorCellPos = positionToCellIndex(position.pos[0], position.pos[1]); - ESM::CellId cellId; - cellId.mPaged = true; - cellId.mIndex = { exteriorCellPos.x(), exteriorCellPos.y() }; - mWorldScene->changeToExteriorCell(cellId.getCellRefId(), position, adjustPlayerPos, changeEvent); + ESM::RefId cellId = ESM::Cell::generateIdForExteriorCell(exteriorCellPos.x(), exteriorCellPos.y()); + mWorldScene->changeToExteriorCell(cellId, position, adjustPlayerPos, changeEvent); addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell()); mRendering->getCamera()->instantTransition(); } diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index 36999e633c..1b89e79f54 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -448,10 +448,7 @@ namespace refId = RecordType::indexToRefId(index); else if constexpr (std::is_same_v) { - ESM::CellId cellId; - cellId.mPaged = true; - cellId.mIndex = { 0, 0 }; - refId = cellId.getCellRefId(); + refId = ESM::Cell::generateIdForExteriorCell(0, 0); } else refId = ESM::StringRefId(stringId); diff --git a/components/esm3/cellid.cpp b/components/esm3/cellid.cpp index c295084a91..25dd7bfc55 100644 --- a/components/esm3/cellid.cpp +++ b/components/esm3/cellid.cpp @@ -7,8 +7,6 @@ namespace ESM { - const std::string CellId::sDefaultWorldspace = "sys::default"; - void CellId::load(ESMReader& esm) { mWorldspace = esm.getHNString("SPAC"); @@ -34,18 +32,6 @@ namespace ESM esm.writeHNT("CIDX", mIndex, 8); } - ESM::RefId CellId::getCellRefId() const - { - if (mPaged) - { - return ESM::RefId::stringRefId("#" + std::to_string(mIndex.mX) + "," + std::to_string(mIndex.mY)); - } - else - { - return ESM::RefId::stringRefId(mWorldspace); - } - } - CellId CellId::extractFromRefId(const ESM::RefId& id) { // This is bad and that code should not be merged. diff --git a/components/esm3/cellid.hpp b/components/esm3/cellid.hpp index 0b27425e35..eeedc5f554 100644 --- a/components/esm3/cellid.hpp +++ b/components/esm3/cellid.hpp @@ -21,11 +21,8 @@ namespace ESM CellIndex mIndex; bool mPaged; - static const std::string sDefaultWorldspace; - void load(ESMReader& esm); void save(ESMWriter& esm) const; - ESM::RefId getCellRefId() const; // TODO tetramir: this probably shouldn't exist, needs it because some CellIds are saved on disk static CellId extractFromRefId(const ESM::RefId& id); diff --git a/components/esm3/esmreader.cpp b/components/esm3/esmreader.cpp index 2cb5322059..2797ee83e4 100644 --- a/components/esm3/esmreader.cpp +++ b/components/esm3/esmreader.cpp @@ -4,6 +4,7 @@ #include "savedgame.hpp" #include +#include #include #include #include @@ -93,7 +94,14 @@ namespace ESM { ESM::CellId cellId; cellId.load(*this); - return cellId.getCellRefId(); + if (cellId.mPaged) + { + return ESM::Cell::generateIdForExteriorCell(cellId.mIndex.mX, cellId.mIndex.mY); + } + else + { + return ESM::RefId::stringRefId(cellId.mWorldspace); + } } return getHNRefId("NAME"); } diff --git a/components/esm3/loadcell.cpp b/components/esm3/loadcell.cpp index 6db783d5c6..0f18e80a9d 100644 --- a/components/esm3/loadcell.cpp +++ b/components/esm3/loadcell.cpp @@ -40,6 +40,8 @@ namespace ESM namespace ESM { + const std::string Cell::sDefaultWorldspace = "sys::default"; + // Some overloaded compare operators. bool operator==(const MovedCellRef& ref, const RefNum& refNum) { @@ -59,26 +61,23 @@ namespace ESM const ESM::RefId& Cell::updateId() { - CellId cellid; - - cellid.mPaged = !(mData.mFlags & Interior); - if (cellid.mPaged) + if (mData.mFlags & Interior) { - cellid.mWorldspace = CellId::sDefaultWorldspace; - cellid.mIndex.mX = mData.mX; - cellid.mIndex.mY = mData.mY; + mId = ESM::RefId::stringRefId(mName); } else { - cellid.mWorldspace = Misc::StringUtils::lowerCase(mName); - cellid.mIndex.mX = 0; - cellid.mIndex.mY = 0; + mId = generateIdForExteriorCell(getGridX(), getGridY()); } - mId = cellid.getCellRefId(); return mId; } + ESM::RefId Cell::generateIdForExteriorCell(int x, int y) + { + return ESM::RefId::stringRefId("#" + std::to_string(x) + "," + std::to_string(y)); + } + void Cell::loadNameAndData(ESMReader& esm, bool& isDeleted) { isDeleted = false; diff --git a/components/esm3/loadcell.hpp b/components/esm3/loadcell.hpp index d59186b6f0..f35077b509 100644 --- a/components/esm3/loadcell.hpp +++ b/components/esm3/loadcell.hpp @@ -67,6 +67,8 @@ namespace ESM */ struct Cell { + static const std::string sDefaultWorldspace; + constexpr static RecNameInts sRecordId = REC_CELL; /// Return a string descriptor for this record type. Currently used for debugging / error logs only. @@ -191,6 +193,8 @@ namespace ESM ///< Set record to default state (does not touch the ID/index). const ESM::RefId& updateId(); + + static ESM::RefId generateIdForExteriorCell(int x, int y); }; } #endif