From 4e7cde5d72865604f4d37fc65b7eadaedbf64195 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sun, 29 Jan 2023 19:18:50 +0100 Subject: [PATCH] applied some review changes. crashfix tests --- apps/openmw/mwmechanics/aiwander.hpp | 1 - apps/openmw/mwworld/cell.cpp | 17 +++--- apps/openmw/mwworld/cell.hpp | 16 ++--- apps/openmw/mwworld/cellref.cpp | 90 ++++++++++++++++++++-------- apps/openmw/mwworld/cellref.hpp | 20 +++---- apps/openmw/mwworld/cellstore.cpp | 8 --- apps/openmw/mwworld/livecellref.cpp | 2 +- apps/openmw/mwworld/scene.cpp | 5 +- apps/openmw/mwworld/worldimp.cpp | 3 +- components/esm3/cellid.cpp | 2 +- components/esm3/cellid.hpp | 1 - 11 files changed, 96 insertions(+), 69 deletions(-) diff --git a/apps/openmw/mwmechanics/aiwander.hpp b/apps/openmw/mwmechanics/aiwander.hpp index f956367321..b4d59bdbe2 100644 --- a/apps/openmw/mwmechanics/aiwander.hpp +++ b/apps/openmw/mwmechanics/aiwander.hpp @@ -160,7 +160,6 @@ namespace MWMechanics }; /// convert point from local (i.e. cell) to world coordinates - void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::CellCommon* cell); void setCurrentNodeToClosestAllowedNode(AiWanderStorage& storage); void addNonPathGridAllowedPoints(const ESM::Pathgrid* pathGrid, int pointIndex, AiWanderStorage& storage, diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index 5f43b5bd43..9a345d2ac8 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -17,13 +17,12 @@ namespace MWWorld mRegion = ESM::RefId::sEmpty; // Unimplemented for now - mFlags.hasWater = cell.mCellFlags & ESM4::CELL_HasWater; - mFlags.isExterior = !(cell.mCellFlags & ESM4::CELL_Interior); - mFlags.isQuasiExterior = cell.mCellFlags & ESM4::CELL_QuasiExt; - mFlags.noSleep = false; // No such notion in ESM4 + mFlags.mHasWater = cell.mCellFlags & ESM4::CELL_HasWater; + mFlags.mIsExterior = !(cell.mCellFlags & ESM4::CELL_Interior); + mFlags.mIsQuasiExterior = cell.mCellFlags & ESM4::CELL_QuasiExt; + mFlags.mNoSleep = false; // No such notion in ESM4 mCellId.mWorldspace = Misc::StringUtils::lowerCase(cell.mEditorId); - mCellId.mWorld = ESM::RefId::sEmpty; mCellId.mIndex.mX = cell.getGridX(); mCellId.mIndex.mX = cell.getGridY(); mCellId.mPaged = isExterior(); @@ -44,10 +43,10 @@ namespace MWWorld mRegion = ESM::RefId::sEmpty; // Unimplemented for now - mFlags.hasWater = cell.mData.mFlags & ESM::Cell::HasWater; - mFlags.isExterior = !(cell.mData.mFlags & ESM::Cell::Interior); - mFlags.isQuasiExterior = cell.mData.mFlags & ESM::Cell::QuasiEx; - mFlags.noSleep = cell.mData.mFlags & ESM::Cell::NoSleep; + mFlags.mHasWater = cell.mData.mFlags & ESM::Cell::HasWater; + mFlags.mIsExterior = !(cell.mData.mFlags & ESM::Cell::Interior); + mFlags.mIsQuasiExterior = cell.mData.mFlags & ESM::Cell::QuasiEx; + mFlags.mNoSleep = cell.mData.mFlags & ESM::Cell::NoSleep; mCellId = cell.getCellId(); diff --git a/apps/openmw/mwworld/cell.hpp b/apps/openmw/mwworld/cell.hpp index a052222005..21a53792da 100644 --- a/apps/openmw/mwworld/cell.hpp +++ b/apps/openmw/mwworld/cell.hpp @@ -38,10 +38,10 @@ namespace MWWorld int getGridX() const { return mGridPos.x(); } int getGridY() const { return mGridPos.y(); } - bool isExterior() const { return mFlags.isExterior; } - bool isQuasiExterior() const { return mFlags.isQuasiExterior; } - bool hasWater() const { return mFlags.hasWater; } - bool noSleep() const { return mFlags.noSleep; } + bool isExterior() const { return mFlags.mIsExterior; } + bool isQuasiExterior() const { return mFlags.mIsQuasiExterior; } + bool hasWater() const { return mFlags.mHasWater; } + bool noSleep() const { return mFlags.mNoSleep; } const ESM::CellId& getCellId() const { return mCellId; } const ESM::RefId& getRegion() const { return mRegion; } std::string_view getNameId() const { return mNameID; } @@ -52,10 +52,10 @@ namespace MWWorld private: struct { - bool isExterior; - bool isQuasiExterior; - bool hasWater; - bool noSleep; + bool mIsExterior; + bool mIsQuasiExterior; + bool mHasWater; + bool mNoSleep; } mFlags; osg::Vec2i mGridPos; diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index 5229614258..4eef83e50d 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -20,29 +20,29 @@ namespace MWWorld CellRef::CellRef(const ESM::CellRef& ref) : mCellRef(ESM::ReferenceVariant(ref)) { - mChanged = false; } CellRef::CellRef(const ESM4::Reference& ref) : mCellRef(ESM::ReferenceVariant(ref)) { - - mChanged = false; } static const ESM::RefNum emptyRefNum = {}; const ESM::RefNum& CellRef::getRefNum() const { - return std::visit(RefVisit{ [&](const ESM4::Reference& ref) -> const ESM::RefNum& { return emptyRefNum; }, - [&](const ESM::CellRef& ref) -> const ESM::RefNum& { return ref.mRefNum; } }, + return std::visit(RefVisit{ + [&](const ESM4::Reference& /*ref*/) -> const ESM::RefNum& { return emptyRefNum; }, + [&](const ESM::CellRef& ref) -> const ESM::RefNum& { return ref.mRefNum; }, + }, mCellRef.mVariant); } const ESM::RefNum& CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum) { return std::visit( - RefVisit{ [&](ESM4::Reference& ref) -> const ESM::RefNum& { return emptyRefNum; }, + RefVisit{ + [&](ESM4::Reference& /*ref*/) -> const ESM::RefNum& { return emptyRefNum; }, [&](ESM::CellRef& ref) -> const ESM::RefNum& { if (!ref.mRefNum.isSet()) { @@ -60,13 +60,17 @@ namespace MWWorld mChanged = true; } return ref.mRefNum; - } }, + }, + }, mCellRef.mVariant); } void CellRef::unsetRefNum() { - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mRefNum = emptyRefNum; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mRefNum = emptyRefNum; }, + }, mCellRef.mVariant); } @@ -94,8 +98,10 @@ namespace MWWorld float CellRef::getEnchantmentCharge() const { - return std::visit(RefVisit{ [&](const ESM4::Reference& ref) { return 0.f; }, - [&](const ESM::CellRef& ref) { return ref.mEnchantmentCharge; } }, + return std::visit(RefVisit{ + [&](const ESM4::Reference& /*ref*/) { return 0.f; }, + [&](const ESM::CellRef& ref) { return ref.mEnchantmentCharge; }, + }, mCellRef.mVariant); } @@ -121,21 +127,27 @@ namespace MWWorld { mChanged = true; - std::visit( - RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mEnchantmentCharge = charge; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mEnchantmentCharge = charge; }, + }, mCellRef.mVariant); } } void CellRef::setCharge(int charge) { - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mChargeInt = charge; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mChargeInt = charge; }, + }, mCellRef.mVariant); } void CellRef::applyChargeRemainderToBeSubtracted(float chargeRemainder) { - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, [&](ESM::CellRef& cellRef3) { cellRef3.mChargeIntRemainder += std::abs(chargeRemainder); if (cellRef3.mChargeIntRemainder > 1.0f) @@ -152,21 +164,27 @@ namespace MWWorld } cellRef3.mChargeIntRemainder = newChargeRemainder; } - } }, + }, + }, mCellRef.mVariant); } void CellRef::setChargeFloat(float charge) { - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mChargeFloat = charge; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mChargeFloat = charge; }, + }, mCellRef.mVariant); } const std::string& CellRef::getGlobalVariable() const { - return std::visit(RefVisit{ [&](const ESM4::Reference& ref) -> const std::string& { return emptyString; }, - [&](const ESM::CellRef& ref) -> const std::string& { return ref.mGlobalVariable; } }, + return std::visit(RefVisit{ + [&](const ESM4::Reference& /*ref*/) -> const std::string& { return emptyString; }, + [&](const ESM::CellRef& ref) -> const std::string& { return ref.mGlobalVariable; }, + }, mCellRef.mVariant); } @@ -175,8 +193,10 @@ namespace MWWorld if (!getGlobalVariable().empty()) { mChanged = true; - std::visit( - RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mGlobalVariable.erase(); } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mGlobalVariable.erase(); }, + }, mCellRef.mVariant); } } @@ -194,7 +214,10 @@ namespace MWWorld { if (owner != getOwner()) { - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mOwner = owner; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mOwner = owner; }, + }, mCellRef.mVariant); } } @@ -204,7 +227,10 @@ namespace MWWorld if (soul != getSoul()) { mChanged = true; - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mSoul = soul; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mSoul = soul; }, + }, mCellRef.mVariant); } } @@ -214,7 +240,10 @@ namespace MWWorld if (faction != getFaction()) { mChanged = true; - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mFaction = faction; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mFaction = faction; }, + }, mCellRef.mVariant); } } @@ -246,7 +275,10 @@ namespace MWWorld if (trap != getTrap()) { mChanged = true; - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mTrap = trap; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mTrap = trap; }, + }, mCellRef.mVariant); } } @@ -256,14 +288,20 @@ namespace MWWorld if (value != getGoldValue()) { mChanged = true; - std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mGoldValue = value; } }, + std::visit(RefVisit{ + [&](ESM4::Reference& /*ref*/) {}, + [&](ESM::CellRef& ref) { ref.mGoldValue = value; }, + }, mCellRef.mVariant); } } void CellRef::writeState(ESM::ObjectState& state) const { - std::visit(RefVisit{ [&](const ESM4::Reference& ref) {}, [&](const ESM::CellRef& ref) { state.mRef = ref; } }, + std::visit(RefVisit{ + [&](const ESM4::Reference& /*ref*/) {}, + [&](const ESM::CellRef& ref) { state.mRef = ref; }, + }, mCellRef.mVariant); } } diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index 25c3e768ef..cab671bd0c 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -20,9 +20,9 @@ namespace MWWorld { protected: public: - CellRef(const ESM::CellRef& ref); + explicit CellRef(const ESM::CellRef& ref); - CellRef(const ESM4::Reference& ref); + explicit CellRef(const ESM4::Reference& ref); // Note: Currently unused for items in containers const ESM::RefNum& getRefNum() const; @@ -105,7 +105,7 @@ namespace MWWorld struct Visitor { int operator()(const ESM::CellRef& ref) { return ref.mChargeInt; } - int operator()(const ESM4::Reference& ref) { return 0; } + int operator()(const ESM4::Reference& /*ref*/) { return 0; } }; return std::visit(Visitor(), mCellRef.mVariant); } @@ -114,7 +114,7 @@ namespace MWWorld struct Visitor { float operator()(const ESM::CellRef& ref) { return ref.mChargeFloat; } - float operator()(const ESM4::Reference& ref) { return 0; } + float operator()(const ESM4::Reference& /*ref*/) { return 0; } }; return std::visit(Visitor(), mCellRef.mVariant); } // Implemented as union with int charge @@ -128,7 +128,7 @@ namespace MWWorld struct Visitor { const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mOwner; } - const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; } + const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; } }; return std::visit(Visitor(), mCellRef.mVariant); } @@ -147,7 +147,7 @@ namespace MWWorld struct Visitor { const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mSoul; } - const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; } + const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; } }; return std::visit(Visitor(), mCellRef.mVariant); } @@ -160,7 +160,7 @@ namespace MWWorld struct Visitor { const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mFaction; } - const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; } + const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; } }; return std::visit(Visitor(), mCellRef.mVariant); } @@ -193,7 +193,7 @@ namespace MWWorld struct Visitor { const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mTrap; } - const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; } + const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; } }; return std::visit(Visitor(), mCellRef.mVariant); } @@ -205,7 +205,7 @@ namespace MWWorld struct Visitor { int operator()(const ESM::CellRef& ref) { return ref.mGoldValue; } - int operator()(const ESM4::Reference& ref) { return 0; } + int operator()(const ESM4::Reference& /*ref*/) { return 0; } }; return std::visit(Visitor(), mCellRef.mVariant); } @@ -218,7 +218,7 @@ namespace MWWorld bool hasChanged() const { return mChanged; } private: - bool mChanged; + bool mChanged = false; ESM::ReferenceVariant mCellRef; }; diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 767c3c86d0..d322c183cf 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -382,17 +382,9 @@ namespace MWWorld if (const X* ptr = store.search(ref.mBaseObj)) { - // typename std::list::iterator iter = std::find(mList.begin(), mList.end(), ref.); - LiveRef liveCellRef(ref, ptr); - if (deleted) liveCellRef.mData.setDeletedByContentFile(true); - - /*if (iter != mList.end()) - *iter = liveCellRef; - else - */ mList.push_back(liveCellRef); } else diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 88218429e1..7668f18de1 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -31,7 +31,7 @@ MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::Referen void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state) { - mRef = state.mRef; + mRef = MWWorld::CellRef(state.mRef); mData = RefData(state, mData.isDeletedByContentFile()); Ptr ptr(this); diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index d77e729c35..0e285ee30d 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -317,8 +317,7 @@ namespace MWWorld { if (mActiveCells.find(cell) == mActiveCells.end()) return; - std::string description = cell->getCell()->getDescription(); - Log(Debug::Info) << "Unloading cell " << description; + Log(Debug::Info) << "Unloading cell " << cell->getCell()->getDescription(); ListAndResetObjectsVisitor visitor; @@ -387,7 +386,7 @@ namespace MWWorld const int cellX = cell->getCell()->getGridX(); const int cellY = cell->getCell()->getGridY(); - auto cellVariant = *cell->getCell(); + const MWWorld::Cell& cellVariant = *cell->getCell(); if (cellVariant.isExterior()) { diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 39d324a80d..641619acf6 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -645,7 +645,8 @@ namespace MWWorld if (!cell.isEsm4()) { const ESM::Region* region = mStore.get().search(cell.getEsm3().mRegion); - return region->mName; + if (region) + return region->mName; } return mStore.get().find("sDefaultCellname")->mValue.getString(); diff --git a/components/esm3/cellid.cpp b/components/esm3/cellid.cpp index f5318cbbd7..a63a1bfad6 100644 --- a/components/esm3/cellid.cpp +++ b/components/esm3/cellid.cpp @@ -31,7 +31,7 @@ namespace ESM bool operator==(const CellId& left, const CellId& right) { - return left.mWorld == right.mWorld && left.mWorldspace == right.mWorldspace && left.mPaged == right.mPaged + return left.mWorldspace == right.mWorldspace && left.mPaged == right.mPaged && (!left.mPaged || (left.mIndex.mX == right.mIndex.mX && left.mIndex.mY == right.mIndex.mY)); } diff --git a/components/esm3/cellid.hpp b/components/esm3/cellid.hpp index 8d2418790f..33db9e7432 100644 --- a/components/esm3/cellid.hpp +++ b/components/esm3/cellid.hpp @@ -17,7 +17,6 @@ namespace ESM int mY; }; - ESM::RefId mWorld; std::string mWorldspace; CellIndex mIndex; bool mPaged;