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.

32 lines
714 B

#include "FPS.h"
#include <QTimer>
FPS::FPS() {
previousFrame = high_resolution_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 = high_resolution_clock::now();
1 year ago
timeSinceUpdate += thisFrame - previousFrame;
previousFrame = thisFrame;
}
void FPS::setUpdateInterval(int milli) {
timer->setInterval(milli);
}
void FPS::updateCurrent() {
1 year ago
current = framesSinceUpdate * 1000 * 1000 * 1000 / timeSinceUpdate.count();
framesSinceUpdate = 0;
1 year ago
timeSinceUpdate = nanoseconds(0);
}