Index: binaries/data/config/default.cfg =================================================================== --- binaries/data/config/default.cfg +++ binaries/data/config/default.cfg @@ -29,9 +29,6 @@ ; Show detailed tooltips (Unit stats) showdetailedtooltips = false -; Pause the game on window focus loss (Only applicable to single player mode) -pauseonfocusloss = true - ; Persist settings after leaving the game setup screen persistmatchsettings = true @@ -446,6 +443,10 @@ [tinygettext] debug = false ; Print error messages each time a translation for an English string is not found. +[unfocused] +pausesimulation = true ; Pause game when window focus loss (Pause only to single player game). +pauserenderer = false ; Pause rendering of the game (simulation continues) when window loses focus. + [userreport] ; Opt-in online user reporting system url = "http://feedback.wildfiregames.com/report/upload/v1/" 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 @@ -24,8 +24,9 @@ { "type": "boolean", "label": "Background Pause", - "tooltip": "Pause single player games when window loses focus", - "config": "pauseonfocusloss" + "tooltip": "Pause single player games or rendering of the game (gameplay continues) when window loses focus.", + "config": "unfocused.pausesimulation", + "function": "UpdatePauseOnFocusLoss" }, { "type": "boolean", @@ -291,6 +292,13 @@ "config": "adaptivefps.session", "min": 20, "max": 100 + }, + { + "type": "boolean", + "label": "Background Pause Rendering (saves alot cpu/gpu)", + "tooltip": "Pause rendering of the game (simulation continues), when window loses focus.\n[color=\"yellow\"]Tip[/color]: Can be helpful, when fast forwarding in a replay or stay in a game as observer, while not much cpu/gpu is used, when the window is in the background.", + "config": "unfocused.pauserenderer", + "function": "UpdatePauseOnFocusLoss" } ] }, Index: source/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -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 @@ -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; @@ -96,6 +99,8 @@ extern CStrW g_CursorName; extern const wchar_t g_DefaultCursor[]; +extern void ConfigSetPauseOnFocusLoss(); + class CmdLineArgs; extern void CONFIG_Init(const CmdLineArgs& args); Index: source/ps/GameSetup/Config.cpp =================================================================== --- source/ps/GameSetup/Config.cpp +++ source/ps/GameSetup/Config.cpp @@ -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,9 @@ CFG_GET_VAL("nos3tc", g_NoGLS3TC); CFG_GET_VAL("noautomipmap", g_NoGLAutoMipmap); CFG_GET_VAL("novbo", g_NoGLVBO); - CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss); + + ConfigSetPauseOnFocusLoss(); + CFG_GET_VAL("renderactors", g_RenderActors); CFG_GET_VAL("shadows", g_Shadows); CFG_GET_VAL("shadowpcf", g_ShadowPCF); @@ -115,6 +118,11 @@ CFG_GET_VAL("gui.scale", g_GuiScale); } +void ConfigSetPauseOnFocusLoss() +{ + CFG_GET_VAL("unfocused.pausesimulation", g_PauseGameOnFocusLoss); + CFG_GET_VAL("unfocused.pauserenderer", g_PauseRendererOnFocusLoss); +} static void ProcessCommandLineArgs(const CmdLineArgs& args) { 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,7 @@ 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 UpdatePauseOnFocusLoss(ScriptInterface::CxPrivate* pCxPrivate); 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,11 @@ return width; } +void JSI_Main::UpdatePauseOnFocusLoss(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) +{ + ConfigSetPauseOnFocusLoss(); +} + void JSI_Main::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("Exit"); @@ -121,4 +127,5 @@ scriptInterface.RegisterFunction("HotkeyIsPressed"); scriptInterface.RegisterFunction("GetFPS"); scriptInterface.RegisterFunction("GetTextWidth"); + scriptInterface.RegisterFunction("UpdatePauseOnFocusLoss"); }