1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-01 14:09:42 +00:00

ESM::ExteriorCellIndex => ESM::ExteriorCellLocation

This commit is contained in:
florent.teppe 2023-05-12 13:24:59 +02:00
parent 393357abc0
commit a3bd6e7e47
22 changed files with 64 additions and 66 deletions

View file

@ -55,7 +55,7 @@ namespace ESM
struct ItemLevList; struct ItemLevList;
struct TimeStamp; struct TimeStamp;
class RefId; class RefId;
struct ExteriorCellIndex; struct ExteriorCellLocation;
} }
namespace MWPhysics namespace MWPhysics

View file

@ -276,7 +276,7 @@ namespace MWGui
if (!mInterior) if (!mInterior)
{ {
ESM::ExteriorCellIndex cellPos = ESM::positionToCellIndex(worldX, worldY); ESM::ExteriorCellLocation cellPos = ESM::positionToCellIndex(worldX, worldY);
cellIndex.x() = cellPos.mX; cellIndex.x() = cellPos.mX;
cellIndex.y() = cellPos.mY; cellIndex.y() = cellPos.mY;
@ -586,7 +586,7 @@ namespace MWGui
{ {
if (!mInterior) if (!mInterior)
requestMapRender(&MWBase::Environment::get().getWorldModel()->getExterior( 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<osg::Texture2D> texture = mLocalMapRender->getMapTexture(entry.mCellX, entry.mCellY); osg::ref_ptr<osg::Texture2D> texture = mLocalMapRender->getMapTexture(entry.mCellX, entry.mCellY);
if (texture) if (texture)
@ -643,7 +643,7 @@ namespace MWGui
for (MapEntry& entry : mMaps) for (MapEntry& entry : mMaps)
{ {
if (!entry.mMapTexture && !widgetCropped(entry.mMapWidget, mLocalMap)) 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)), entry.mCellX, entry.mCellY, ESM::Cell::sDefaultWorldspaceId)),
doors); doors);
} }

View file

