forked from alterware/iw6-mod
Added workaround to enforce max fps limit.
Without this workaround my fps occasionally exceeds 1500 or even 2000 fps.
This commit is contained in:
parent
d26a5fe43f
commit
d424dc2c45
@ -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<std::int32_t>(static_cast<float>(1000.0f /
|
||||
static_cast<float>(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<void>(SELECT_VALUE(0x1405806E0, 0x140658E30));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user