mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-15 19:54:10 +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:
@@ -28,6 +28,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/translation.h"
|
||||
#include "vehicle/Train.h"
|
||||
#include "utilities/Timer.h"
|
||||
#include "utilities/framepacer.h"
|
||||
#include "utilities/dictionary.h"
|
||||
#include "version_info.h"
|
||||
#include <chrono>
|
||||
@@ -479,9 +480,14 @@ bool eu07_application::is_client() const
|
||||
int eu07_application::run()
|
||||
{
|
||||
auto frame{0};
|
||||
frame_pacer framepacer;
|
||||
Timer::subsystem.mainloop_period.start();
|
||||
// main application loop
|
||||
while (!glfwWindowShouldClose(m_windows.front()) && !m_modestack.empty())
|
||||
{
|
||||
// the time from one frame's start to the next, the wait for fpslimit included
|
||||
Timer::subsystem.mainloop_period.stop();
|
||||
Timer::subsystem.mainloop_period.start();
|
||||
Timer::subsystem.mainloop_total.start();
|
||||
glfwPollEvents();
|
||||
|
||||
@@ -641,10 +647,11 @@ int eu07_application::run()
|
||||
if (m_network)
|
||||
m_network->update();
|
||||
|
||||
auto const frametime{Timer::subsystem.mainloop_total.stop()};
|
||||
if (Global.minframetime.count() != 0.0f && (Global.minframetime - frametime).count() > 0.0f)
|
||||
Timer::subsystem.mainloop_total.stop();
|
||||
// fpslimit: wait for the next frame's slot (eu07/maszyna#416)
|
||||
if (auto const nextframe{framepacer.next_frame(frame_pacer::clock::now(), Global.minframetime)})
|
||||
{
|
||||
std::this_thread::sleep_for(Global.minframetime - frametime);
|
||||
std::this_thread::sleep_until(*nextframe);
|
||||
}
|
||||
}
|
||||
// Handled by application.exit
|
||||
|
||||
Reference in New Issue
Block a user