Make the CompositeMapRenderer use available time and add related setting

pull/385/head
scrawl 7 years ago
parent a708ac488e
commit 123f7b83d5
No known key found for this signature in database
GPG Key ID: 2E6CC3676024C402

@ -163,7 +163,6 @@ namespace MWGui
if (mViewer->getIncrementalCompileOperation())
{
mViewer->getIncrementalCompileOperation()->setMaximumNumOfObjectsToCompilePerFrame(100);
mViewer->getIncrementalCompileOperation()->setTargetFrameRate(getTargetFrameRate());
}
// Assign dummy bounding sphere callback to avoid the bounding sphere of the entire scene being recomputed after each frame of loading

@ -205,7 +205,10 @@ namespace MWRender
mObjects.reset(new Objects(mResourceSystem, sceneRoot, mUnrefQueue.get()));
if (getenv("OPENMW_DONT_PRECOMPILE") == NULL)
{
mViewer->setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation);
mViewer->getIncrementalCompileOperation()->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells"));
}
mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation());
@ -223,6 +226,7 @@ namespace MWRender
else
mTerrain.reset(new Terrain::TerrainGrid(sceneRoot, mRootNode, mResourceSystem, mTerrainStorage, Mask_Terrain, Mask_PreCompile));
mTerrain->setDefaultViewer(mViewer->getCamera());
mTerrain->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells"));
mCamera.reset(new Camera(mViewer->getCamera()));

@ -10,7 +10,8 @@ namespace Terrain
{
CompositeMapRenderer::CompositeMapRenderer()
: mTimeAvailable(0.0005)
: mTargetFrameRate(120)
, mMinimumTimeAvailable(0.0025)
{
setSupportsDisplayList(false);
setCullingActive(false);
@ -22,6 +23,14 @@ CompositeMapRenderer::CompositeMapRenderer()
void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const
{
double dt = mTimer.time_s();
dt = std::min(dt, 0.2);
mTimer.setStartTick();
double targetFrameTime = 1.0/static_cast<double>(mTargetFrameRate);
double conservativeTimeRatio(0.75);
double availableTime = std::max((targetFrameTime - dt)*conservativeTimeRatio,
mMinimumTimeAvailable);
mCompiled.clear();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
@ -39,7 +48,7 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const
mImmediateCompileSet.erase(mImmediateCompileSet.begin());
}
double timeLeft = mTimeAvailable;
double timeLeft = availableTime;
while (!mCompileSet.empty() && timeLeft > 0)
{
@ -126,9 +135,14 @@ void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo &
ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId);
}
void CompositeMapRenderer::setTimeAvailableForCompile(double time)
void CompositeMapRenderer::setMinimumTimeAvailableForCompile(double time)
{
mMinimumTimeAvailable = time;
}
void CompositeMapRenderer::setTargetFrameRate(float framerate)
{
mTimeAvailable = time;
mTargetFrameRate = framerate;
}
void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool immediate)

@ -40,7 +40,10 @@ namespace Terrain
void compile(CompositeMap& compositeMap, osg::RenderInfo& renderInfo, double* timeLeft) const;
/// Set the available time in seconds for compiling (non-immediate) composite maps each frame
void setTimeAvailableForCompile(double time);
void setMinimumTimeAvailableForCompile(double time);
/// If current frame rate is higher than this, the extra time will be set aside to do more compiling
void setTargetFrameRate(float framerate);
/// Add a composite map to be rendered
void addCompositeMap(CompositeMap* map, bool immediate=false);
@ -51,7 +54,9 @@ namespace Terrain
unsigned int getCompileSetSize() const;
private:
double mTimeAvailable;
float mTargetFrameRate;
double mMinimumTimeAvailable;
mutable osg::Timer mTimer;
typedef std::set<osg::ref_ptr<CompositeMap> > CompileSet;

@ -65,6 +65,11 @@ World::~World()
delete mStorage;
}
void World::setTargetFrameRate(float rate)
{
mCompositeMapRenderer->setTargetFrameRate(rate);
}
float World::getHeightAt(const osg::Vec3f &worldPos)
{
return mStorage->getHeightAt(worldPos);

@ -57,6 +57,9 @@ namespace Terrain
World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask);
virtual ~World();
/// See CompositeMapRenderer::setTargetFrameRate
void setTargetFrameRate(float rate);
/// Apply the scene manager's texture filtering settings to all cached textures.
/// @note Thread safe.
void updateTextureFiltering();

@ -178,6 +178,14 @@ cache expiry delay
The amount of time (in seconds) that a preloaded texture or object will stay in cache
after it is no longer referenced or required, for example, when all cells containing this texture have been unloaded.
target framerate
----------------
:Type: floating point
:Range: >0
:Default: 60
Affects the time to be set aside each frame for graphics preloading operations. The game will distribute the preloading over several frames so as to not go under the specified framerate. For best results, set this value to the monitor's refresh rate. If you still experience stutters on turning around, you can try a lower value, although the framerate during loading will suffer a bit in that case.
pointers cache size
------------------

@ -79,6 +79,9 @@ prediction time = 1
# How long to keep models/textures/collision shapes in cache after they're no longer referenced/required (in seconds)
cache expiry delay = 5
# Affects the time to be set aside each frame for graphics preloading operations
target framerate = 60
# The count of pointers, that will be saved for a faster search by object ID.
pointers cache size = 40

Loading…
Cancel
Save