From a3bd6e7e47fa8291c1e9a848930177fcde60ffde Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Fri, 12 May 2023 13:24:59 +0200 Subject: [PATCH] ESM::ExteriorCellIndex => ESM::ExteriorCellLocation --- apps/openmw/mwbase/world.hpp | 2 +- apps/openmw/mwgui/mapwindow.cpp | 6 ++-- apps/openmw/mwgui/travelwindow.cpp | 4 +-- apps/openmw/mwlua/luabindings.cpp | 2 +- apps/openmw/mwphysics/physicssystem.cpp | 2 +- apps/openmw/mwphysics/physicssystem.hpp | 2 +- apps/openmw/mwrender/landmanager.cpp | 2 +- apps/openmw/mwrender/landmanager.hpp | 2 +- apps/openmw/mwrender/terrainstorage.cpp | 2 +- apps/openmw/mwscript/cellextensions.cpp | 2 +- .../mwscript/transformationextensions.cpp | 8 ++--- apps/openmw/mwstate/statemanagerimp.cpp | 2 +- apps/openmw/mwworld/cellpreloader.cpp | 2 +- apps/openmw/mwworld/scene.cpp | 30 +++++++++---------- apps/openmw/mwworld/scene.hpp | 4 +-- apps/openmw/mwworld/store.cpp | 4 +-- apps/openmw/mwworld/store.hpp | 6 ++-- apps/openmw/mwworld/worldimp.cpp | 10 +++---- apps/openmw/mwworld/worldmodel.cpp | 16 +++++----- apps/openmw/mwworld/worldmodel.hpp | 4 +-- components/esm/util.cpp | 2 +- components/esm/util.hpp | 16 +++++----- 22 files changed, 64 insertions(+), 66 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 963a22d065..31a93e9201 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -55,7 +55,7 @@ namespace ESM struct ItemLevList; struct TimeStamp; class RefId; - struct ExteriorCellIndex; + struct ExteriorCellLocation; } namespace MWPhysics diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index 691d096450..f3d3b346e4 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -276,7 +276,7 @@ namespace MWGui if (!mInterior) { - ESM::ExteriorCellIndex cellPos = ESM::positionToCellIndex(worldX, worldY); + ESM::ExteriorCellLocation cellPos = ESM::positionToCellIndex(worldX, worldY); cellIndex.x() = cellPos.mX; cellIndex.y() = cellPos.mY; @@ -586,7 +586,7 @@ namespace MWGui { if (!mInterior) requestMapRender(&MWBase::Environment::get().getWorldModel()->getExterior( - ESM::ExteriorCellIndex(entry.mCellX, entry.mCellY, ESM::Cell::sDefaultWorldspaceId))); + ESM::ExteriorCellLocation(entry.mCellX, entry.mCellY, ESM::Cell::sDefaultWorldspaceId))); osg::ref_ptr texture = mLocalMapRender->getMapTexture(entry.mCellX, entry.mCellY); if (texture) @@ -643,7 +643,7 @@ namespace MWGui for (MapEntry& entry : mMaps) { if (!entry.mMapTexture && !widgetCropped(entry.mMapWidget, mLocalMap)) - world->getDoorMarkers(worldModel->getExterior(ESM::ExteriorCellIndex( + world->getDoorMarkers(worldModel->getExterior(ESM::ExteriorCellLocation( entry.mCellX, entry.mCellY, ESM::Cell::sDefaultWorldspaceId)), doors); } diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 4ad90547b5..e5f840874d 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -125,7 +125,7 @@ namespace MWGui { std::string_view cellname = transport[i].mCellName; bool interior = true; - const ESM::ExteriorCellIndex cellIndex + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); if (cellname.empty()) { @@ -192,7 +192,7 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); - const ESM::ExteriorCellIndex posCell = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); + const ESM::ExteriorCellLocation posCell = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); ESM::RefId cellId = ESM::Cell::generateIdForCell(!interior, cellname, posCell.mX, posCell.mY); // Teleports any followers, too. diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index b1c762440c..0084c4a901 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -115,7 +115,7 @@ namespace MWLua = [](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( - ESM::ExteriorCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId)) }; + ESM::ExteriorCellLocation(x, y, ESM::Cell::sDefaultWorldspaceId)) }; }; api["activeActors"] = GObjectList{ worldView->getActorsInScene() }; api["createObject"] = [](std::string_view recordId, sol::optional count) -> GObject { diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index dbc31fccb1..1c37ac029e 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -483,7 +483,7 @@ namespace MWPhysics mHeightFields.erase(heightfield); } - const HeightField* PhysicsSystem::getHeightField(ESM::ExteriorCellIndex cellIndex) const + const HeightField* PhysicsSystem::getHeightField(ESM::ExteriorCellLocation cellIndex) const { if (ESM::isEsm4Ext(cellIndex.mWorldspace)) return nullptr; diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index 1e1d7bdb61..32899dd711 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -190,7 +190,7 @@ namespace MWPhysics void removeHeightField(int x, int y); - const HeightField* getHeightField(ESM::ExteriorCellIndex cellIndex) const; + const HeightField* getHeightField(ESM::ExteriorCellLocation cellIndex) const; bool toggleCollisionMode(); diff --git a/apps/openmw/mwrender/landmanager.cpp b/apps/openmw/mwrender/landmanager.cpp index a3248d21a7..e7a647f348 100644 --- a/apps/openmw/mwrender/landmanager.cpp +++ b/apps/openmw/mwrender/landmanager.cpp @@ -18,7 +18,7 @@ namespace MWRender mCache = new CacheType; } - osg::ref_ptr LandManager::getLand(ESM::ExteriorCellIndex cellIndex) + osg::ref_ptr LandManager::getLand(ESM::ExteriorCellLocation cellIndex) { if (ESM::isEsm4Ext(cellIndex.mWorldspace)) return osg::ref_ptr(nullptr); diff --git a/apps/openmw/mwrender/landmanager.hpp b/apps/openmw/mwrender/landmanager.hpp index f7ebf5ddb8..1a95038eea 100644 --- a/apps/openmw/mwrender/landmanager.hpp +++ b/apps/openmw/mwrender/landmanager.hpp @@ -21,7 +21,7 @@ namespace MWRender LandManager(int loadFlags); /// @note Will return nullptr if not found. - osg::ref_ptr getLand(ESM::ExteriorCellIndex cellIndex); + osg::ref_ptr getLand(ESM::ExteriorCellLocation cellIndex); void reportStats(unsigned int frameNumber, osg::Stats* stats) const override; diff --git a/apps/openmw/mwrender/terrainstorage.cpp b/apps/openmw/mwrender/terrainstorage.cpp index b950e4fe5c..ebbe3fa18b 100644 --- a/apps/openmw/mwrender/terrainstorage.cpp +++ b/apps/openmw/mwrender/terrainstorage.cpp @@ -68,7 +68,7 @@ namespace MWRender osg::ref_ptr TerrainStorage::getLand(int cellX, int cellY) { - return mLandManager->getLand(ESM::ExteriorCellIndex(cellX, cellY, ESM::Cell::sDefaultWorldspaceId)); + return mLandManager->getLand(ESM::ExteriorCellLocation(cellX, cellY, ESM::Cell::sDefaultWorldspaceId)); } const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin) diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 041476492d..147b9a5d82 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -124,7 +124,7 @@ namespace MWScript const MWWorld::Ptr playerPtr = world->getPlayerPtr(); osg::Vec2 posFromIndex - = ESM::indexToPosition(ESM::ExteriorCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId), true); + = ESM::indexToPosition(ESM::ExteriorCellLocation(x, y, ESM::Cell::sDefaultWorldspaceId), true); pos.pos[0] = posFromIndex.x(); pos.pos[1] = posFromIndex.y(); pos.pos[2] = 0; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 4bf1f148e5..fd091711c8 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -400,7 +400,7 @@ namespace MWScript store = &worldModel->getCell(cellID); if (store->isExterior()) { - const ESM::ExteriorCellIndex cellIndex + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(x, y, store->getCell()->getWorldSpace()); store = &worldModel->getExterior(cellIndex); } @@ -416,7 +416,7 @@ namespace MWScript Log(Debug::Warning) << error; if (!isPlayer) return; - const ESM::ExteriorCellIndex cellIndex + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(x, y, store->getCell()->getWorldSpace()); store = &worldModel->getExterior(cellIndex); } @@ -467,7 +467,7 @@ namespace MWScript { world->getPlayer().setTeleported(true); } - const ESM::ExteriorCellIndex cellIndex + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId); // another morrowind oddity: player will be moved to the exterior cell at this location, @@ -568,7 +568,7 @@ namespace MWScript MWWorld::CellStore* store = nullptr; if (player.getCell()->isExterior()) { - const ESM::ExteriorCellIndex cellIndex + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(x, y, player.getCell()->getCell()->getWorldSpace()); store = &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex); } diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 796f820999..c14a221187 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -563,7 +563,7 @@ 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"; - ESM::ExteriorCellIndex cellIndex(0, 0, ESM::Cell::sDefaultWorldspaceId); + ESM::ExteriorCellLocation cellIndex(0, 0, ESM::Cell::sDefaultWorldspaceId); MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex); osg::Vec2 posFromIndex = ESM::indexToPosition(cellIndex, false); ESM::Position pos; diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 9881595123..8e5c539ae0 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -103,7 +103,7 @@ namespace MWWorld { mTerrain->cacheCell(mTerrainView.get(), mX, mY); mPreloadedObjects.insert( - mLandManager->getLand(ESM::ExteriorCellIndex(mX, mY, ESM::Cell::sDefaultWorldspaceId))); + mLandManager->getLand(ESM::ExteriorCellLocation(mX, mY, ESM::Cell::sDefaultWorldspaceId))); } catch (std::exception&) { diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 08208b93b3..1f4a7d526a 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -247,7 +247,7 @@ namespace return std::abs(cellPosition.first) + std::abs(cellPosition.second); } - bool isCellInCollection(ESM::ExteriorCellIndex cellIndex, MWWorld::Scene::CellStoreCollection& collection) + bool isCellInCollection(ESM::ExteriorCellLocation cellIndex, MWWorld::Scene::CellStoreCollection& collection) { for (auto* cell : collection) { @@ -346,7 +346,7 @@ namespace MWWorld if (cell->getCell()->isExterior()) { - if (mPhysics->getHeightField(ESM::ExteriorCellIndex(cellX, cellY, cell->getCell()->getWorldSpace())) + if (mPhysics->getHeightField(ESM::ExteriorCellLocation(cellX, cellY, cell->getCell()->getWorldSpace())) != nullptr) mNavigator.removeHeightfield(osg::Vec2i(cellX, cellY), navigatorUpdateGuard); @@ -393,7 +393,7 @@ namespace MWWorld const int cellY = cell.getCell()->getGridY(); const MWWorld::Cell& cellVariant = *cell.getCell(); ESM::RefId worldspace = cellVariant.getWorldSpace(); - ESM::ExteriorCellIndex cellIndex(cellX, cellY, worldspace); + ESM::ExteriorCellLocation cellIndex(cellX, cellY, worldspace); if (cellVariant.isExterior()) { @@ -512,19 +512,17 @@ namespace MWWorld { ESM::RefId worldspace = mCurrentCell ? mCurrentCell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; - bool isEsm4Ext = ESM::isEsm4Ext(worldspace); - if (currentGridCenter) { osg::Vec2 center = ESM::indexToPosition( - ESM::ExteriorCellIndex(currentGridCenter->x(), currentGridCenter->y(), worldspace), true); + ESM::ExteriorCellLocation(currentGridCenter->x(), currentGridCenter->y(), worldspace), true); float distance = std::max(std::abs(center.x() - pos.x()), std::abs(center.y() - pos.y())); float cellSize = ESM::getCellSize(worldspace); const float maxDistance = cellSize / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold if (distance <= maxDistance) return *currentGridCenter; } - ESM::ExteriorCellIndex cellPos = ESM::positionToCellIndex(pos.x(), pos.y(), worldspace); + ESM::ExteriorCellLocation cellPos = ESM::positionToCellIndex(pos.x(), pos.y(), worldspace); return { cellPos.mX, cellPos.mY }; } @@ -541,10 +539,10 @@ namespace MWWorld void Scene::requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent) { mChangeCellGridRequest = ChangeCellGridRequest{ position, - ESM::ExteriorCellIndex(cell.x(), cell.y(), mCurrentCell->getCell()->getWorldSpace()), changeEvent }; + ESM::ExteriorCellLocation(cell.x(), cell.y(), mCurrentCell->getCell()->getWorldSpace()), changeEvent }; } - void Scene::changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellIndex playerCellIndex, bool changeEvent) + void Scene::changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellLocation playerCellIndex, bool changeEvent) { auto navigatorUpdateGuard = mNavigator.makeUpdateGuard(); int playerCellX = playerCellIndex.mX; @@ -586,7 +584,7 @@ namespace MWWorld { for (int y = playerCellY - range; y <= playerCellY + range; ++y) { - if (!isCellInCollection(ESM::ExteriorCellIndex(x, y, playerCellIndex.mWorldspace), collection)) + if (!isCellInCollection(ESM::ExteriorCellLocation(x, y, playerCellIndex.mWorldspace), collection)) { refsToLoad += mWorld.getWorldModel().getExterior(playerCellIndex).count(); cellsPositionsToLoad.emplace_back(x, y); @@ -620,7 +618,7 @@ namespace MWWorld for (const auto& [x, y] : cellsPositionsToLoad) { - ESM::ExteriorCellIndex indexToLoad = { x, y, playerCellIndex.mWorldspace }; + ESM::ExteriorCellLocation indexToLoad = { x, y, playerCellIndex.mWorldspace }; if (!isCellInCollection(indexToLoad, mActiveCells)) { CellStore& cell = mWorld.getWorldModel().getExterior(indexToLoad); @@ -686,7 +684,7 @@ namespace MWWorld + std::to_string(cells.getExtSize()) + ")..."); CellStore& cell = mWorld.getWorldModel().getExterior( - ESM::ExteriorCellIndex(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId)); + ESM::ExteriorCellLocation(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId)); mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); const osg::Vec3f position = osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits; @@ -940,7 +938,7 @@ namespace MWWorld const osg::Vec2i cellIndex(current.getCell()->getGridX(), current.getCell()->getGridY()); changeCellGrid(position.asVec3(), - ESM::ExteriorCellIndex(cellIndex.x(), cellIndex.y(), current.getCell()->getWorldSpace()), changeEvent); + ESM::ExteriorCellLocation(cellIndex.x(), cellIndex.y(), current.getCell()->getWorldSpace()), changeEvent); changePlayerCell(current, position, adjustPlayerPos); @@ -1172,7 +1170,7 @@ namespace MWWorld if (dy != halfGridSizePlusOne && dy != -halfGridSizePlusOne && dx != halfGridSizePlusOne && dx != -halfGridSizePlusOne) continue; // only care about the outer (not yet loaded) part of the grid - ESM::ExteriorCellIndex cellIndex(cellX + dx, cellY + dy, extWorldspace); + ESM::ExteriorCellLocation cellIndex(cellX + dx, cellY + dy, extWorldspace); osg::Vec2 thisCellCenter = ESM::indexToPosition(cellIndex, true); float dist = std::max( @@ -1200,7 +1198,7 @@ namespace MWWorld for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy) { mPreloader->preload(mWorld.getWorldModel().getExterior( - ESM::ExteriorCellIndex(x + dx, y + dy, cell.getCell()->getWorldSpace())), + ESM::ExteriorCellLocation(x + dx, y + dy, cell.getCell()->getWorldSpace())), mRendering.getReferenceTime()); if (++numpreloaded >= mPreloader->getMaxCacheSize()) break; @@ -1283,7 +1281,7 @@ namespace MWWorld else { osg::Vec3f pos = dest.mPos.asVec3(); - const ESM::ExteriorCellIndex cellIndex = ESM::positionToCellIndex(pos.x(), pos.y(), extWorldspace); + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(pos.x(), pos.y(), extWorldspace); preloadCell(mWorld.getWorldModel().getExterior(cellIndex), true); exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos))); } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 3dcd33a3c0..cec284a693 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -80,7 +80,7 @@ namespace MWWorld struct ChangeCellGridRequest { osg::Vec3f mPosition; - ESM::ExteriorCellIndex mCellIndex; + ESM::ExteriorCellLocation mCellIndex; bool mChangeEvent; }; @@ -118,7 +118,7 @@ namespace MWWorld osg::Vec2i mCurrentGridCenter; // Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center - void changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellIndex playerCellIndex, bool changeEvent = true); + void changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellLocation playerCellIndex, bool changeEvent = true); void requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent = true); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 7fbbb0c695..b87cf6e445 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -1105,7 +1105,7 @@ namespace MWWorld return foundCell->second; } - const ESM4::Cell* Store::searchExterior(ESM::ExteriorCellIndex cellIndex) const + const ESM4::Cell* Store::searchExterior(ESM::ExteriorCellLocation cellIndex) const { const auto foundCell = mExteriors.find(cellIndex); if (foundCell == mExteriors.end()) @@ -1133,7 +1133,7 @@ namespace MWWorld mCellNameIndex[cellPtr->mEditorId] = cellPtr; if (cellPtr->isExterior()) { - ESM::ExteriorCellIndex cellindex = { cellPtr->mX, cellPtr->mY, cellPtr->mParent }; + ESM::ExteriorCellLocation cellindex = { cellPtr->mX, cellPtr->mY, cellPtr->mParent }; if (cellPtr->mCellFlags & ESM4::Rec_Persistent) mPersistentExteriors[cellindex] = cellPtr; else diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 45706dc793..662fc2b558 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -285,12 +285,12 @@ namespace MWWorld std::unordered_map mCellNameIndex; - std::unordered_map mExteriors; - std::unordered_map mPersistentExteriors; + std::unordered_map mExteriors; + std::unordered_map mPersistentExteriors; public: const ESM4::Cell* searchCellName(std::string_view) const; - const ESM4::Cell* searchExterior(ESM::ExteriorCellIndex cellIndex) const; + const ESM4::Cell* searchExterior(ESM::ExteriorCellLocation cellIndex) const; ESM4::Cell* insert(const ESM4::Cell& item, bool overrideOnly = false); ESM4::Cell* insertStatic(const ESM4::Cell& item); void insertCell(ESM4::Cell* cell); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index d61c1b2334..546b564d56 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -379,7 +379,7 @@ namespace MWWorld pos.rot[1] = 0; pos.rot[2] = 0; - ESM::ExteriorCellIndex exteriorCellPos = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); + ESM::ExteriorCellLocation exteriorCellPos = ESM::positionToCellIndex(pos.pos[0], pos.pos[1]); ESM::RefId cellId = ESM::RefId::esm3ExteriorCell(exteriorCellPos.mX, exteriorCellPos.mY); mWorldScene->changeToExteriorCell(cellId, pos, true); } @@ -1247,7 +1247,7 @@ namespace MWWorld CellStore* cell = ptr.getCell(); ESM::RefId worldspaceId = cell->isExterior() ? cell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; - const ESM::ExteriorCellIndex index = ESM::positionToCellIndex(position.x(), position.y(), worldspaceId); + const ESM::ExteriorCellLocation index = ESM::positionToCellIndex(position.x(), position.y(), worldspaceId); CellStore* newCell = cell->isExterior() ? &mWorldModel.getExterior(index) : nullptr; bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() @@ -2046,7 +2046,7 @@ namespace MWWorld throw std::runtime_error("copyObjectToCell(): cannot copy object to null cell"); if (cell->isExterior()) { - const ESM::ExteriorCellIndex index + const ESM::ExteriorCellLocation index = ESM::positionToCellIndex(pos.pos[0], pos.pos[1], cell->getCell()->getWorldSpace()); cell = &mWorldModel.getExterior(index); } @@ -2732,7 +2732,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(ESM::ExteriorCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId)) + ext = mWorldModel.getExterior(ESM::ExteriorCellLocation(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 @@ -2743,7 +2743,7 @@ namespace MWWorld { int x = ext->getGridX(); int y = ext->getGridY(); - osg::Vec2 posFromIndex = indexToPosition(ESM::ExteriorCellIndex(x, y, ext->getWorldSpace()), true); + osg::Vec2 posFromIndex = indexToPosition(ESM::ExteriorCellLocation(x, y, ext->getWorldSpace()), true); pos.pos[0] = posFromIndex.x(); pos.pos[1] = posFromIndex.y(); diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index dacbe63587..e9b1cf1300 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -76,8 +76,8 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellStore(const ESM::Cell* cell) } else { - ESM::ExteriorCellIndex extIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId); - std::map::iterator result = mExteriors.find(extIndex); + ESM::ExteriorCellLocation extIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId); + std::map::iterator result = mExteriors.find(extIndex); if (result == mExteriors.end()) result = mExteriors.emplace(extIndex, cellStore).first; @@ -160,9 +160,9 @@ MWWorld::WorldModel::WorldModel(const MWWorld::ESMStore& store, ESM::ReadersCach { } -MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellIndex cellIndex) +MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellLocation cellIndex) { - std::map::iterator result; + std::map::iterator result; result = mExteriors.find(cellIndex); @@ -257,7 +257,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id) if (const auto* exteriorId = id.getIf()) return getExterior( - ESM::ExteriorCellIndex(exteriorId->getX(), exteriorId->getY(), ESM::Cell::sDefaultWorldspaceId)); + ESM::ExteriorCellLocation(exteriorId->getX(), exteriorId->getY(), ESM::Cell::sDefaultWorldspaceId)); const ESM4::Cell* cell4 = mStore.get().search(id); CellStore* newCellStore = nullptr; @@ -274,7 +274,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id) { std::pair coord = std::make_pair(newCellStore->getCell()->getGridX(), newCellStore->getCell()->getGridY()); - ESM::ExteriorCellIndex extIndex = { coord.first, coord.second, newCellStore->getCell()->getWorldSpace() }; + ESM::ExteriorCellLocation extIndex = { coord.first, coord.second, newCellStore->getCell()->getWorldSpace() }; mExteriors.emplace(extIndex, newCellStore); } else @@ -319,7 +319,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(ESM::ExteriorCellIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId)); + return getExterior(ESM::ExteriorCellLocation(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId)); } MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition( @@ -329,7 +329,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition( return *cellInSameWorldSpace; ESM::RefId exteriorWorldspace = cellInSameWorldSpace ? cellInSameWorldSpace->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; - const ESM::ExteriorCellIndex cellIndex = ESM::positionToCellIndex(pos.x(), pos.y(), exteriorWorldspace); + const ESM::ExteriorCellLocation cellIndex = ESM::positionToCellIndex(pos.x(), pos.y(), exteriorWorldspace); return getExterior(cellIndex); } diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index cca916a917..b90a063c69 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -44,7 +44,7 @@ namespace MWWorld mutable std::unordered_map mCells; mutable std::map mInteriors; - mutable std::map mExteriors; + mutable std::map mExteriors; IdCache mIdCache; std::size_t mIdCacheIndex = 0; std::unordered_map mPtrIndex; @@ -65,7 +65,7 @@ namespace MWWorld void clear(); - CellStore& getExterior(ESM::ExteriorCellIndex cellIndex); + CellStore& getExterior(ESM::ExteriorCellLocation cellIndex); 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/esm/util.cpp b/components/esm/util.cpp index 514472211b..30a477641e 100644 --- a/components/esm/util.cpp +++ b/components/esm/util.cpp @@ -1,6 +1,6 @@ #include "util.hpp" -osg::Vec2 ESM::indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre) +osg::Vec2 ESM::indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre) { const int cellSize = ESM::getCellSize(cellIndex.mWorldspace); diff --git a/components/esm/util.hpp b/components/esm/util.hpp index 6a5c664ecc..6edf087854 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -49,24 +49,24 @@ namespace ESM operator osg::Vec3f() const { return osg::Vec3f(mValues[0], mValues[1], mValues[2]); } }; - struct ExteriorCellIndex + struct ExteriorCellLocation { int mX, mY; ESM::RefId mWorldspace; - ExteriorCellIndex(int x, int y, ESM::RefId worldspace) + ExteriorCellLocation(int x, int y, ESM::RefId worldspace) : mX(x) , mY(y) , mWorldspace(worldspace) { } - bool operator==(const ExteriorCellIndex& other) const + bool operator==(const ExteriorCellLocation& other) const { return mX == other.mX && mY == other.mY && mWorldspace == other.mWorldspace; } - bool operator<(const ExteriorCellIndex& other) const + bool operator<(const ExteriorCellLocation& other) const { return std::make_tuple(mX, mY, mWorldspace) < std::make_tuple(other.mX, other.mY, other.mWorldspace); } @@ -83,23 +83,23 @@ namespace ESM return isEsm4Ext(worldspaceId) ? Constants::ESM4CellSizeInUnits : Constants::CellSizeInUnits; } - inline ESM::ExteriorCellIndex positionToCellIndex( + inline ESM::ExteriorCellLocation positionToCellIndex( float x, float y, ESM::RefId worldspaceId = ESM::Cell::sDefaultWorldspaceId) { const float cellSize = getCellSize(worldspaceId); return { static_cast(std::floor(x / cellSize)), static_cast(std::floor(y / cellSize)), worldspaceId }; } - osg::Vec2 indexToPosition(const ESM::ExteriorCellIndex& cellIndex, bool centre = false); + osg::Vec2 indexToPosition(const ESM::ExteriorCellLocation& cellIndex, bool centre = false); ///< Convert cell numbers to position. } namespace std { template <> - struct hash + struct hash { - std::size_t operator()(const ESM::ExteriorCellIndex& toHash) const + std::size_t operator()(const ESM::ExteriorCellLocation& toHash) const { // Compute individual hash values for first, // second and third and combine them using XOR