feat: added FPS counter to terminal
This commit is contained in:
40
PerformanceAnalyser.hpp
Normal file
40
PerformanceAnalyser.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <GL/glew.h>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
class PerformanceAnalyser {
|
||||
private:
|
||||
double lastFrameTime = 0;
|
||||
int frameCount = 0;
|
||||
double timeAcc = 0;
|
||||
double lastFps = 0;
|
||||
|
||||
public:
|
||||
PerformanceAnalyser(int framesToAcc = 10, bool autoPrint = true)
|
||||
: framesToAcc(framesToAcc), autoPrint(autoPrint) {};
|
||||
|
||||
int framesToAcc;
|
||||
bool autoPrint;
|
||||
|
||||
int getFPS() { return lastFps; }
|
||||
|
||||
void update(float time) {
|
||||
|
||||
timeAcc += (time - lastFrameTime);
|
||||
lastFrameTime = time;
|
||||
frameCount++;
|
||||
|
||||
if (frameCount == framesToAcc) {
|
||||
|
||||
lastFps = double(framesToAcc) / timeAcc;
|
||||
|
||||
if (autoPrint) {
|
||||
std::cout << "Fps: " << std::round(lastFps * 10.0) * 0.1 << "\n"
|
||||
<< std::flush;
|
||||
}
|
||||
|
||||
frameCount = 0;
|
||||
timeAcc = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user