@ -125,7 +125,7 @@ namespace MWGui
{ {
std::string_view cellname = transport[i].mCellName; std::string_view cellname = transport[i].mCellName;
bool interior = true; bool interior = true;
const ESM::ExteriorCellIndex cellIndex const ESM::ExteriorCellLocation cellIndex
= ESM::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]); = ESM::positionToCellIndex(transport[i].mPos.pos[0], transport[i].mPos.pos[1]);
if (cellname.empty()) if (cellname.empty())
{ {
@ -192,7 +192,7 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode(); MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
MWBase::Environment::get().getWindowManager()->fadeScreenOut(1); 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); ESM::RefId cellId = ESM::Cell::generateIdForCell(!interior, cellname, posCell.mX, posCell.mY);
// Teleports any followers, too. // Teleports any followers, too.

View file

@ -115,7 +115,7 @@ namespace MWLua
= [](std::string_view name) { return GCell{ &MWBase::Environment::get().getWorldModel()->getCell(name) }; }; = [](std::string_view name) { return GCell{ &MWBase::Environment::get().getWorldModel()->getCell(name) }; };
api["getExteriorCell"] = [](int x, int y) { api["getExteriorCell"] = [](int x, int y) {
return GCell{ &MWBase::Environment::get().getWorldModel()->getExterior( 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["activeActors"] = GObjectList{ worldView->getActorsInScene() };
api["createObject"] = [](std::string_view recordId, sol::optional<int> count) -> GObject { api["createObject"] = [](std::string_view recordId, sol::optional<int> count) -> GObject {

View file

@ -483,7 +483,7 @@ namespace MWPhysics
mHeightFields.erase(heightfield); mHeightFields.erase(heightfield);
} }
const HeightField* PhysicsSystem::getHeightField(ESM::ExteriorCellIndex cellIndex) const const HeightField* PhysicsSystem::getHeightField(ESM::ExteriorCellLocation cellIndex) const
{ {
if (ESM::isEsm4Ext(cellIndex.mWorldspace)) if (ESM::isEsm4Ext(cellIndex.mWorldspace))
return nullptr; return nullptr;

View file

@ -190,7 +190,7 @@ namespace MWPhysics
void removeHeightField(int x, int y); void removeHeightField(int x, int y);
const HeightField* getHeightField(ESM::ExteriorCellIndex cellIndex) const; const HeightField* getHeightField(ESM::ExteriorCellLocation cellIndex) const;
bool toggleCollisionMode(); bool toggleCollisionMode();

View file

@ -18,7 +18,7 @@ namespace MWRender
mCache = new CacheType; mCache = new CacheType;
} }
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellIndex cellIndex) osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellLocation cellIndex)
{ {
if (ESM::isEsm4Ext(cellIndex.mWorldspace)) if (ESM::isEsm4Ext(cellIndex.mWorldspace))
return osg::ref_ptr<ESMTerrain::LandObject>(nullptr); return osg::ref_ptr<ESMTerrain::LandObject>(nullptr);

View file

@ -21,7 +21,7 @@ namespace MWRender
LandManager(int loadFlags); LandManager(int loadFlags);
/// @note Will return nullptr if not found. /// @note Will return nullptr if not found.
osg::ref_ptr<ESMTerrain::LandObject> getLand(ESM::ExteriorCellIndex cellIndex); osg::ref_ptr<ESMTerrain::LandObject> getLand(ESM::ExteriorCellLocation cellIndex);
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override; void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;

View file

@ -68,7 +68,7 @@ namespace MWRender
osg::ref_ptr<const ESMTerrain::LandObject> TerrainStorage::getLand(int cellX, int cellY) osg::ref_ptr<const ESMTerrain::LandObject> 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) const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)

View file

@ -124,7 +124,7 @@ namespace MWScript
const MWWorld::Ptr playerPtr = world->getPlayerPtr(); const MWWorld::Ptr playerPtr = world->getPlayerPtr();
osg::Vec2 posFromIndex 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[0] = posFromIndex.x();
pos.pos[1] = posFromIndex.y(); pos.pos[1] = posFromIndex.y();
pos.pos[2] = 0; pos.pos[2] = 0;

View file

@ -400,7 +400,7 @@ namespace MWScript
store = &worldModel->getCell(cellID); store = &worldModel->getCell(cellID);
if (store->isExterior()) if (store->isExterior())
{ {
const ESM::ExteriorCellIndex cellIndex const ESM::ExteriorCellLocation cellIndex
= ESM::positionToCellIndex(x, y, store->getCell()->getWorldSpace()); = ESM::positionToCellIndex(x, y, store->getCell()->getWorldSpace());
store = &worldModel->getExterior(cellIndex); store = &worldModel->getExterior(cellIndex);
} }
@ -416,7 +416,7 @@ namespace MWScript
Log(Debug::Warning) << error; Log(Debug::Warning) << error;
if (!isPlayer) if (!isPlayer)
return; return;
const ESM::ExteriorCellIndex cellIndex const ESM::ExteriorCellLocation cellIndex
= ESM::positionToCellIndex(x, y, store->getCell()->getWorldSpace()); = ESM::positionToCellIndex(x, y, store->getCell()->getWorldSpace());
store = &worldModel->getExterior(cellIndex); store = &worldModel->getExterior(cellIndex);
} }
@ -467,7 +467,7 @@ namespace MWScript
{ {
world->getPlayer().setTeleported(true); world->getPlayer().setTeleported(true);
} }
const ESM::ExteriorCellIndex cellIndex const ESM::ExteriorCellLocation cellIndex
= ESM::positionToCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId); = ESM::positionToCellIndex(x, y, ESM::Cell::sDefaultWorldspaceId);
// another morrowind oddity: player will be moved to the exterior cell at this location, // another morrowind oddity: player will be moved to the exterior cell at this location,
@ -568,7 +568,7 @@ namespace MWScript
MWWorld::CellStore* store = nullptr; MWWorld::CellStore* store = nullptr;
if (player.getCell()->isExterior()) if (player.getCell()->isExterior())
{ {
const ESM::ExteriorCellIndex cellIndex const ESM::ExteriorCellLocation cellIndex
= ESM::positionToCellIndex(x, y, player.getCell()->getCell()->getWorldSpace()); = ESM::positionToCellIndex(x, y, player.getCell()->getCell()->getWorldSpace());
store = &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex); store = &MWBase::Environment::get().getWorldModel()->getExterior(cellIndex);
} }

