Implement FPS counting

This commit is contained in:
SimoneN64
2024-12-25 21:28:34 +01:00
parent 92a10d41ad
commit 7d18f2386a
2 changed files with 8 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ void EmuThread::run() noexcept {
auto lastSample = std::chrono::high_resolution_clock::now();
auto avgFps = 16.667;
auto sampledFps = 0;
static bool oneSecondPassed = false;
fps.setText(fmt::format("{:.2f} FPS", 1000.0 / avgFps).c_str());
@@ -34,6 +35,10 @@ void EmuThread::run() noexcept {
if (const auto elapsedSinceLastSample = std::chrono::duration<double>(endFrameTime - lastSample) / 1s;
elapsedSinceLastSample >= 1.0) {
if (!oneSecondPassed) {
oneSecondPassed = true;
continue;
}
lastSample = endFrameTime;
avgFps /= sampledFps;
sampledFps = 0;