From 70759acf6570ea769d41cc1f8a8bfeea50ef3bfa Mon Sep 17 00:00:00 2001 From: Knightmare66 Date: Thu, 6 Aug 2020 00:33:53 -0400 Subject: [PATCH] Added automatic setting of r_maxfps based on r_displayrefresh. --- client/cl_main.c | 65 ++++++++++++++++++++++++++++++++---------- client/client.h | 5 ++-- kmquake2_changelog.txt | 4 ++- ui/ui_video.c | 5 ++++ 4 files changed, 61 insertions(+), 18 deletions(-) diff --git a/client/cl_main.c b/client/cl_main.c index e0c88f3..b5784a9 100644 --- a/client/cl_main.c +++ b/client/cl_main.c @@ -2221,6 +2221,11 @@ void CL_InitLocal (void) Cmd_AddCommand ("weapnext", NULL); Cmd_AddCommand ("weapprev", NULL); +#ifdef CLIENT_SPLIT_NETFRAME + // auto-set r_maxfps based on r_displayrefresh + CL_SetFramerateCap (); +#endif // CLIENT_SPLIT_NETFRAME + // Chat Ignore from R1Q2/Q2Pro // Init list pointers cl_chatNickIgnores.next = NULL; @@ -2340,6 +2345,36 @@ void CL_AdvertiseVersion (void) #ifdef CLIENT_SPLIT_NETFRAME +/* +================== +CL_SetFramerateCap + +Auto-sets r_maxfps based on r_displayrefresh. +Does nothing if r_displayrefresh is not set. +================== +*/ +void CL_SetFramerateCap (void) +{ + int displayFreq = Cvar_VariableInteger("r_displayrefresh"); + + // if no refresh set, leave framerate cap at default + if (displayFreq <= 0) { + // Cvar_SetInteger ("r_maxfps", 125); // 8ms frame interval + return; + } + + // isn't 250 fps enough for any display? + if (displayFreq > 200) + Cvar_SetInteger ("r_maxfps", 250); // 4ms frame interval + else if (displayFreq > 167) + Cvar_SetInteger ("r_maxfps", 200); // 5ms frame interval + else if (displayFreq > 125) + Cvar_SetInteger ("r_maxfps", 167); // 6ms frame interval + else // 125 fps is default cap + Cvar_SetInteger ("r_maxfps", 125); // 8ms frame interval +} + + /* ================== CL_RefreshInputs @@ -2404,14 +2439,14 @@ void CL_Frame_Async (int msec) qboolean miscFrame = true; // Don't allow setting maxfps too low or too high - if (net_maxfps->value < 10) - Cvar_SetValue("net_maxfps", 10); - if (net_maxfps->value > 100) - Cvar_SetValue("net_maxfps", 100); - if (r_maxfps->value < 10) - Cvar_SetValue("r_maxfps", 10); - if (r_maxfps->value > 1000) - Cvar_SetValue("r_maxfps", 1000); + if (net_maxfps->integer < 10) + Cvar_SetInteger ("net_maxfps", 10); + if (net_maxfps->integer > 100) + Cvar_SetInteger ("net_maxfps", 100); + if (r_maxfps->integer < 10) + Cvar_SetInteger ("r_maxfps", 10); + if (r_maxfps->integer > 1000) + Cvar_SetInteger ("r_maxfps", 1000); packetDelta += msec; renderDelta += msec; @@ -2633,10 +2668,10 @@ void CL_Frame (int msec) // don't allow setting maxfps too low (or game could stop responding) // don't allow too high, either - if (cl_maxfps->value < 10) - Cvar_SetValue("cl_maxfps", 10); - if (cl_maxfps->value > 500) - Cvar_SetValue("cl_maxfps", 500); + if (cl_maxfps->integer < 10) + Cvar_SetInteger ("cl_maxfps", 10); + if (cl_maxfps->integer > 500) + Cvar_SetInteger ("cl_maxfps", 500); // if (!cl_timedemo->value) if (!cl_timedemo->integer) @@ -2681,15 +2716,15 @@ void CL_Frame (int msec) // clamp this to acceptable values (don't allow infinite particles) if (cl_particle_scale->value < 1.0f) - Cvar_SetValue("cl_particle_scale", 1); + Cvar_SetValue ("cl_particle_scale", 1); // clamp this to acceptable minimum length if (cl_rail_length->value < MIN_RAIL_LENGTH) - Cvar_SetValue("cl_rail_length", MIN_RAIL_LENGTH); + Cvar_SetValue ("cl_rail_length", MIN_RAIL_LENGTH); // clamp this to acceptable minimum duration if (r_decal_life->value < MIN_DECAL_LIFE) - Cvar_SetValue("r_decal_life", MIN_DECAL_LIFE); + Cvar_SetValue ("r_decal_life", MIN_DECAL_LIFE); // if in the debugger last frame, don't timeout if (msec > 5000) diff --git a/client/client.h b/client/client.h index 2088d34..f5065ac 100644 --- a/client/client.h +++ b/client/client.h @@ -816,8 +816,9 @@ void CL_GetChallengePacket (void); void CL_PingServers_f (void); void CL_Snd_Restart_f (void); void CL_WriteConfig_f (void); - -void vectoangles2 (vec3_t value1, vec3_t angles); +#ifdef CLIENT_SPLIT_NETFRAME +void CL_SetFramerateCap (void); +#endif // CLIENT_SPLIT_NETFRAME // // cl_input diff --git a/kmquake2_changelog.txt b/kmquake2_changelog.txt index 63827b3..1f4a0ea 100644 --- a/kmquake2_changelog.txt +++ b/kmquake2_changelog.txt @@ -4,7 +4,9 @@ Changes as of v0.20 update 8: - Added 3840x1600 and 4096x2160 video modes. -- Added 160Hz and 240Hz refresh rates. +- Added 160Hz and 240Hz refresh rates. + +- Added automatic setting of r_maxfps based on refresh rate set in video menu (r_displayrefresh). - Added support for triple-monitor surround modes via custom resolutions. Monitors must be bound as a single logical display. Keeps all menu/HUD elements on the center screen, set the cvar scr_surroundlayout to 0 to disable this. diff --git a/ui/ui_video.c b/ui/ui_video.c index 330f455..d0a259f 100644 --- a/ui/ui_video.c +++ b/ui/ui_video.c @@ -145,6 +145,11 @@ static void prepareVideoRefresh( void ) Cvar_Set( "vid_ref", "gl" ); Cvar_Set( "gl_driver", "opengl32" ); +#ifdef CLIENT_SPLIT_NETFRAME + // auto-set r_maxfps based on r_displayrefresh + CL_SetFramerateCap (); +#endif // CLIENT_SPLIT_NETFRAME + // tell them they're modified so they refresh vid_ref->modified = true; }