36 lines
661 B
C++
36 lines
661 B
C++
#include "frame_counter.hpp"
|
|
#include "../logging/easylogging++.h"
|
|
|
|
unsigned int FrameCounter::getFps() const
|
|
{
|
|
return lastFps;
|
|
}
|
|
|
|
void FrameCounter::addFrame()
|
|
{
|
|
liveFrameCount++;
|
|
timeSinceLastFpsUpdate += clock.restart();
|
|
auto const second = sf::seconds(1);
|
|
if (timeSinceLastFpsUpdate < second)
|
|
{
|
|
return;
|
|
}
|
|
|
|
lastFps = liveFrameCount;
|
|
liveFrameCount = 0;
|
|
timeSinceLastFpsUpdate -= second;
|
|
|
|
if (printFpsInConsole)
|
|
{
|
|
LOG(INFO) << "FPS: " << lastFps;
|
|
}
|
|
}
|
|
|
|
void FrameCounter::reset()
|
|
{
|
|
clock.restart();
|
|
timeSinceLastFpsUpdate = sf::Time::Zero;
|
|
liveFrameCount = 0;
|
|
lastFps = 0;
|
|
|
|
}
|