diff options
author | HybridDog <3192173+HybridDog@users.noreply.github.com> | 2020-10-03 18:33:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-03 17:33:51 +0100 |
commit | 9dc29a75b416c6dab27ce93d0129383309cbf2c2 (patch) | |
tree | dabdf0456227196499a02a2db8717788dd80a1f7 /src/gui/guiEngine.cpp | |
parent | 4b423ee9b12aabe6ccd6a8e7dbc7db1d89dc365b (diff) | |
download | minetest-9dc29a75b416c6dab27ce93d0129383309cbf2c2.tar.gz minetest-9dc29a75b416c6dab27ce93d0129383309cbf2c2.tar.bz2 minetest-9dc29a75b416c6dab27ce93d0129383309cbf2c2.zip |
Reduce the FPS when the window is unfocused (#8837)
Diffstat (limited to 'src/gui/guiEngine.cpp')
-rw-r--r-- | src/gui/guiEngine.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index b40707d01..4a13f0b11 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -297,10 +297,14 @@ void GUIEngine::run() driver->endScene(); + IrrlichtDevice *device = RenderingEngine::get_raw_device(); + u32 frametime_min = 1000 / (device->isWindowFocused() + ? g_settings->getFloat("fps_max") + : g_settings->getFloat("fps_max_unfocused")); if (m_clouds_enabled) - cloudPostProcess(); + cloudPostProcess(frametime_min, device); else - sleep_ms(25); + sleep_ms(frametime_min); m_script->step(); @@ -367,9 +371,8 @@ void GUIEngine::cloudPreProcess() } /******************************************************************************/ -void GUIEngine::cloudPostProcess() +void GUIEngine::cloudPostProcess(u32 frametime_min, IrrlichtDevice *device) { - float fps_max = g_settings->getFloat("pause_fps_max"); // Time of frame without fps limit u32 busytime_u32; @@ -380,12 +383,10 @@ void GUIEngine::cloudPostProcess() else busytime_u32 = 0; - // FPS limiter - u32 frametime_min = 1000./fps_max; - + // FPS limit if (busytime_u32 < frametime_min) { u32 sleeptime = frametime_min - busytime_u32; - RenderingEngine::get_raw_device()->sleep(sleeptime); + device->sleep(sleeptime); } } |