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

@ -606,8 +606,8 @@ arm_inertia (Arm inertia) bool true
# to not waste CPU power for no benefit.
fps_max (Maximum FPS) int 60 1
# Maximum FPS when game is paused.
pause_fps_max (FPS in pause menu) int 20 1
# Maximum FPS when the window is not focused, or when the game is paused.
fps_max_unfocused (FPS when unfocused or paused) int 20 1
# Open the pause menu when the window's focus is lost. Does not pause if a formspec is
# open.

@ -3996,9 +3996,10 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
else
fps_timings->busy_time = 0;
u32 frametime_min = 1000 / (g_menumgr.pausesGame()
? g_settings->getFloat("pause_fps_max")
: g_settings->getFloat("fps_max"));
u32 frametime_min = 1000 / (
device->isWindowFocused() && !g_menumgr.pausesGame()
? g_settings->getFloat("fps_max")
: g_settings->getFloat("fps_max_unfocused"));
if (fps_timings->busy_time < frametime_min) {
fps_timings->sleep_time = frametime_min - fps_timings->busy_time;

@ -165,7 +165,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("tooltip_show_delay", "400");
settings->setDefault("tooltip_append_itemname", "false");
settings->setDefault("fps_max", "60");
settings->setDefault("pause_fps_max", "20");
settings->setDefault("fps_max_unfocused", "20");
settings->setDefault("viewing_range", "100");
#if ENABLE_GLES
settings->setDefault("near_plane", "0.1");
@ -477,7 +477,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("max_block_generate_distance", "5");
settings->setDefault("enable_3d_clouds", "false");
settings->setDefault("fps_max", "30");
settings->setDefault("pause_fps_max", "10");
settings->setDefault("fps_max_unfocused", "10");
settings->setDefault("max_objects_per_block", "20");
settings->setDefault("sqlite_synchronous", "1");
settings->setDefault("server_map_save_interval", "15");

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

@ -277,7 +277,7 @@ private:
/** do preprocessing for cloud subsystem */
void cloudPreProcess();
/** do postprocessing for cloud subsystem */
void cloudPostProcess();
void cloudPostProcess(u32 frametime_min, IrrlichtDevice *device);
/** internam data required for drawing clouds */
struct clouddata {