more accurate

main
Benjamin Kraft 1 year ago
parent f66c5743e6
commit 51a9ab9a60
  1. 8
      src/FPS.cpp
  2. 2
      src/FPS.h

@ -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<milliseconds>(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);
}

@ -8,7 +8,7 @@ using namespace std::chrono;
class FPS : public QObject {
QTimer * timer;
time_point<system_clock> previousFrame;
milliseconds timeSinceUpdate;
nanoseconds timeSinceUpdate;
size_t framesSinceUpdate;
public:
FPS();

Loading…
Cancel
Save