init
This commit is contained in:
commit
444f800536
122 changed files with 17137 additions and 0 deletions
43
shared/UtilsFPS.h
Normal file
43
shared/UtilsFPS.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class FramesPerSecondCounter
|
||||
{
|
||||
public:
|
||||
explicit FramesPerSecondCounter(float avgInterval = 0.5f)
|
||||
: avgInterval_(avgInterval)
|
||||
{
|
||||
assert(avgInterval > 0.0f);
|
||||
}
|
||||
|
||||
bool tick(float deltaSeconds, bool frameRendered = true)
|
||||
{
|
||||
if (frameRendered)
|
||||
numFrames_++;
|
||||
|
||||
accumulatedTime_ += deltaSeconds;
|
||||
|
||||
if (accumulatedTime_ > avgInterval_) {
|
||||
currentFPS_ = static_cast<float>(numFrames_ / accumulatedTime_);
|
||||
if (printFPS_)
|
||||
printf("FPS: %.1f\n", currentFPS_);
|
||||
numFrames_ = 0;
|
||||
accumulatedTime_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline float getFPS() const { return currentFPS_; }
|
||||
|
||||
bool printFPS_ = true;
|
||||
|
||||
public:
|
||||
float avgInterval_ = 0.5f;
|
||||
unsigned int numFrames_ = 0;
|
||||
double accumulatedTime_ = 0;
|
||||
float currentFPS_ = 0.0f;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue