From 950cc7be83b0b5b54a93ae1ac848af80f1f2e4ca Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 29 Jun 2023 11:09:06 +0200 Subject: [PATCH] gets the right worldspace when calculating exterior positions. --- apps/openmw/mwworld/scene.cpp | 7 ++++--- apps/openmw/mwworld/scene.hpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 6925933876..766aaf627e 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -577,7 +577,7 @@ namespace MWWorld if (mRendering.pagingUnlockCache()) mPreloader->abortTerrainPreloadExcept(nullptr); if (!mPreloader->isTerrainLoaded(std::make_pair(pos, newGrid), mRendering.getReferenceTime())) - preloadTerrain(pos, true); + preloadTerrain(pos, playerCellIndex.mWorldspace, true); mPagedRefs.clear(); mRendering.getPagedRefnums(newGrid, mPagedRefs); @@ -1205,10 +1205,11 @@ namespace MWWorld mPreloader->preload(cell, mRendering.getReferenceTime()); } - void Scene::preloadTerrain(const osg::Vec3f& pos, bool sync) + void Scene::preloadTerrain(const osg::Vec3f& pos, ESM::RefId worldspace, bool sync) { + ESM::ExteriorCellLocation cellPos = ESM::positionToExteriorCellLocation(pos.x(), pos.y(), worldspace); std::vector vec; - vec.emplace_back(pos, gridCenterToBounds(getNewGridCenter(pos))); + vec.emplace_back(pos, gridCenterToBounds({ cellPos.mX, cellPos.mY })); mPreloader->abortTerrainPreloadExcept(vec.data()); mPreloader->setTerrainPreloadPositions(vec); if (!sync) diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index e6b6e942fb..f3dd377845 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -145,7 +145,7 @@ namespace MWWorld ~Scene(); void preloadCell(MWWorld::CellStore& cell, bool preloadSurrounding = false); - void preloadTerrain(const osg::Vec3f& pos, bool sync = false); + void preloadTerrain(const osg::Vec3f& pos, ESM::RefId worldspace, bool sync = false); void reloadTerrain(); void playerMoved(const osg::Vec3f& pos); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 77a225ab09..c83c2f0fd2 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -513,7 +513,8 @@ namespace MWWorld if (getPlayerPtr().isInCell()) { if (getPlayerPtr().getCell()->isExterior()) - mWorldScene->preloadTerrain(getPlayerPtr().getRefData().getPosition().asVec3()); + mWorldScene->preloadTerrain(getPlayerPtr().getRefData().getPosition().asVec3(), + getPlayerPtr().getCell()->getCell()->getWorldSpace()); mWorldScene->preloadCell(*getPlayerPtr().getCell(), true); } break;