From 8ad2d5f949df609fa6841525347e30b5fd660360 Mon Sep 17 00:00:00 2001 From: orcephrye Date: Mon, 8 Jul 2019 20:13:24 -0500 Subject: [PATCH] [client] autodetect monitor refresh rate for fps limit --- client/src/config.c | 4 ++-- client/src/main.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/client/src/config.c b/client/src/config.c index 5f9a8b09..9c683c9c 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -185,10 +185,10 @@ static struct Option options[] = { .module = "win", .name = "fpsLimit", - .description = "Frame rate limit (0 = disable - not recommended)", + .description = "Frame rate limit (0 = disable - not recommended, -1 = auto detect)", .shortopt = 'K', .type = OPTION_TYPE_INT, - .value.x_int = 200, + .value.x_int = -1, }, { .module = "win", diff --git a/client/src/main.c b/client/src/main.c index 47def566..9ce9384b 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1000,7 +1000,6 @@ int run() state.running = true; state.scaleX = 1.0f; state.scaleY = 1.0f; - state.frameTime = 1e9 / params.fpsLimit; state.mouseSens = params.mouseSens; if (state.mouseSens < -9) state.mouseSens = -9; @@ -1120,6 +1119,26 @@ int run() // ensure renderer viewport is aware of the current window size updatePositionInfo(); + //Auto detect active monitor refresh rate for FPS Limit if no FPS Limit was passed. + if (params.fpsLimit == -1) + { + SDL_DisplayMode current; + if (SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(state.window), ¤t) == 0) + { + state.frameTime = 1e9 / (current.refresh_rate * 2); + } + else + { + DEBUG_WARN("Unable to capture monitor refresh rate using the default FPS Limit: 200"); + state.frameTime = 1e9 / 200; + } + } + else + { + DEBUG_INFO("Using the FPS Limit from args: %d", params.fpsLimit); + state.frameTime = 1e9 / params.fpsLimit; + } + register_key_binds(); // set the compositor hint to bypass for low latency