From 559830f59a8ad6e4d86816b3fdf46d8e319e727d Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Wed, 10 May 2023 14:51:33 +0200 Subject: [PATCH] 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. --- apps/openmw/mwworld/scene.cpp | 15 +++++-------- apps/openmw/mwworld/worldmodel.cpp | 35 +++++++++++++----------------- components/esm/util.hpp | 2 -- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index c6623998b9..10145fbf17 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -548,7 +548,6 @@ namespace MWWorld auto navigatorUpdateGuard = mNavigator.makeUpdateGuard(); int playerCellX = playerCellIndex.mX; int playerCellY = playerCellIndex.mY; - ESM::RefId exteriorWorldspace = playerCellIndex.mWorldspace; for (auto iter = mActiveCells.begin(); iter != mActiveCells.end();) { @@ -564,8 +563,7 @@ namespace MWWorld unloadCell(cell, navigatorUpdateGuard.get()); } mNavigator.setWorldspace( - Misc::StringUtils::lowerCase( - mWorld.getWorldModel().getExterior(playerCellIndex).getCell()->getWorldSpace().serializeText()), + mWorld.getWorldModel().getExterior(playerCellIndex).getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); mNavigator.updateBounds(pos, navigatorUpdateGuard.get()); @@ -621,7 +619,7 @@ namespace MWWorld for (const auto& [x, y] : cellsPositionsToLoad) { - ESM::ExteriorCellIndex indexToLoad = { x, y, exteriorWorldspace }; + ESM::ExteriorCellIndex indexToLoad = { x, y, playerCellIndex.mWorldspace }; if (!isCellInCollection(indexToLoad, mActiveCells)) { CellStore& cell = mWorld.getWorldModel().getExterior(indexToLoad); @@ -688,8 +686,7 @@ namespace MWWorld CellStore& cell = mWorld.getWorldModel().getExterior( ESM::ExteriorCellIndex(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId)); - mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), - navigatorUpdateGuard.get()); + 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; mNavigator.updateBounds(position, navigatorUpdateGuard.get()); @@ -746,8 +743,7 @@ namespace MWWorld + std::to_string(cells.getIntSize()) + ")..."); CellStore& cell = mWorld.getWorldModel().getInterior(it->mName); - mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), - navigatorUpdateGuard.get()); + mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); ESM::Position position; mWorld.findInteriorPosition(it->mName, position); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); @@ -902,8 +898,7 @@ namespace MWWorld loadingListener->setProgressRange(cell.count()); - mNavigator.setWorldspace( - Misc::StringUtils::lowerCase(cell.getCell()->getWorldSpace().serializeText()), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(cell.getCell()->getWorldSpace().serializeText(), navigatorUpdateGuard.get()); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); // Load cell. diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index d0c47dd6b1..7491415630 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -76,7 +76,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellStore(const ESM::Cell* cell) } else { - ESM::ExteriorCellIndex extIndex = { cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId }; + ESM::ExteriorCellIndex extIndex(cell->getGridX(), cell->getGridY(), ESM::Cell::sDefaultWorldspaceId); std::map::iterator result = mExteriors.find(extIndex); if (result == mExteriors.end()) @@ -172,7 +172,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellIndex cell { const ESM::Cell* cell = mStore.get().search(cellIndex.mX, cellIndex.mY); - if (!cell) + if (cell == nullptr) { // Cell isn't predefined. Make one on the fly. ESM::Cell record; @@ -193,27 +193,22 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellIndex cell else { const Store& cell4Store = mStore.get(); - bool exteriorExists = mStore.get().search(cellIndex.mWorldspace); + bool exteriorExists = mStore.get().search(cellIndex.mWorldspace) != nullptr; 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; - record.mX = cellIndex.mX; - record.mY = cellIndex.mY; - 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() + "'"); + ESM4::Cell record; + record.mParent = cellIndex.mWorldspace; + record.mX = cellIndex.mX; + record.mY = cellIndex.mY; + 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; } } if (result->second->getState() != CellStore::State_Loaded) diff --git a/components/esm/util.hpp b/components/esm/util.hpp index a6818e562c..3ae244bd20 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -70,8 +70,6 @@ namespace ESM { return std::make_tuple(mX, mY, mWorldspace) < std::make_tuple(other.mX, other.mY, other.mWorldspace); } - - friend struct std::hash; }; static inline bool isEsm4Ext(ESM::RefId worldspaceId)