1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 03:32:36 +00:00

Should resolve #5493 by better supporting objects that are placed across cells.

This commit is contained in:
bzzt lost a hitlab login 2020-07-09 23:17:01 +02:00 committed by Bret Curtis
parent 46db69a349
commit 4ea018c594
3 changed files with 19 additions and 6 deletions

View File

@ -670,16 +670,27 @@ namespace MWRender
{ {
if (mActiveGridOnly && !std::get<2>(id)) return false; if (mActiveGridOnly && !std::get<2>(id)) return false;
pos /= ESM::Land::REAL_SIZE; pos /= ESM::Land::REAL_SIZE;
clampToCell(pos);
osg::Vec2f center = std::get<0>(id); osg::Vec2f center = std::get<0>(id);
float halfSize = std::get<1>(id)/2; 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; 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::Vec3f mPosition;
osg::Vec2i mCell;
std::set<MWRender::ChunkId> mToClear; std::set<MWRender::ChunkId> mToClear;
bool mActiveGridOnly = false; 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)) if (!typeFilter(type, false))
return false; return false;
@ -693,6 +704,7 @@ namespace MWRender
ClearCacheFunctor ccf; ClearCacheFunctor ccf;
ccf.mPosition = pos; ccf.mPosition = pos;
ccf.mCell = cell;
mCache->call(ccf); mCache->call(ccf);
if (ccf.mToClear.empty()) return false; if (ccf.mToClear.empty()) return false;
for (auto chunk : ccf.mToClear) for (auto chunk : ccf.mToClear)
@ -700,7 +712,7 @@ namespace MWRender
return true; 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)) if (!typeFilter(type, false))
return false; return false;
@ -713,6 +725,7 @@ namespace MWRender
ClearCacheFunctor ccf; ClearCacheFunctor ccf;
ccf.mPosition = pos; ccf.mPosition = pos;
ccf.mCell = cell;
ccf.mActiveGridOnly = true; ccf.mActiveGridOnly = true;
mCache->call(ccf); mCache->call(ccf);
if (ccf.mToClear.empty()) return false; if (ccf.mToClear.empty()) return false;

View File

@ -34,10 +34,10 @@ namespace MWRender
virtual unsigned int getNodeMask() override; virtual unsigned int getNodeMask() override;
/// @return true if view needs rebuild /// @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 /// @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(); void clear();

View File

@ -1517,7 +1517,7 @@ namespace MWRender
{ {
if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging) if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging)
return false; 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(); mTerrain->rebuildViews();
return true; return true;
@ -1530,7 +1530,7 @@ namespace MWRender
return; return;
const ESM::RefNum & refnum = ptr.getCellRef().getRefNum(); const ESM::RefNum & refnum = ptr.getCellRef().getRefNum();
if (!refnum.hasContentFile()) return; 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(); mTerrain->rebuildViews();
} }
bool RenderingManager::pagingUnlockCache() bool RenderingManager::pagingUnlockCache()