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