1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Reduce the FPS when the window is unfocused (#8837)

This commit is contained in:
HybridDog 2020-10-03 18:33:51 +02:00 committed by GitHub
parent 4b423ee9b1
commit 9dc29a75b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 16 deletions

View file

@ -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);
}
}