mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
fixes stutters => bugs in the way cells were updated.
This commit is contained in:
parent
0e4d21a40c
commit
a9e0489867
2 changed files with 17 additions and 9 deletions
|
@ -1363,6 +1363,9 @@ namespace MWRender
|
|||
mTerrainStorage.get(), Mask_Terrain, worldspace, Mask_PreCompile, Mask_Debug);
|
||||
|
||||
newTerrain->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells"));
|
||||
float distanceMult = std::cos(osg::DegreesToRadians(std::min(mFieldOfView, 140.f)) / 2.f);
|
||||
newTerrain->setViewDistance(mViewDistance * (distanceMult ? 1.f / distanceMult : 1.f));
|
||||
|
||||
mWorldspaceTerrains[worldspace] = std::move(newTerrain);
|
||||
return mWorldspaceTerrains[worldspace].get();
|
||||
}
|
||||
|
|
|
@ -39,13 +39,14 @@ namespace Terrain
|
|||
class DefaultLodCallback : public LodCallback
|
||||
{
|
||||
public:
|
||||
DefaultLodCallback(
|
||||
float factor, float minSize, float viewDistance, const osg::Vec4i& grid, float distanceModifier = 0.f)
|
||||
DefaultLodCallback(float factor, float minSize, float viewDistance, const osg::Vec4i& grid, int cellSizeInUnits,
|
||||
float distanceModifier = 0.f)
|
||||
: mFactor(factor)
|
||||
, mMinSize(minSize)
|
||||
, mViewDistance(viewDistance)
|
||||
, mActiveGrid(grid)
|
||||
, mDistanceModifier(distanceModifier)
|
||||
, mCellSizeInUnits(cellSizeInUnits)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,8 @@ namespace Terrain
|
|||
dist = std::max(0.f, dist + mDistanceModifier);
|
||||
if (dist > mViewDistance && !activeGrid) // for Scene<->ObjectPaging sync the activegrid must remain loaded
|
||||
return StopTraversal;
|
||||
return getNativeLodLevel(node, mMinSize) <= convertDistanceToLodLevel(dist, mMinSize, mFactor)
|
||||
return getNativeLodLevel(node, mMinSize)
|
||||
<= convertDistanceToLodLevel(dist, mMinSize, mFactor, mCellSizeInUnits)
|
||||
? StopTraversalAndUse
|
||||
: Deeper;
|
||||
}
|
||||
|
@ -77,9 +79,9 @@ namespace Terrain
|
|||
{
|
||||
return Log2(static_cast<unsigned int>(node->getSize() / minSize));
|
||||
}
|
||||
static unsigned int convertDistanceToLodLevel(float dist, float minSize, float factor)
|
||||
static unsigned int convertDistanceToLodLevel(float dist, float minSize, float factor, int cellSize)
|
||||
{
|
||||
return Log2(static_cast<unsigned int>(dist / (Constants::CellSizeInUnits * minSize * factor)));
|
||||
return Log2(static_cast<unsigned int>(dist / (cellSize * minSize * factor)));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -88,6 +90,7 @@ namespace Terrain
|
|||
float mViewDistance;
|
||||
osg::Vec4i mActiveGrid;
|
||||
float mDistanceModifier;
|
||||
int mCellSizeInUnits;
|
||||
};
|
||||
|
||||
class RootNode : public QuadTreeNode
|
||||
|
@ -471,7 +474,8 @@ namespace Terrain
|
|||
if (needsUpdate)
|
||||
{
|
||||
vd->reset();
|
||||
DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, mActiveGrid);
|
||||
DefaultLodCallback lodCallback(
|
||||
mLodFactor, mMinSize, mViewDistance, mActiveGrid, ESM::getCellSize(mWorldspace));
|
||||
mRootNode->traverseNodes(vd, viewPoint, &lodCallback);
|
||||
}
|
||||
|
||||
|
@ -549,7 +553,7 @@ namespace Terrain
|
|||
distanceModifier = 1024;
|
||||
else if (pass == 2)
|
||||
distanceModifier = -1024;
|
||||
DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, distanceModifier);
|
||||
DefaultLodCallback lodCallback(mLodFactor, mMinSize, mViewDistance, grid, cellWorldSize, distanceModifier);
|
||||
mRootNode->traverseNodes(vd, viewPoint, &lodCallback);
|
||||
|
||||
if (pass == 0)
|
||||
|
@ -605,8 +609,9 @@ namespace Terrain
|
|||
mChunkManagers.push_back(m);
|
||||
mTerrainRoot->setNodeMask(mTerrainRoot->getNodeMask() | m->getNodeMask());
|
||||
if (m->getViewDistance())
|
||||
m->setMaxLodLevel(DefaultLodCallback::convertDistanceToLodLevel(
|
||||
m->getViewDistance() + mViewDataMap->getReuseDistance(), mMinSize, mLodFactor));
|
||||
m->setMaxLodLevel(
|
||||
DefaultLodCallback::convertDistanceToLodLevel(m->getViewDistance() + mViewDataMap->getReuseDistance(),
|
||||
mMinSize, ESM::getCellSize(mWorldspace), mLodFactor));
|
||||
}
|
||||
|
||||
void QuadTreeWorld::rebuildViews()
|
||||
|
|
Loading…
Reference in a new issue