From 51a9ab9a60d5885d86ffcf14274611bc1c766203 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Tue, 12 Sep 2023 12:36:38 +0200 Subject: [PATCH] more accurate --- src/FPS.cpp | 8 ++++---- src/FPS.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/FPS.cpp b/src/FPS.cpp index 0014f59..305f764 100644 --- a/src/FPS.cpp +++ b/src/FPS.cpp @@ -3,7 +3,7 @@ FPS::FPS() { previousFrame = high_resolution_clock::now(); - timeSinceUpdate = milliseconds(0); + timeSinceUpdate = nanoseconds(0); framesSinceUpdate = 0; current = 0; @@ -16,7 +16,7 @@ FPS::FPS() { void FPS::newFrame() { framesSinceUpdate++; auto thisFrame = high_resolution_clock::now(); - timeSinceUpdate += duration_cast(thisFrame - previousFrame); + timeSinceUpdate += thisFrame - previousFrame; previousFrame = thisFrame; } @@ -25,7 +25,7 @@ void FPS::setUpdateInterval(int milli) { } void FPS::updateCurrent() { - current = framesSinceUpdate * 1000 / timeSinceUpdate.count(); + current = framesSinceUpdate * 1000 * 1000 * 1000 / timeSinceUpdate.count(); framesSinceUpdate = 0; - timeSinceUpdate = milliseconds(0); + timeSinceUpdate = nanoseconds(0); } diff --git a/src/FPS.h b/src/FPS.h index 28ab80b..70a2c48 100644 --- a/src/FPS.h +++ b/src/FPS.h @@ -8,7 +8,7 @@ using namespace std::chrono; class FPS : public QObject { QTimer * timer; time_point previousFrame; - milliseconds timeSinceUpdate; + nanoseconds timeSinceUpdate; size_t framesSinceUpdate; public: FPS();