mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 00:26:50 +02:00
Reduce the FPS when the window is unfocused (#8837)
This commit is contained in:
parent
4b423ee9b1
commit
9dc29a75b4
@ -606,8 +606,8 @@ arm_inertia (Arm inertia) bool true
|
|||||||
# to not waste CPU power for no benefit.
|
# to not waste CPU power for no benefit.
|
||||||
fps_max (Maximum FPS) int 60 1
|
fps_max (Maximum FPS) int 60 1
|
||||||
|
|
||||||
# Maximum FPS when game is paused.
|
# Maximum FPS when the window is not focused, or when the game is paused.
|
||||||
pause_fps_max (FPS in pause menu) int 20 1
|
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 the pause menu when the window's focus is lost. Does not pause if a formspec is
|
||||||
# open.
|
# open.
|
||||||
|
@ -3996,9 +3996,10 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
|
|||||||
else
|
else
|
||||||
fps_timings->busy_time = 0;
|
fps_timings->busy_time = 0;
|
||||||
|
|
||||||
u32 frametime_min = 1000 / (g_menumgr.pausesGame()
|
u32 frametime_min = 1000 / (
|
||||||
? g_settings->getFloat("pause_fps_max")
|
device->isWindowFocused() && !g_menumgr.pausesGame()
|
||||||
: g_settings->getFloat("fps_max"));
|
? g_settings->getFloat("fps_max")
|
||||||
|
: g_settings->getFloat("fps_max_unfocused"));
|
||||||
|
|
||||||
if (fps_timings->busy_time < frametime_min) {
|
if (fps_timings->busy_time < frametime_min) {
|
||||||
fps_timings->sleep_time = frametime_min - fps_timings->busy_time;
|
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_show_delay", "400");
|
||||||
settings->setDefault("tooltip_append_itemname", "false");
|
settings->setDefault("tooltip_append_itemname", "false");
|
||||||
settings->setDefault("fps_max", "60");
|
settings->setDefault("fps_max", "60");
|
||||||
settings->setDefault("pause_fps_max", "20");
|
settings->setDefault("fps_max_unfocused", "20");
|
||||||
settings->setDefault("viewing_range", "100");
|
settings->setDefault("viewing_range", "100");
|
||||||
#if ENABLE_GLES
|
#if ENABLE_GLES
|
||||||
settings->setDefault("near_plane", "0.1");
|
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("max_block_generate_distance", "5");
|
||||||
settings->setDefault("enable_3d_clouds", "false");
|
settings->setDefault("enable_3d_clouds", "false");
|
||||||
settings->setDefault("fps_max", "30");
|
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("max_objects_per_block", "20");
|
||||||
settings->setDefault("sqlite_synchronous", "1");
|
settings->setDefault("sqlite_synchronous", "1");
|
||||||
settings->setDefault("server_map_save_interval", "15");
|
settings->setDefault("server_map_save_interval", "15");
|
||||||
|
@ -297,10 +297,14 @@ void GUIEngine::run()
|
|||||||
|
|
||||||
driver->endScene();
|
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)
|
if (m_clouds_enabled)
|
||||||
cloudPostProcess();
|
cloudPostProcess(frametime_min, device);
|
||||||
else
|
else
|
||||||
sleep_ms(25);
|
sleep_ms(frametime_min);
|
||||||
|
|
||||||
m_script->step();
|
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
|
// Time of frame without fps limit
|
||||||
u32 busytime_u32;
|
u32 busytime_u32;
|
||||||
|
|
||||||
@ -380,12 +383,10 @@ void GUIEngine::cloudPostProcess()
|
|||||||
else
|
else
|
||||||
busytime_u32 = 0;
|
busytime_u32 = 0;
|
||||||
|
|
||||||
// FPS limiter
|
// FPS limit
|
||||||
u32 frametime_min = 1000./fps_max;
|
|
||||||
|
|
||||||
if (busytime_u32 < frametime_min) {
|
if (busytime_u32 < frametime_min) {
|
||||||
u32 sleeptime = frametime_min - busytime_u32;
|
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 */
|
/** do preprocessing for cloud subsystem */
|
||||||
void cloudPreProcess();
|
void cloudPreProcess();
|
||||||
/** do postprocessing for cloud subsystem */
|
/** do postprocessing for cloud subsystem */
|
||||||
void cloudPostProcess();
|
void cloudPostProcess(u32 frametime_min, IrrlichtDevice *device);
|
||||||
|
|
||||||
/** internam data required for drawing clouds */
|
/** internam data required for drawing clouds */
|
||||||
struct clouddata {
|
struct clouddata {
|
||||||
|
Loading…
Reference in New Issue
Block a user