Index: binaries/data/config/default.cfg =================================================================== --- binaries/data/config/default.cfg +++ binaries/data/config/default.cfg @@ -30,7 +30,7 @@ showdetailedtooltips = false ; Pause the game on window focus loss (Only applicable to single player mode) -pauseonfocusloss = true +pausegameonfocusloss = true ; Persist settings after leaving the game setup screen persistmatchsettings = true @@ -128,6 +128,9 @@ ; Color of the sky (in "r g b" format) skycolor = "0 0 0" +; Pause rendering of the game when window loses focus. +pauserendereronfocusloss = false + [adaptivefps] session = 60 ; Throttle FPS in running games (prevents 100% CPU workload). menu = 30 ; Throttle FPS in menus only. Index: binaries/data/mods/public/gui/options/options.json =================================================================== --- binaries/data/mods/public/gui/options/options.json +++ binaries/data/mods/public/gui/options/options.json @@ -25,7 +25,8 @@ "type": "boolean", "label": "Background Pause", "tooltip": "Pause single player games when window loses focus", - "config": "pauseonfocusloss" + "config": "pausegameonfocusloss", + "function": "SetPauseGameOnFocusLossEnabled" }, { "type": "boolean", @@ -308,6 +309,13 @@ "config": "adaptivefps.session", "min": 20, "max": 100 + }, + { + "type": "boolean", + "label": "Only Render When Focused", + "tooltip": "Pause rendering if the window is not focused.\nTip: This can be helpful when fast forwarding in replays.", + "config": "pauserendereronfocusloss", + "function": "SetPauseRendererOnFocusLossEnabled" } ] }, Index: source/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -305,13 +305,13 @@ ENSURE(realTimeSinceLastFrame > 0.0f); // decide if update/render is necessary - bool need_render = !g_app_minimized; + bool need_render = !g_app_minimized && (!g_PauseRendererOnFocusLoss || g_app_has_focus); bool need_update = true; // If we are not running a multiplayer game, disable updates when the game is // minimized or out of focus and relinquish the CPU a bit, in order to make // debugging easier. - if (g_PauseOnFocusLoss && !g_NetClient && !g_app_has_focus) + if (g_PauseGameOnFocusLoss && !g_NetClient && !g_app_has_focus) { PROFILE3("non-focus delay"); need_update = false; Index: source/ps/GameSetup/Config.h =================================================================== --- source/ps/GameSetup/Config.h +++ source/ps/GameSetup/Config.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -42,7 +42,10 @@ //----------------------------------------------------------------------------- // flag to pause the game on window focus loss -extern bool g_PauseOnFocusLoss; +extern bool g_PauseGameOnFocusLoss; + +// flag to pause the renderer on window focus loss +extern bool g_PauseRendererOnFocusLoss; // flag to switch on actor rendering extern bool g_RenderActors; Index: source/ps/GameSetup/Config.cpp =================================================================== --- source/ps/GameSetup/Config.cpp +++ source/ps/GameSetup/Config.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,7 +35,8 @@ bool g_NoGLAutoMipmap = false; bool g_NoGLVBO = false; -bool g_PauseOnFocusLoss = false; +bool g_PauseGameOnFocusLoss = false; +bool g_PauseRendererOnFocusLoss = false; bool g_RenderActors = true; @@ -92,7 +93,10 @@ CFG_GET_VAL("nos3tc", g_NoGLS3TC); CFG_GET_VAL("noautomipmap", g_NoGLAutoMipmap); CFG_GET_VAL("novbo", g_NoGLVBO); - CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss); + + CFG_GET_VAL("pausegameonfocusloss", g_PauseGameOnFocusLoss); + CFG_GET_VAL("pauserendereronfocusloss", g_PauseRendererOnFocusLoss); + CFG_GET_VAL("renderactors", g_RenderActors); CFG_GET_VAL("shadows", g_Shadows); CFG_GET_VAL("shadowpcf", g_ShadowPCF); Index: source/ps/scripting/JSInterface_Main.h =================================================================== --- source/ps/scripting/JSInterface_Main.h +++ source/ps/scripting/JSInterface_Main.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -33,6 +33,8 @@ bool HotkeyIsPressed_(ScriptInterface::CxPrivate* pCxPrivate, const std::string& hotkeyName); int GetFps(ScriptInterface::CxPrivate* pCxPrivate); int GetTextWidth(ScriptInterface::CxPrivate* pCxPrivate, const std::string& fontName, const std::wstring& text); + void SetPauseGameOnFocusLossEnabled(ScriptInterface::CxPrivate* pCxPrivate, bool enabled); + void SetPauseRendererOnFocusLossEnabled(ScriptInterface::CxPrivate* pCxPrivate, bool enabled); void RegisterScriptFunctions(const ScriptInterface& scriptInterface); } Index: source/ps/scripting/JSInterface_Main.cpp =================================================================== --- source/ps/scripting/JSInterface_Main.cpp +++ source/ps/scripting/JSInterface_Main.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -26,6 +26,7 @@ #include "ps/CStrIntern.h" #include "ps/GUID.h" #include "ps/GameSetup/Atlas.h" +#include "ps/GameSetup/Config.h" #include "ps/Globals.h" #include "ps/Hotkey.h" #include "tools/atlas/GameInterface/GameLoop.h" @@ -108,6 +109,16 @@ return width; } +void JSI_Main::SetPauseGameOnFocusLossEnabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool enabled) +{ + g_PauseGameOnFocusLoss = enabled; +} + +void JSI_Main::SetPauseRendererOnFocusLossEnabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool enabled) +{ + g_PauseRendererOnFocusLoss = enabled; +} + void JSI_Main::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("Exit"); @@ -121,4 +132,6 @@ scriptInterface.RegisterFunction("HotkeyIsPressed"); scriptInterface.RegisterFunction("GetFPS"); scriptInterface.RegisterFunction("GetTextWidth"); + scriptInterface.RegisterFunction("SetPauseGameOnFocusLossEnabled"); + scriptInterface.RegisterFunction("SetPauseRendererOnFocusLossEnabled"); }