diff --git a/src/m_menu.c b/src/m_menu.c index 97b194c9e..8e1ec1505 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1715,9 +1715,11 @@ static menuitem_t OP_FocusOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Pause Game While Unfocused", &cv_pauseifunfocused, 60}, - {IT_STRING|IT_CVAR, NULL, "Show \"FOCUS LOST\"", &cv_showfocuslost, 80}, + {IT_STRING|IT_CVAR, NULL, "Background FPS Cap", &cv_fpscapbg, 80}, - {IT_STRING|IT_CVAR, NULL, "Always Grab Mouse While Focused", &cv_alwaysgrabmouse, 100}, + {IT_STRING|IT_CVAR, NULL, "Show \"FOCUS LOST\"", &cv_showfocuslost, 100}, + + {IT_STRING|IT_CVAR, NULL, "Always Grab Mouse While Focused", &cv_alwaysgrabmouse, 120}, }; static const char* OP_FocusOptionsTooltips[] = @@ -1726,6 +1728,7 @@ static const char* OP_FocusOptionsTooltips[] = "Should music play while the game is unfocused?", "Should soundeffects play while the game is unfocused?", "Should the game pause while the game is unfocused?", + "Set manual framerate cap while the game is unfocused.", "Should the FOCUS LOST window appear\n while the game is unfocused?", "Should the mouse cursor be grabbed and hidden\n while the game is in focus?", }; @@ -3157,7 +3160,7 @@ menu_t OP_ChatOptionsDef = DEFAULTMENUSTYLE("M_HUD", OP_ChatOptionsMenu, &OP_HUD menu_t OP_SoundAdvancedDef = DEFAULTSCROLLSTYLE("M_SOUND", OP_SoundAdvancedMenu, &OP_SoundOptionsDef, 30, 30); -menu_t OP_FocusOptionsDef = DEFAULTMENUSTYLE(NULL, OP_FocusOptionsMenu, &OP_MainDef, 25, 30); +menu_t OP_FocusOptionsDef = DEFAULTMENUSTYLE(NULL, OP_FocusOptionsMenu, &OP_MainDef, 17, 30); menu_t OP_GameOptionsDef = DEFAULTMENUSTYLE("M_GAME", OP_GameOptionsMenu, &OP_MainDef, 30, 20); menu_t OP_ServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_ServerOptionsMenu, &OP_MainDef, 24, 20); diff --git a/src/r_fps.c b/src/r_fps.c index 9e6c7c18c..01f605a60 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -41,13 +41,49 @@ static CV_PossibleValue_t fpscap_cons_t[] = { {0, "Match refresh rate"}, {0, NULL} }; + consvar_t cv_fpscap = {"fpscap", "Match refresh rate", CV_SAVE, fpscap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fpscapbg = {"fpscapbackground", "Match refresh rate", CV_SAVE, fpscap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_precipinterp = {"precipinterpolation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; ps_metric_t ps_interp_frac = {0}; ps_metric_t ps_interp_lag = {0}; +static boolean R_UseBackgroundFramerateCap(void) +{ + if (!window_notinfocus) + return false; + + // if foreground is unlimited or matched to refresh rate but bg is limited + if (cv_fpscap.value <= 0 && cv_fpscapbg.value >= 0) + return true; + + // use the lower value + if ((cv_fpscap.value > 0 && cv_fpscapbg.value > 0) + && (cv_fpscapbg.value < cv_fpscap.value)) + return true; + + return false; +} + +static UINT32 R_GetBackgroundFramerateCap(void) +{ + if (cv_fpscapbg.value == 0) + { + // 0: Match refresh rate + return I_GetRefreshRate(); + } + + if (cv_fpscapbg.value < 0) + { + // -1: Unlimited + return 0; + } + + return cv_fpscapbg.value; +} + UINT32 R_GetFramerateCap(void) { if (rendermode == render_none) @@ -57,6 +93,11 @@ UINT32 R_GetFramerateCap(void) return TICRATE; } + if (R_UseBackgroundFramerateCap()) + { + return R_GetBackgroundFramerateCap(); + } + if (cv_fpscap.value == 0) { // 0: Match refresh rate diff --git a/src/r_fps.h b/src/r_fps.h index 2ca6f1bf3..7ed55c848 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -20,7 +20,7 @@ #include "r_state.h" #include "m_perfstats.h" -extern consvar_t cv_fpscap; +extern consvar_t cv_fpscap, cv_fpscapbg; extern consvar_t cv_precipinterp; extern ps_metric_t ps_interp_frac; diff --git a/src/r_main.c b/src/r_main.c index 46c1ffcfb..201ae495f 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1576,5 +1576,6 @@ void R_RegisterEngineStuff(void) // Frame interpolation/uncapped CV_RegisterVar(&cv_fpscap); + CV_RegisterVar(&cv_fpscapbg); CV_RegisterVar(&cv_precipinterp); }