From 481f23d955a8802b36cf7cc13ecb35c6c574b551 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 7 Sep 2015 16:05:51 +0200 Subject: [PATCH] Implement framerate limit setting The framerate limit can be used to reduce strain on the CPU and GPU, in a way similar to VSync, but without the increased input lag that is typical with VSync. --- apps/openmw/engine.cpp | 12 ++++++++++++ files/settings-default.cfg | 3 +++ 2 files changed, 15 insertions(+) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 6801363b1..79c8c4cc9 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -676,6 +676,7 @@ void OMW::Engine::go() // Start the main rendering loop osg::Timer frameTimer; double simulationTime = 0.0; + float framerateLimit = Settings::Manager::getFloat("framerate limit", "Video"); while (!mViewer->done() && !mEnvironment.getStateManager()->hasQuitRequest()) { double dt = frameTimer.time_s(); @@ -693,6 +694,7 @@ void OMW::Engine::go() if (!mEnvironment.getInputManager()->isWindowVisible()) { OpenThreads::Thread::microSleep(5000); + continue; } else { @@ -700,6 +702,16 @@ void OMW::Engine::go() mViewer->updateTraversal(); mViewer->renderingTraversals(); } + + if (framerateLimit > 0.f) + { + double thisFrameTime = frameTimer.time_s(); + double minFrameTime = 1.0 / framerateLimit; + if (thisFrameTime < minFrameTime) + { + OpenThreads::Thread::microSleep(1000*1000*(minFrameTime-thisFrameTime)); + } + } } // Save user settings diff --git a/files/settings-default.cfg b/files/settings-default.cfg index f2b6aa34f..c793225c2 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -20,6 +20,9 @@ vsync = false gamma = 1.00 contrast = 1.00 +# Maximum framerate in frames per second, 0 = unlimited +framerate limit = 0 + [GUI] scaling factor = 1.0