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