From 6895a452efaf04f679d88577ffeeed50041cf732 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Mon, 20 Feb 2023 22:33:35 +0100 Subject: [PATCH] restores the concept of worldspace for MWWorld::Cell --- apps/openmw/mwmechanics/aifollow.cpp | 4 ++-- .../mwscript/transformationextensions.cpp | 3 +-- apps/openmw/mwworld/cell.cpp | 10 +++++++++ apps/openmw/mwworld/cell.hpp | 2 ++ apps/openmw/mwworld/scene.cpp | 22 ++++++++++--------- components/esm4/loadcell.cpp | 2 +- components/esm4/loadcell.hpp | 2 +- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index 55a5e2534c..50f8f8e3c3 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -174,8 +174,8 @@ namespace MWMechanics return true; } } - else if (Misc::StringUtils::ciEqual( - mCellId, actor.getCell()->getCell()->getNameId())) // Cell to travel to + else if (Misc::StringUtils::ciEqual(mCellId, + actor.getCell()->getCell()->getWorldSpace().getRefIdString())) // Cell to travel to { mRemainingDuration = mDuration; return true; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index fc994c8754..6ae9c77ca2 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -87,8 +87,7 @@ namespace MWScript float distance; // If the objects are in different worldspaces, return a large value (just like vanilla) if (!to.isInCell() || !from.isInCell() - || !Misc::StringUtils::ciEqual( - to.getCell()->getCell()->getNameId(), from.getCell()->getCell()->getNameId())) + || to.getCell()->getCell()->getWorldSpace() != from.getCell()->getCell()->getWorldSpace()) distance = std::numeric_limits::max(); else { diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index b8a352df71..7680090410 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -1,5 +1,6 @@ #include "cell.hpp" +#include #include #include #include @@ -17,6 +18,7 @@ namespace MWWorld , mNameID(cell.mEditorId) , mRegion(ESM::RefId()) // Unimplemented for now , mId(cell.mId) + , mParent(cell.mParent) ,mMood{ .mAmbiantColor = cell.mLighting.ambient, .mDirectionalColor = cell.mLighting.directional, @@ -38,6 +40,7 @@ namespace MWWorld , mNameID(cell.mName) , mRegion(cell.mRegion) , mId(cell.mId) + , mParent(ESM::RefId::stringRefId(ESM::CellId::sDefaultWorldspace)) , mMood{ .mAmbiantColor = cell.mAmbi.mAmbient, .mDirectionalColor = cell.mAmbi.mSunlight, @@ -56,4 +59,11 @@ namespace MWWorld }, *this); } + ESM::RefId Cell::getWorldSpace() const + { + if (isExterior()) + return mParent; + else + return mId; + } } diff --git a/apps/openmw/mwworld/cell.hpp b/apps/openmw/mwworld/cell.hpp index 60751e8797..4b8e9b7639 100644 --- a/apps/openmw/mwworld/cell.hpp +++ b/apps/openmw/mwworld/cell.hpp @@ -49,6 +49,7 @@ namespace MWWorld const MoodData& getMood() const { return mMood; } float getWaterHeight() const { return mWaterHeight; } const ESM::RefId& getId() const { return mId; } + ESM::RefId getWorldSpace() const; private: bool mIsExterior; @@ -61,6 +62,7 @@ namespace MWWorld std::string mNameID; // The name that will be used by the script and console commands ESM::RefId mRegion; ESM::RefId mId; + ESM::RefId mParent; MoodData mMood; float mWaterHeight; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index b3a077d23d..7d5989baea 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -552,9 +552,11 @@ namespace MWWorld unloadCell(cell, navigatorUpdateGuard.get()); } - mNavigator.setWorldspace( - Misc::StringUtils::lowerCase( - mWorld.getWorldModel().getExterior(playerCellX, playerCellY)->getCell()->getNameId()), + mNavigator.setWorldspace(Misc::StringUtils::lowerCase(mWorld.getWorldModel() + .getExterior(playerCellX, playerCellY) + ->getCell() + ->getWorldSpace() + .getRefIdString()), navigatorUpdateGuard.get()); mNavigator.updateBounds(pos, navigatorUpdateGuard.get()); @@ -675,8 +677,8 @@ namespace MWWorld "Testing exterior cells (" + std::to_string(i) + "/" + std::to_string(cells.getExtSize()) + ")..."); CellStore* cell = mWorld.getWorldModel().getExterior(it->mData.mX, it->mData.mY); - mNavigator.setWorldspace( - Misc::StringUtils::lowerCase(cell->getCell()->getNameId()), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell->getCell()->getWorldSpace().getRefIdString()), + 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()); @@ -733,8 +735,8 @@ namespace MWWorld "Testing interior cells (" + std::to_string(i) + "/" + std::to_string(cells.getIntSize()) + ")..."); CellStore* cell = mWorld.getWorldModel().getInterior(it->mName); - mNavigator.setWorldspace( - Misc::StringUtils::lowerCase(cell->getCell()->getNameId()), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell->getCell()->getWorldSpace().getRefIdString()), + navigatorUpdateGuard.get()); ESM::Position position; mWorld.findInteriorPosition(it->mName, position); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); @@ -750,7 +752,7 @@ namespace MWWorld { assert(!(*iter)->getCell()->isExterior()); - if (it->mName == (*iter)->getCell()->getNameId()) + if (it->mName == (*iter)->getCell()->getWorldSpace().getRefIdString()) { unloadCell(*iter, navigatorUpdateGuard.get()); break; @@ -889,8 +891,8 @@ namespace MWWorld loadingListener->setProgressRange(cell->count()); - mNavigator.setWorldspace( - Misc::StringUtils::lowerCase(cell->getCell()->getNameId()), navigatorUpdateGuard.get()); + mNavigator.setWorldspace(Misc::StringUtils::lowerCase(cell->getCell()->getWorldSpace().getRefIdString()), + navigatorUpdateGuard.get()); mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get()); // Load cell. diff --git a/components/esm4/loadcell.cpp b/components/esm4/loadcell.cpp index fc199be6fc..917172265d 100644 --- a/components/esm4/loadcell.cpp +++ b/components/esm4/loadcell.cpp @@ -53,7 +53,7 @@ void ESM4::Cell::load(ESM4::Reader& reader) reader.adjustFormId(mFormId); mId = ESM::RefId::formIdRefId(mFormId); mFlags = reader.hdr().record.flags; - mParent = reader.currWorld(); + mParent = ESM::RefId::formIdRefId(reader.currWorld()); reader.clearCellGrid(); // clear until XCLC FIXME: somehow do this automatically? diff --git a/components/esm4/loadcell.hpp b/components/esm4/loadcell.hpp index 264746a1c6..5fd077b068 100644 --- a/components/esm4/loadcell.hpp +++ b/components/esm4/loadcell.hpp @@ -68,7 +68,7 @@ namespace ESM4 ESM::RefId mId; std::uint32_t mFlags; // from the header, see enum type RecordFlag for details - FormId mParent; // world formId (for grouping cells), from the loading sequence + ESM::RefId mParent; // world formId (for grouping cells), from the loading sequence std::string mEditorId; std::string mFullName;