View file

@ -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 // 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"; 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); MWWorld::CellStore& cell = MWBase::Environment::get().getWorldModel()->getExterior(cellIndex);
osg::Vec2 posFromIndex = ESM::indexToPosition(cellIndex, false); osg::Vec2 posFromIndex = ESM::indexToPosition(cellIndex, false);
ESM::Position pos; ESM::Position pos;

View file

@ -103,7 +103,7 @@ namespace MWWorld
{ {
mTerrain->cacheCell(mTerrainView.get(), mX, mY); mTerrain->cacheCell(mTerrainView.get(), mX, mY);
mPreloadedObjects.insert( mPreloadedObjects.insert(
mLandManager->getLand(ESM::ExteriorCellIndex(mX, mY, ESM::Cell::sDefaultWorldspaceId))); mLandManager->getLand(ESM::ExteriorCellLocation(mX, mY, ESM::Cell::sDefaultWorldspaceId)));
} }
catch (std::exception&) catch (std::exception&)
{ {

View file

@ -247,7 +247,7 @@ namespace
return std::abs(cellPosition.first) + std::abs(cellPosition.second); 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) for (auto* cell : collection)
{ {
@ -346,7 +346,7 @@ namespace MWWorld
if (cell->getCell()->isExterior()) 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) != nullptr)
mNavigator.removeHeightfield(osg::Vec2i(cellX, cellY), navigatorUpdateGuard); mNavigator.removeHeightfield(osg::Vec2i(cellX, cellY), navigatorUpdateGuard);
@ -393,7 +393,7 @@ namespace MWWorld
const int cellY = cell.getCell()->getGridY(); const int cellY = cell.getCell()->getGridY();
const MWWorld::Cell& cellVariant = *cell.getCell(); const MWWorld::Cell& cellVariant = *cell.getCell();
ESM::RefId worldspace = cellVariant.getWorldSpace(); ESM::RefId worldspace = cellVariant.getWorldSpace();
ESM::ExteriorCellIndex cellIndex(cellX, cellY, worldspace); ESM::ExteriorCellLocation cellIndex(cellX, cellY, worldspace);
if (cellVariant.isExterior()) if (cellVariant.isExterior())
{ {
@ -512,19 +512,17 @@ namespace MWWorld
{ {
ESM::RefId worldspace ESM::RefId worldspace
= mCurrentCell ? mCurrentCell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; = mCurrentCell ? mCurrentCell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId;
bool isEsm4Ext = ESM::isEsm4Ext(worldspace);
if (currentGridCenter) if (currentGridCenter)
{ {
osg::Vec2 center = ESM::indexToPosition( 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 distance = std::max(std::abs(center.x() - pos.x()), std::abs(center.y() - pos.y()));
float cellSize = ESM::getCellSize(worldspace); float cellSize = ESM::getCellSize(worldspace);
const float maxDistance = cellSize / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold const float maxDistance = cellSize / 2 + mCellLoadingThreshold; // 1/2 cell size + threshold
if (distance <= maxDistance) if (distance <= maxDistance)
return *currentGridCenter; 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 }; return { cellPos.mX, cellPos.mY };
} }
@ -541,10 +539,10 @@ namespace MWWorld
void Scene::requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent) void Scene::requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent)
{ {
mChangeCellGridRequest = ChangeCellGridRequest{ position, 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(); auto navigatorUpdateGuard = mNavigator.makeUpdateGuard();
int playerCellX = playerCellIndex.mX; int playerCellX = playerCellIndex.mX;
@ -586,7 +584,7 @@ namespace MWWorld
{ {
for (int y = playerCellY - range; y <= playerCellY + range; ++y) 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(); refsToLoad += mWorld.getWorldModel().getExterior(playerCellIndex).count();
cellsPositionsToLoad.emplace_back(x, y); cellsPositionsToLoad.emplace_back(x, y);
@ -620,7 +618,7 @@ namespace MWWorld
for (const auto& [x, y] : cellsPositionsToLoad) for (const auto& [x, y] : cellsPositionsToLoad)
{ {
ESM::ExteriorCellIndex indexToLoad = { x, y, playerCellIndex.mWorldspace }; ESM::ExteriorCellLocation indexToLoad = { x, y, playerCellIndex.mWorldspace };
if (!isCellInCollection(indexToLoad, mActiveCells)) if (!isCellInCollection(indexToLoad, mActiveCells))
{ {
CellStore& cell = mWorld.getWorldModel().getExterior(indexToLoad); CellStore& cell = mWorld.getWorldModel().getExterior(indexToLoad);
@ -686,7 +684,7 @@ namespace MWWorld
+ std::to_string(cells.getExtSize()) + ")..."); + std::to_string(cells.getExtSize()) + ")...");
CellStore& cell = mWorld.getWorldModel().getExterior( 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()); mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
const osg::Vec3f position const osg::Vec3f position
= osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits; = 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()); const osg::Vec2i cellIndex(current.getCell()->getGridX(), current.getCell()->getGridY());
changeCellGrid(position.asVec3(), 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); changePlayerCell(current, position, adjustPlayerPos);
@ -1172,7 +1170,7 @@ namespace MWWorld
if (dy != halfGridSizePlusOne && dy != -halfGridSizePlusOne && dx != halfGridSizePlusOne if (dy != halfGridSizePlusOne && dy != -halfGridSizePlusOne && dx != halfGridSizePlusOne
&& dx != -halfGridSizePlusOne) && dx != -halfGridSizePlusOne)
continue; // only care about the outer (not yet loaded) part of the grid 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); osg::Vec2 thisCellCenter = ESM::indexToPosition(cellIndex, true);
float dist = std::max( float dist = std::max(
@ -1200,7 +1198,7 @@ namespace MWWorld
for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy) for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy)
{ {
mPreloader->preload(mWorld.getWorldModel().getExterior( 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()); mRendering.getReferenceTime());
if (++numpreloaded >= mPreloader->getMaxCacheSize()) if (++numpreloaded >= mPreloader->getMaxCacheSize())
break; break;
@ -1283,7 +1281,7 @@ namespace MWWorld
else else
{ {
osg::Vec3f pos = dest.mPos.asVec3(); 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); preloadCell(mWorld.getWorldModel().getExterior(cellIndex), true);
exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos))); exteriorPositions.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos)));
} }

View file

@ -80,7 +80,7 @@ namespace MWWorld
struct ChangeCellGridRequest struct ChangeCellGridRequest
{ {
osg::Vec3f mPosition; osg::Vec3f mPosition;
ESM::ExteriorCellIndex mCellIndex; ESM::ExteriorCellLocation mCellIndex;
bool mChangeEvent; bool mChangeEvent;
}; };
@ -118,7 +118,7 @@ namespace MWWorld
osg::Vec2i mCurrentGridCenter; osg::Vec2i mCurrentGridCenter;
// Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center // 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); void requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent = true);

View file

@ -1105,7 +1105,7 @@ namespace MWWorld
return foundCell->second; return foundCell->second;
} }
const ESM4::Cell* Store<ESM4::Cell>::searchExterior(ESM::ExteriorCellIndex cellIndex) const const ESM4::Cell* Store<ESM4::Cell>::searchExterior(ESM::ExteriorCellLocation cellIndex) const
{ {
const auto foundCell = mExteriors.find(cellIndex); const auto foundCell = mExteriors.find(cellIndex);
if (foundCell == mExteriors.end()) if (foundCell == mExteriors.end())
@ -1133,7 +1133,7 @@ namespace MWWorld
mCellNameIndex[cellPtr->mEditorId] = cellPtr; mCellNameIndex[cellPtr->mEditorId] = cellPtr;
if (cellPtr->isExterior()) 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) if (cellPtr->mCellFlags & ESM4::Rec_Persistent)
mPersistentExteriors[cellindex] = cellPtr; mPersistentExteriors[cellindex] = cellPtr;
else else

View file

@ -285,12 +285,12 @@ namespace MWWorld
std::unordered_map<std::string, ESM4::Cell*, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> std::unordered_map<std::string, ESM4::Cell*, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>
mCellNameIndex; mCellNameIndex;
std::unordered_map<ESM::ExteriorCellIndex, ESM4::Cell*> mExteriors; std::unordered_map<ESM::ExteriorCellLocation, ESM4::Cell*> mExteriors;
std::unordered_map<ESM::ExteriorCellIndex, ESM4::Cell*> mPersistentExteriors; std::unordered_map<ESM::ExteriorCellLocation, ESM4::Cell*> mPersistentExteriors;
public: public:
const ESM4::Cell* searchCellName(std::string_view) const; 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* insert(const ESM4::Cell& item, bool overrideOnly = false);
ESM4::Cell* insertStatic(const ESM4::Cell& item); ESM4::Cell* insertStatic(const ESM4::Cell& item);
void insertCell(ESM4::Cell* cell); void insertCell(ESM4::Cell* cell);

View file

@ -379,7 +379,7 @@ namespace MWWorld
pos.rot[1] = 0; pos.rot[1] = 0;
pos.rot[2] = 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); ESM::RefId cellId = ESM::RefId::esm3ExteriorCell(exteriorCellPos.mX, exteriorCellPos.mY);
mWorldScene->changeToExteriorCell(cellId, pos, true); mWorldScene->changeToExteriorCell(cellId, pos, true);
} }
@ -1247,7 +1247,7 @@ namespace MWWorld
CellStore* cell = ptr.getCell(); CellStore* cell = ptr.getCell();
ESM::RefId worldspaceId ESM::RefId worldspaceId
= cell->isExterior() ? cell->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; = 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; CellStore* newCell = cell->isExterior() ? &mWorldModel.getExterior(index) : nullptr;
bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior() bool isCellActive = getPlayerPtr().isInCell() && getPlayerPtr().getCell()->isExterior()
@ -2046,7 +2046,7 @@ namespace MWWorld
throw std::runtime_error("copyObjectToCell(): cannot copy object to null cell"); throw std::runtime_error("copyObjectToCell(): cannot copy object to null cell");
if (cell->isExterior()) if (cell->isExterior())
{ {
const ESM::ExteriorCellIndex index const ESM::ExteriorCellLocation index
= ESM::positionToCellIndex(pos.pos[0], pos.pos[1], cell->getCell()->getWorldSpace()); = ESM::positionToCellIndex(pos.pos[0], pos.pos[1], cell->getCell()->getWorldSpace());
cell = &mWorldModel.getExterior(index); 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) 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."); throw std::runtime_error("Cell coordinates out of range.");
else if (xResult.ec == std::errc{} && yResult.ec == std::errc{}) 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(); .getCell();
// ignore std::errc::invalid_argument, as this means that name probably refers to a interior cell // ignore std::errc::invalid_argument, as this means that name probably refers to a interior cell
// instead of comma separated coordinates // instead of comma separated coordinates
@ -2743,7 +2743,7 @@ namespace MWWorld
{ {
int x = ext->getGridX(); int x = ext->getGridX();
int y = ext->getGridY(); 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[0] = posFromIndex.x();
pos.pos[1] = posFromIndex.y(); pos.pos[1] = posFromIndex.y();

View file

@ -76,8 +76,8 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
} }
else else
{ {
ESM::ExteriorCellIndex extIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId); ESM::ExteriorCellLocation extIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId);
std::map<ESM::ExteriorCellIndex, CellStore*>::iterator result = mExteriors.find(extIndex); std::map<ESM::ExteriorCellLocation, CellStore*>::iterator result = mExteriors.find(extIndex);
if (result == mExteriors.end()) if (result == mExteriors.end())
result = mExteriors.emplace(extIndex, cellStore).first; 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<ESM::ExteriorCellIndex, CellStore*>::iterator result; std::map<ESM::ExteriorCellLocation, CellStore*>::iterator result;
result = mExteriors.find(cellIndex); result = mExteriors.find(cellIndex);
@ -257,7 +257,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id)
if (const auto* exteriorId = id.getIf<ESM::ESM3ExteriorCellRefId>()) if (const auto* exteriorId = id.getIf<ESM::ESM3ExteriorCellRefId>())
return getExterior( 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<ESM4::Cell>().search(id); const ESM4::Cell* cell4 = mStore.get<ESM4::Cell>().search(id);
CellStore* newCellStore = nullptr; CellStore* newCellStore = nullptr;
@ -274,7 +274,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id)
{ {
std::pair<int, int> coord std::pair<int, int> coord
= std::make_pair(newCellStore->getCell()->getGridX(), newCellStore->getCell()->getGridY()); = 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); mExteriors.emplace(extIndex, newCellStore);
} }
else else
@ -319,7 +319,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(std::string_view name)
if (!cell) if (!cell)
throw std::runtime_error(std::string("Can't find cell with name ") + std::string(name)); 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( MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition(
@ -329,7 +329,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition(
return *cellInSameWorldSpace; return *cellInSameWorldSpace;
ESM::RefId exteriorWorldspace ESM::RefId exteriorWorldspace
= cellInSameWorldSpace ? cellInSameWorldSpace->getCell()->getWorldSpace() : ESM::Cell::sDefaultWorldspaceId; = 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); return getExterior(cellIndex);
} }

