Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
FrameRateHandler.cpp
Go to the documentation of this file.
1
2
4
5namespace Divide::Time {
6
7
8void FrameRateHandler::tick(const U64 deltaTimeUS) noexcept {
9 const F32 elapsedSeconds = Time::MicrosecondsToSeconds<F32>(deltaTimeUS);
10 const F32 deltaSeconds = elapsedSeconds - _previousElapsedSeconds;
11 _framerateSecPerFrameAccum += deltaSeconds - _framerateSecPerFrame[_framerateSecPerFrameIdx];
12 _framerateSecPerFrame[_framerateSecPerFrameIdx] = deltaSeconds;
13 _framerateSecPerFrameIdx = (_framerateSecPerFrameIdx + 1) % FRAME_ARRAY_SIZE;
14 _framerate = 1.0f / (_framerateSecPerFrameAccum / to_F32(FRAME_ARRAY_SIZE));
15 _previousElapsedSeconds = elapsedSeconds;
16
17 _averageFPS += _framerate;
18
19 if (_frameCount > FRAME_AVG_DELAY_COUNT) {
20 _maxFPS = std::max(_framerate, _maxFPS);
21 _minFPS = std::min(_framerate, _minFPS);
22 }
23
24 // Min/max frame rate
25 if (++_frameCount > FRAME_AVG_RESET_COUNT) {
26 _averageFPS = 0.0f;
27 _frameCount = 0;
28 _minFPS = F32_MAX;
29 _maxFPS = F32_LOWEST;
30 }
31}
32
33} //namespace Divide::Time
void tick(U64 deltaTimeUS) noexcept
constexpr F32 to_F32(const T value)
constexpr F32 F32_LOWEST
constexpr F32 F32_MAX
uint64_t U64