From 22981af2ea8f86b0ad01a3df62a1d30d304701e0 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 30 Jul 2023 16:19:36 +0200 Subject: [PATCH] Make sure ESM4 cell description is not empty To avoid logging empty cell descriptions on loading and unloading. Not all cells have editor id but every has id and coordinates. Add world to distinguish cell coordinates in different worldspaces. --- apps/openmw/mwworld/cell.cpp | 46 +++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index 9f1ad3e4a2..3ea6766b90 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -1,15 +1,47 @@ #include "cell.hpp" +#include "esmstore.hpp" + +#include "../mwbase/environment.hpp" + #include #include #include #include -#include "../mwbase/environment.hpp" -#include "esmstore.hpp" +#include +#include namespace MWWorld { + namespace + { + std::string getDescription(const ESM4::World& value) + { + if (!value.mEditorId.empty()) + return value.mEditorId; + + return value.mId.serializeText(); + } + + std::string getCellDescription(const ESM4::Cell& cell, const ESM4::World* world) + { + std::string result; + + if (!cell.mEditorId.empty()) + result = cell.mEditorId; + else if (world != nullptr && cell.isExterior()) + result = getDescription(*world); + else + result = cell.mId.serializeText(); + + if (cell.isExterior()) + result += " (" + std::to_string(cell.mX) + ", " + std::to_string(cell.mY) + ")"; + + return result; + } + } + Cell::Cell(const ESM4::Cell& cell) : ESM::CellVariant(cell) , mIsExterior(!(cell.mCellFlags & ESM4::CELL_Interior)) @@ -23,7 +55,6 @@ namespace MWWorld , mId(cell.mId) , mParent(cell.mParent) , mWaterHeight(cell.mWaterHeight) - , mDescription(cell.mEditorId) , mMood{ .mAmbiantColor = cell.mLighting.ambient, .mDirectionalColor = cell.mLighting.directional, @@ -32,12 +63,15 @@ namespace MWWorld .mFogDensity = 1.f, } { + const ESM4::World* world = MWBase::Environment::get().getESMStore()->get().search(mParent); if (isExterior()) { - auto& worldStore = MWBase::Environment::get().getESMStore()->get(); - const ESM4::World* cellWorld = worldStore.find(mParent); - mWaterHeight = cellWorld->mWaterLevel; + if (world == nullptr) + throw std::runtime_error( + "Cell " + cell.mId.toDebugString() + " parent world " + mParent.toDebugString() + " is not found"); + mWaterHeight = world->mWaterLevel; } + mDescription = getCellDescription(cell, world); } Cell::Cell(const ESM::Cell& cell)