From 4ea018c594929e4beacad0009942a094b45fddd8 Mon Sep 17 00:00:00 2001 From: bzzt lost a hitlab login Date: Thu, 9 Jul 2020 23:17:01 +0200 Subject: [PATCH 1/2] Should resolve #5493 by better supporting objects that are placed across cells. --- apps/openmw/mwrender/objectpaging.cpp | 17 +++++++++++++++-- apps/openmw/mwrender/objectpaging.hpp | 4 ++-- apps/openmw/mwrender/renderingmanager.cpp | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index fd12ad367..0f7e1c422 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -670,16 +670,27 @@ namespace MWRender { if (mActiveGridOnly && !std::get<2>(id)) return false; pos /= ESM::Land::REAL_SIZE; + clampToCell(pos); osg::Vec2f center = std::get<0>(id); float halfSize = std::get<1>(id)/2; return pos.x() >= center.x()-halfSize && pos.y() >= center.y()-halfSize && pos.x() <= center.x()+halfSize && pos.y() <= center.y()+halfSize; } + void clampToCell(osg::Vec3f& cellPos) + { + osg::Vec2i min (mCell.x(), mCell.y()); + osg::Vec2i max (mCell.x()+1, mCell.y()+1); + if (cellPos.x() < min.x()) cellPos.x() = min.x(); + if (cellPos.x() > max.x()) cellPos.x() = max.x(); + if (cellPos.y() < min.y()) cellPos.y() = min.y(); + if (cellPos.y() > max.y()) cellPos.y() = max.y(); + } osg::Vec3f mPosition; + osg::Vec2i mCell; std::set mToClear; bool mActiveGridOnly = false; }; - bool ObjectPaging::enableObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, bool enabled) + bool ObjectPaging::enableObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled) { if (!typeFilter(type, false)) return false; @@ -693,6 +704,7 @@ namespace MWRender ClearCacheFunctor ccf; ccf.mPosition = pos; + ccf.mCell = cell; mCache->call(ccf); if (ccf.mToClear.empty()) return false; for (auto chunk : ccf.mToClear) @@ -700,7 +712,7 @@ namespace MWRender return true; } - bool ObjectPaging::blacklistObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos) + bool ObjectPaging::blacklistObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, const osg::Vec2i& cell) { if (!typeFilter(type, false)) return false; @@ -713,6 +725,7 @@ namespace MWRender ClearCacheFunctor ccf; ccf.mPosition = pos; + ccf.mCell = cell; ccf.mActiveGridOnly = true; mCache->call(ccf); if (ccf.mToClear.empty()) return false; diff --git a/apps/openmw/mwrender/objectpaging.hpp b/apps/openmw/mwrender/objectpaging.hpp index 2ca302038..18fa30289 100644 --- a/apps/openmw/mwrender/objectpaging.hpp +++ b/apps/openmw/mwrender/objectpaging.hpp @@ -34,10 +34,10 @@ namespace MWRender virtual unsigned int getNodeMask() override; /// @return true if view needs rebuild - bool enableObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, bool enabled); + bool enableObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled); /// @return true if view needs rebuild - bool blacklistObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos); + bool blacklistObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, const osg::Vec2i& cell); void clear(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 0c6e48645..a7d9003dc 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1517,7 +1517,7 @@ namespace MWRender { if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging) return false; - if (mObjectPaging->enableObject(type, ptr.getCellRef().getRefNum(), ptr.getCellRef().getPosition().asVec3(), enabled)) + if (mObjectPaging->enableObject(type, ptr.getCellRef().getRefNum(), ptr.getCellRef().getPosition().asVec3(), osg::Vec2i(ptr.getCell()->getCell()->getGridX(), ptr.getCell()->getCell()->getGridY()), enabled)) { mTerrain->rebuildViews(); return true; @@ -1530,7 +1530,7 @@ namespace MWRender return; const ESM::RefNum & refnum = ptr.getCellRef().getRefNum(); if (!refnum.hasContentFile()) return; - if (mObjectPaging->blacklistObject(type, refnum, ptr.getCellRef().getPosition().asVec3())) + if (mObjectPaging->blacklistObject(type, refnum, ptr.getCellRef().getPosition().asVec3(), osg::Vec2i(ptr.getCell()->getCell()->getGridX(), ptr.getCell()->getCell()->getGridY()))) mTerrain->rebuildViews(); } bool RenderingManager::pagingUnlockCache() From fd61ebf6abf6e2077e0e0d23f7ab451e37823b3c Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Fri, 10 Jul 2020 00:44:54 +0200 Subject: [PATCH 2/2] remove big white blob of space --- apps/openmw/mwrender/renderingmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index a7d9003dc..9876fae54 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1517,7 +1517,7 @@ namespace MWRender { if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging) return false; - if (mObjectPaging->enableObject(type, ptr.getCellRef().getRefNum(), ptr.getCellRef().getPosition().asVec3(), osg::Vec2i(ptr.getCell()->getCell()->getGridX(), ptr.getCell()->getCell()->getGridY()), enabled)) + if (mObjectPaging->enableObject(type, ptr.getCellRef().getRefNum(), ptr.getCellRef().getPosition().asVec3(), osg::Vec2i(ptr.getCell()->getCell()->getGridX(), ptr.getCell()->getCell()->getGridY()), enabled)) { mTerrain->rebuildViews(); return true;