diff --git a/src/client/component/fps.cpp b/src/client/component/fps.cpp index 3614829..154cf8c 100644 --- a/src/client/component/fps.cpp +++ b/src/client/component/fps.cpp @@ -74,6 +74,23 @@ namespace fps ++data->index; } + void enforce_fps_limit() + { + const auto* maxfps = game::Dvar_FindVar("com_maxfps"); + const auto max = (maxfps) ? std::min(2 * maxfps->current.integer, maxfps->domain.integer.max + 250) : 1250; + const auto fps = static_cast(static_cast(1000.0f / + static_cast(cg_perf.average)) + 9.313225746154785e-10); + + if (fps > max) + { + // workaround to limit fps + scheduler::once([]() + { + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + }, scheduler::pipeline::renderer); + } + } + void perf_update() { cg_perf.count = 32; @@ -84,6 +101,7 @@ namespace fps cg_perf.previous_ms = cg_perf.current_ms; perf_calc_fps(&cg_perf, cg_perf.frame_ms); + enforce_fps_limit(); utils::hook::invoke(SELECT_VALUE(0x1405806E0, 0x140658E30)); }