Simulate thousands of n-Pendula (up to 32) with Position Based Dynamics
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
755 B

#include "FPS.h"
#include <QTimer>
FPS::FPS() {
previousFrame = system_clock::now();
1 year ago
timeSinceUpdate = nanoseconds(0);
framesSinceUpdate = 0;
current = 0;
timer = new QTimer(this);
timer->setInterval(250);
connect(timer, &QTimer::timeout, this, &FPS::updateCurrent);
timer->start();
}
void FPS::newFrame() {
framesSinceUpdate++;
auto thisFrame = system_clock::now();
1 year ago
timeSinceUpdate += thisFrame - previousFrame;
previousFrame = thisFrame;
}
void FPS::setUpdateInterval(int milli) {
timer->setInterval(milli);
}
void FPS::updateCurrent() {
if (timeSinceUpdate.count() == 0)
current = 0;
else
current = framesSinceUpdate * 1000 * 1000 * 1000 / (timeSinceUpdate.count());
framesSinceUpdate = 0;
1 year ago
timeSinceUpdate = nanoseconds(0);
}