View file

@ -44,7 +44,7 @@ namespace MWWorld
mutable std::unordered_map<ESM::RefId, CellStore> mCells; mutable std::unordered_map<ESM::RefId, CellStore> mCells;
mutable std::map<std::string, CellStore*, Misc::StringUtils::CiComp> mInteriors; mutable std::map<std::string, CellStore*, Misc::StringUtils::CiComp> mInteriors;
mutable std::map<ESM::ExteriorCellIndex, CellStore*> mExteriors; mutable std::map<ESM::ExteriorCellLocation, CellStore*> mExteriors;
IdCache mIdCache; IdCache mIdCache;
std::size_t mIdCacheIndex = 0; std::size_t mIdCacheIndex = 0;
std::unordered_map<ESM::RefNum, Ptr> mPtrIndex; std::unordered_map<ESM::RefNum, Ptr> mPtrIndex;
@ -65,7 +65,7 @@ namespace MWWorld
void clear(); void clear();
CellStore& getExterior(ESM::ExteriorCellIndex cellIndex); CellStore& getExterior(ESM::ExteriorCellLocation cellIndex);
CellStore& getInterior(std::string_view name); CellStore& getInterior(std::string_view name);
CellStore& getCell(std::string_view name); // interior or named exterior CellStore& getCell(std::string_view name); // interior or named exterior
CellStore& getCell(const ESM::RefId& Id); CellStore& getCell(const ESM::RefId& Id);

