18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 01:46:01 +01:00

fix: fpslimit paced in integer clock ticks, FPS shown counts the wait (eu07/maszyna#416)

The limiter slept off the rest of each frame with sleep_for() given a float
duration. MSVC adds that to steady_clock::now() in float nanoseconds, so after
a few hours of system uptime the wake-up time is rounded to tens of ms: at
95 h uptime fpslimit 60 had no effect at all and fpslimit 30 gave ~22 fps, in
the full and the legacy renderer alike.

frame_pacer now schedules frames on a fixed cadence in steady_clock ticks and
the loop waits with sleep_until; an overshooting wait is made up in the next
frame. The FPS shown and the motion blur use the new mainloop_period stopwatch
(frame start to frame start, wait included); the targetfps/fpsaverage
draw-range controllers keep reading the work time as before.

(eu07/maszyna#416)
This commit is contained in:
jerrrrycho
2026-11-07 18:47:41 +01:00
parent 939e42b611
commit e8c4f3592e
6 changed files with 192 additions and 9 deletions

View File

@@ -5663,12 +5663,15 @@ void opengl33_renderer::Update(double const Deltatime)
}
m_updateaccumulator = 0.0;
m_framerate = 1000.f / ( Timer::subsystem.mainloop_total.average() );
// the frames actually shown, the wait for fpslimit included (eu07/maszyna#416)
m_framerate = 1000.f / ( Timer::subsystem.mainloop_period.average() );
// the frames the work alone would allow, so a frame rate held down by fpslimit doesn't cut the draw ranges
auto const workframerate{1000.f / Timer::subsystem.mainloop_total.average()};
// adjust draw ranges etc, based on recent performance
if (Global.targetfps != 0.0f) {
float fps_diff = Global.targetfps - m_framerate;
float fps_diff = Global.targetfps - workframerate;
if (fps_diff > 0.0f)
Global.fDistanceFactor = std::max(0.5f, Global.fDistanceFactor - 0.05f);
else
@@ -5676,7 +5679,7 @@ void opengl33_renderer::Update(double const Deltatime)
}
// legacy framerate parameters
else if (Global.fFpsAverage != 0.f) {
auto const fps_diff = m_framerate - Global.fFpsAverage;
auto const fps_diff = workframerate - Global.fFpsAverage;
if (fps_diff < -Global.fFpsDeviation) {
Global.fDistanceFactor = std::min(std::max(1.0f, Global.fDistanceFactor - 0.05f), Global.gfx_distance_factor_max);
}