#include "FPS.h" #include 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); }