diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 4753c39f2..2c12547fd 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -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 diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 4fbcdc4d5..3281a787b 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -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())); diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index 653ac53ec..6626a5713 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -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(mTargetFrameRate); + double conservativeTimeRatio(0.75); + double availableTime = std::max((targetFrameTime - dt)*conservativeTimeRatio, + mMinimumTimeAvailable); + mCompiled.clear(); OpenThreads::ScopedLock 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) diff --git a/components/terrain/compositemaprenderer.hpp b/components/terrain/compositemaprenderer.hpp index 15e939389..54e158ed4 100644 --- a/components/terrain/compositemaprenderer.hpp +++ b/components/terrain/compositemaprenderer.hpp @@ -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 > CompileSet; diff --git a/components/terrain/world.cpp b/components/terrain/world.cpp index 335bb496b..213d5c8a7 100644 --- a/components/terrain/world.cpp +++ b/components/terrain/world.cpp @@ -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); diff --git a/components/terrain/world.hpp b/components/terrain/world.hpp index e1c3828fc..688ed84d5 100644 --- a/components/terrain/world.hpp +++ b/components/terrain/world.hpp @@ -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(); diff --git a/docs/source/reference/modding/settings/cells.rst b/docs/source/reference/modding/settings/cells.rst index d2e7cf5be..aa5d43231 100644 --- a/docs/source/reference/modding/settings/cells.rst +++ b/docs/source/reference/modding/settings/cells.rst @@ -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 ------------------ diff --git a/files/settings-default.cfg b/files/settings-default.cfg index c694d4db2..8a28c42e4 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -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