From 1bbf4a3acfb0cb7e43dfce0d017d6000171f4f81 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sun, 19 Feb 2023 19:19:11 +0100 Subject: [PATCH] fixes teleport to exterior cells. fixes linux compile fix compile bis --- apps/essimporter/converter.cpp | 3 ++- apps/openmw/mwworld/cell.hpp | 2 +- apps/openmw/mwworld/cellref.cpp | 23 ++++------------------- apps/openmw/mwworld/scene.cpp | 8 +++++--- apps/openmw/mwworld/scene.hpp | 3 ++- apps/openmw/mwworld/worldimp.cpp | 17 +++++++++++++---- apps/openmw/mwworld/worldmodel.cpp | 4 ++-- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/apps/essimporter/converter.cpp b/apps/essimporter/converter.cpp index 0da74d3251..8dcfcfe832 100644 --- a/apps/essimporter/converter.cpp +++ b/apps/essimporter/converter.cpp @@ -301,7 +301,8 @@ namespace ESSImport marker.mWorldX = notepos[0]; marker.mWorldY = notepos[1]; marker.mNote = note; - marker.mCell = cell.getCellId(); + marker.mCellId = cell.getCellId(); + marker.mCell = cell.getCellId().getCellRefId(); mMarkers.push_back(marker); } diff --git a/apps/openmw/mwworld/cell.hpp b/apps/openmw/mwworld/cell.hpp index 818968fabb..fd391e870b 100644 --- a/apps/openmw/mwworld/cell.hpp +++ b/apps/openmw/mwworld/cell.hpp @@ -49,7 +49,7 @@ namespace MWWorld std::string getDescription() const; const MoodData& getMood() const { return mMood; } float getWaterHeight() const { return mWaterHeight; } - const ESM::RefId& getId() const { return mId; }; + const ESM::RefId& getId() const { return mId; } private: bool mIsExterior; diff --git a/apps/openmw/mwworld/cellref.cpp b/apps/openmw/mwworld/cellref.cpp index a9af6e72a6..02dd0ec4c4 100644 --- a/apps/openmw/mwworld/cellref.cpp +++ b/apps/openmw/mwworld/cellref.cpp @@ -73,25 +73,10 @@ namespace MWWorld ESM::Position CellRef::getDoorDest() const { - auto esm3Visit = [&](const ESM::CellRef& ref) -> ESM::Position { - // So the destinaion pos is always in relationship to the destination cells origin, interior or exterior - // alike - ESM::Position pos = ref.mDoorDest; - if (ref.mDestCell.empty()) // Exterior cell case - { - const osg::Vec2i index = positionToCellIndex(ref.mDoorDest.pos[0], ref.mDoorDest.pos[1]); - pos.pos[0] -= index.x() * Constants::CellSizeInUnits; - pos.pos[1] -= index.y() * Constants::CellSizeInUnits; - } - - return pos; - }; - - return std::visit( - ESM::VisitOverload{ - [&](const ESM4::Reference& ref) { return ref.mDoor.destPos; }, - esm3Visit, - }, + return std::visit(ESM::VisitOverload{ + [&](const ESM4::Reference& ref) { return ref.mDoor.destPos; }, + [&](const ESM::CellRef& ref) -> ESM::Position { return ref.mDoorDest; }, + }, mCellRef.mVariant); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 3d0d97e272..c255618dba 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -920,16 +920,18 @@ namespace MWWorld MWBase::Environment::get().getWorld()->getPostProcessor()->setExteriorFlag(cell->getCell()->isQuasiExterior()); } - void Scene::changeToExteriorCell(const ESM::Position& position, bool adjustPlayerPos, bool changeEvent) + void Scene::changeToExteriorCell( + const ESM::RefId& extCellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent) { - const osg::Vec2i cellIndex = positionToCellIndex(position.pos[0], position.pos[1]); if (changeEvent) MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5); + CellStore* current = mWorld.getWorldModel().getCell(extCellId); + + const osg::Vec2i cellIndex(current->getCell()->getGridX(), current->getCell()->getGridY()); changeCellGrid(position.asVec3(), cellIndex.x(), cellIndex.y(), changeEvent); - CellStore* current = mWorld.getWorldModel().getExterior(cellIndex.x(), cellIndex.y()); changePlayerCell(current, position, adjustPlayerPos); if (changeEvent) diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index d43842fbba..0383d0c888 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -167,7 +167,8 @@ namespace MWWorld ///< Move to interior cell. /// @param changeEvent Set cellChanged flag? - void changeToExteriorCell(const ESM::Position& position, bool adjustPlayerPos, bool changeEvent = true); + void changeToExteriorCell( + const ESM::RefId& extCellId, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent = true); ///< Move to exterior cell. /// @param changeEvent Set cellChanged flag? diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5e29e50bbb..2af2ae7faf 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -378,7 +378,12 @@ namespace MWWorld pos.rot[0] = 0; pos.rot[1] = 0; pos.rot[2] = 0; - mWorldScene->changeToExteriorCell(pos, true); + + osg::Vec2i exteriorCellPos = positionToCellIndex(pos.pos[0], pos.pos[1]); + ESM::CellId CellId; + CellId.mPaged = true; + CellId.mIndex = { exteriorCellPos.x(), exteriorCellPos.y() }; + mWorldScene->changeToExteriorCell(CellId.getCellRefId(), pos, true); } } @@ -981,7 +986,11 @@ namespace MWWorld mRendering->notifyWorldSpaceChanged(); } removeContainerScripts(getPlayerPtr()); - mWorldScene->changeToExteriorCell(position, adjustPlayerPos, changeEvent); + osg::Vec2i exteriorCellPos = positionToCellIndex(position.pos[0], position.pos[1]); + ESM::CellId CellId; + CellId.mPaged = true; + CellId.mIndex = { exteriorCellPos.x(), exteriorCellPos.y() }; + mWorldScene->changeToExteriorCell(CellId.getCellRefId(), position, adjustPlayerPos, changeEvent); addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell()); mRendering->getCamera()->instantTransition(); } @@ -1018,7 +1027,7 @@ namespace MWWorld } removeContainerScripts(getPlayerPtr()); if (exteriorCell) - mWorldScene->changeToExteriorCell(position, adjustPlayerPos, changeEvent); + mWorldScene->changeToExteriorCell(cellId, position, adjustPlayerPos, changeEvent); else mWorldScene->changeToInteriorCell(destinationCell->getNameId(), position, adjustPlayerPos, changeEvent); addContainerScripts(getPlayerPtr(), getPlayerPtr().getCell()); @@ -1194,7 +1203,7 @@ namespace MWWorld if (mWorldScene->isCellActive(*newCell)) mWorldScene->changePlayerCell(newCell, pos, false); else - mWorldScene->changeToExteriorCell(pos, false); + mWorldScene->changeToExteriorCell(newCell->getCell()->getId(), pos, false); } addContainerScripts(getPlayerPtr(), newCell); newPtr = getPlayerPtr(); diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index e98ce190be..3e22ad02a6 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -267,11 +267,11 @@ MWWorld::CellStore* MWWorld::WorldModel::getCell(const ESM::RefId& id) { std::pair coord = std::make_pair(newCellStore->getCell()->getGridX(), newCellStore->getCell()->getGridY()); - mExteriors.emplace(coord, newCellStore).first; + mExteriors.emplace(coord, newCellStore); } else { - mInteriors.emplace(newCellStore->getCell()->getNameId(), newCellStore).first; + mInteriors.emplace(newCellStore->getCell()->getNameId(), newCellStore); } if (newCellStore->getState() != CellStore::State_Loaded) {