View file

@ -1,6 +1,6 @@
#include "util.hpp" #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); const int cellSize = ESM::getCellSize(cellIndex.mWorldspace);

View file

@ -49,24 +49,24 @@ namespace ESM
operator osg::Vec3f() const { return osg::Vec3f(mValues[0], mValues[1], mValues[2]); } operator osg::Vec3f() const { return osg::Vec3f(mValues[0], mValues[1], mValues[2]); }
}; };
struct ExteriorCellIndex struct ExteriorCellLocation
{ {
int mX, mY; int mX, mY;
ESM::RefId mWorldspace; ESM::RefId mWorldspace;
ExteriorCellIndex(int x, int y, ESM::RefId worldspace) ExteriorCellLocation(int x, int y, ESM::RefId worldspace)
: mX(x) : mX(x)
, mY(y) , mY(y)
, mWorldspace(worldspace) , mWorldspace(worldspace)
{ {
} }
bool operator==(const ExteriorCellIndex& other) const bool operator==(const ExteriorCellLocation& other) const
{ {
return mX == other.mX && mY == other.mY && mWorldspace == other.mWorldspace; 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); 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; 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) float x, float y, ESM::RefId worldspaceId = ESM::Cell::sDefaultWorldspaceId)
{ {
const float cellSize = getCellSize(worldspaceId); const float cellSize = getCellSize(worldspaceId);
return { static_cast<int>(std::floor(x / cellSize)), static_cast<int>(std::floor(y / cellSize)), worldspaceId }; return { static_cast<int>(std::floor(x / cellSize)), static_cast<int>(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. ///< Convert cell numbers to position.
} }
namespace std namespace std
{ {
template <> template <>
struct hash<ESM::ExteriorCellIndex> struct hash<ESM::ExteriorCellLocation>
{ {
std::size_t operator()(const ESM::ExteriorCellIndex& toHash) const std::size_t operator()(const ESM::ExteriorCellLocation& toHash) const
{ {
// Compute individual hash values for first, // Compute individual hash values for first,
// second and third and combine them using XOR // second and third and combine them using XOR