applies review comments

Removes ToLowercase after .serializeText
removed unused variable
!ptr => ptr == nullptr
better indentation + error message on throw
friend struct std::hash<...> useless on struct with all public fields.
simplify_debugging
florent.teppe 2 years ago
parent 39cfe9c2fb
commit 559830f59a

@ -548,7 +548,6 @@ namespace MWWorld
auto navigatorUpdateGuard = mNavigator.makeUpdateGuard(); auto navigatorUpdateGuard = mNavigator.makeUpdateGuard();
int playerCellX = playerCellIndex.mX; int playerCellX = playerCellIndex.mX;
int playerCellY = playerCellIndex.mY; int playerCellY = playerCellIndex.mY;
ESM::RefId exteriorWorldspace = playerCellIndex.mWorldspace;
for (auto iter = mActiveCells.begin(); iter != mActiveCells.end();) for (auto iter = mActiveCells.begin(); iter != mActiveCells.end();)
{ {
@ -564,8 +563,7 @@ namespace MWWorld
unloadCell(cell, navigatorUpdateGuard.get()); unloadCell(cell, navigatorUpdateGuard.get());
} }
mNavigator.setWorldspace( mNavigator.setWorldspace(
Misc::StringUtils::lowerCase( mWorld.getWorldModel().getExterior(playerCellIndex).getCell()->getWorldSpace().serializeText(),
mWorld.getWorldModel().getExterior(playerCellIndex).getCell()->getWorldSpace().serializeText()),
navigatorUpdateGuard.get()); navigatorUpdateGuard.get());
mNavigator.updateBounds(pos, navigatorUpdateGuard.get()); mNavigator.updateBounds(pos, navigatorUpdateGuard.get());
@ -621,7 +619,7 @@ namespace MWWorld
for (const auto& [x, y] : cellsPositionsToLoad) for (const auto& [x, y] : cellsPositionsToLoad)
{ {
ESM::ExteriorCellIndex indexToLoad = { x, y, exteriorWorldspace }; ESM::ExteriorCellIndex 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);
@ -688,8 +686,7 @@ namespace MWWorld
CellStore& cell = mWorld.getWorldModel().getExterior( CellStore& cell = mWorld.getWorldModel().getExterior(
ESM::ExteriorCellIndex(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId)); ESM::ExteriorCellIndex(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId));
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
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;
mNavigator.updateBounds(position, navigatorUpdateGuard.get()); mNavigator.updateBounds(position, navigatorUpdateGuard.get());
@ -746,8 +743,7 @@ namespace MWWorld
+ std::to_string(cells.getIntSize()) + ")..."); + std::to_string(cells.getIntSize()) + ")...");
CellStore& cell = mWorld.getWorldModel().getInterior(it->mName); CellStore& cell = mWorld.getWorldModel().getInterior(it->mName);
mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
navigatorUpdateGuard.get());
ESM::Position position; ESM::Position position;
mWorld.findInteriorPosition(it->mName, position); mWorld.findInteriorPosition(it->mName, position);
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
@ -902,8 +898,7 @@ namespace MWWorld
loadingListener->setProgressRange(cell.count()); loadingListener->setProgressRange(cell.count());
mNavigator.setWorldspace( mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get());
Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), navigatorUpdateGuard.get());
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
// Load cell. // Load cell.

@ -76,7 +76,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellStore(const ESM::Cell* cell)
} }
else else
{ {
ESM::ExteriorCellIndex extIndex = { cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId }; ESM::ExteriorCellIndex extIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId);
std::map<ESM::ExteriorCellIndex, CellStore*>::iterator result = mExteriors.find(extIndex); std::map<ESM::ExteriorCellIndex, CellStore*>::iterator result = mExteriors.find(extIndex);
if (result == mExteriors.end()) if (result == mExteriors.end())
@ -172,7 +172,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellIndex cell
{ {
const ESM::Cell* cell = mStore.get<ESM::Cell>().search(cellIndex.mX, cellIndex.mY); const ESM::Cell* cell = mStore.get<ESM::Cell>().search(cellIndex.mX, cellIndex.mY);
if (!cell) if (cell == nullptr)
{ {
// Cell isn't predefined. Make one on the fly. // Cell isn't predefined. Make one on the fly.
ESM::Cell record; ESM::Cell record;
@ -193,27 +193,22 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellIndex cell
else else
{ {
const Store<ESM4::Cell>& cell4Store = mStore.get<ESM4::Cell>(); const Store<ESM4::Cell>& cell4Store = mStore.get<ESM4::Cell>();
bool exteriorExists = mStore.get<ESM4::World>().search(cellIndex.mWorldspace); bool exteriorExists = mStore.get<ESM4::World>().search(cellIndex.mWorldspace) != nullptr;
const ESM4::Cell* cell = cell4Store.searchExterior(cellIndex); const ESM4::Cell* cell = cell4Store.searchExterior(cellIndex);
if (exteriorExists) if (!exteriorExists)
throw std::runtime_error("Exterior ESM4 world is not found: " + cellIndex.mWorldspace.toDebugString());
if (cell == nullptr)
{ {
if (!cell) ESM4::Cell record;
{ record.mParent = cellIndex.mWorldspace;
ESM4::Cell record; record.mX = cellIndex.mX;
record.mParent = cellIndex.mWorldspace; record.mY = cellIndex.mY;
record.mX = cellIndex.mX; record.mCellFlags = !ESM4::CELL_Interior;
record.mY = cellIndex.mY; cell = MWBase::Environment::get().getESMStore()->insert(record);
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 = mExteriors.emplace(cellIndex, cellStore).first;
}
else
{
throw std::runtime_error("exterior not found: '" + cellIndex.mWorldspace.toDebugString() + "'");
} }
CellStore* cellStore
= &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second;
result = mExteriors.emplace(cellIndex, cellStore).first;
} }
} }
if (result->second->getState() != CellStore::State_Loaded) if (result->second->getState() != CellStore::State_Loaded)

@ -70,8 +70,6 @@ namespace ESM
{ {
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);
} }
friend struct std::hash<ExteriorCellIndex>;
}; };
static inline bool isEsm4Ext(ESM::RefId worldspaceId) static inline bool isEsm4Ext(ESM::RefId worldspaceId)

Loading…
Cancel
Save