mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-15 00:15:15 +01:00
Merge pull request #270 from MaSzyna-EU07/fix/fpslimit-frame-pacing
fpslimit: pace frames in integer clock ticks, show the real frame rate (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 "simulation/simulationtest.h"
|
||||
@@ -488,9 +489,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();
|
||||
|
||||
@@ -650,10 +656,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