Kanzi 4.0.0-beta2
kanzi::FrameTimeQueue Class Reference

Bookkeeping for frame durations and associated errors. More...

#include <kanzi/core.ui/main_loop/frame_time_queue.hpp>

Classes

class  ErrorTermCalculator
 Error term calculator. More...
 

Public Member Functions

 FrameTimeQueue (chrono::nanoseconds window)
 Constructor.
 
 FrameTimeQueue (chrono::nanoseconds window, size_t desiredFrameRate)
 Constructor.
 
 FrameTimeQueue (FrameTimeQueue &&other)=default
 Move constructor.
 
size_t getDesiredFrameRate () const
 Gets the desired frame rate.
 
chrono::nanoseconds getDesiredFrameTime () const
 Gets the desired frame time.
 
float getFPS () const
 Gets the current framerate.
 
chrono::nanoseconds getFrameTimeErrorTerm () const
 Gets the cumulative frame time error.
 
chrono::nanoseconds getWindow () const
 Gets the frame time window.
 
FrameTimeQueueoperator= (FrameTimeQueue &&other)=default
 Move operator.
 
void update (chrono::nanoseconds frameTime)
 Add a frame time.
 

Static Public Member Functions

static constexpr chrono::nanoseconds fpsToDurationCeiled (size_t desiredFrameRate)
 Converts frame rate to desired frame time duration.
 

Protected Member Functions

size_t decrementIterator (size_t iter) const
 Decrement an iterator and wrap around if needed.
 
void growFrameTimeArray ()
 Enlarges the frame time array.
 
size_t incrementIterator (size_t iter) const
 Increment an iterator and wrap around if needed.
 

Static Protected Member Functions

static constexpr chrono::nanoseconds durationDivideRoundUp (chrono::nanoseconds duration, size_t divisor)
 Divide time by a value, round up.
 

Protected Attributes

ErrorTermCalculator m_errorTermCalculator
 Calculator for frame time error term.
 
float m_fps
 Frame rate cache.
 
size_t m_frameTimeCount
 Frame time element count.
 
vector< chrono::nanoseconds > m_frameTimes
 Array containing frame times for FPS calculation.
 
size_t m_insertionIndex
 Frame time insertion index.
 
size_t m_removeIndex
 Frame time removal index.
 
chrono::nanoseconds m_totalTime
 Total time spent within the frame time window.
 
chrono::nanoseconds m_window
 Time window for frame time error bookkeeping.
 

Detailed Description

Bookkeeping for frame durations and associated errors.

Constructor & Destructor Documentation

◆ FrameTimeQueue() [1/3]

kanzi::FrameTimeQueue::FrameTimeQueue ( chrono::nanoseconds window,
size_t desiredFrameRate )
inlineexplicit

Constructor.

Parameters
windowTime window for bookkeeping.
desiredFrameRateDesired frame rate.

◆ FrameTimeQueue() [2/3]

kanzi::FrameTimeQueue::FrameTimeQueue ( chrono::nanoseconds window)
explicit

Constructor.

Frame rate is unlimited.

Parameters
windowTime window for bookkeeping.

◆ FrameTimeQueue() [3/3]

kanzi::FrameTimeQueue::FrameTimeQueue ( FrameTimeQueue && other)
default

Move constructor.

Parameters
otherSource object.

Member Function Documentation

◆ operator=()

FrameTimeQueue & kanzi::FrameTimeQueue::operator= ( FrameTimeQueue && other)
default

Move operator.

Parameters
otherSource object.

◆ update()

void kanzi::FrameTimeQueue::update ( chrono::nanoseconds frameTime)

Add a frame time.

Parameters
frameTimeTime spent last frame.

◆ getFPS()

float kanzi::FrameTimeQueue::getFPS ( ) const
inline

Gets the current framerate.

Returns
Current framerate as calculated from recorded frame times.

◆ getDesiredFrameRate()

size_t kanzi::FrameTimeQueue::getDesiredFrameRate ( ) const
inline

Gets the desired frame rate.

Returns
Targeted frame rate.
Since
Kanzi 4.0.0

◆ getDesiredFrameTime()

chrono::nanoseconds kanzi::FrameTimeQueue::getDesiredFrameTime ( ) const
inline

Gets the desired frame time.

Returns
Frame time from the targeted frame rate.
Since
Kanzi 4.0.0

◆ getFrameTimeErrorTerm()

chrono::nanoseconds kanzi::FrameTimeQueue::getFrameTimeErrorTerm ( ) const
inline

Gets the cumulative frame time error.

Returns
Cumulative frame time error.
Since
Kanzi 4.0.0

◆ getWindow()

chrono::nanoseconds kanzi::FrameTimeQueue::getWindow ( ) const
inline

Gets the frame time window.

Returns
Frame window time.
Since
Kanzi 4.0.0

◆ fpsToDurationCeiled()

static constexpr chrono::nanoseconds kanzi::FrameTimeQueue::fpsToDurationCeiled ( size_t desiredFrameRate)
inlinestaticconstexpr

Converts frame rate to desired frame time duration.

Always rounds nanoseconds up.

Parameters
desiredFrameRateDesired Frame rate.
Returns
Frame duration in nanoseconds.
Since
Kanzi 4.0.0

◆ durationDivideRoundUp()

static constexpr chrono::nanoseconds kanzi::FrameTimeQueue::durationDivideRoundUp ( chrono::nanoseconds duration,
size_t divisor )
inlinestaticconstexprprotected

Divide time by a value, round up.

Parameters
durationDuration.
divisorDivisor.
Since
Kanzi 4.0.0

◆ growFrameTimeArray()

void kanzi::FrameTimeQueue::growFrameTimeArray ( )
protected

Enlarges the frame time array.

After calling this function, insertion of

Since
Kanzi 4.0.0

◆ decrementIterator()

size_t kanzi::FrameTimeQueue::decrementIterator ( size_t iter) const
inlineprotected

Decrement an iterator and wrap around if needed.

Parameters
iterIterator.
Returns
New iterator location.
Since
Kanzi 4.0.0

◆ incrementIterator()

size_t kanzi::FrameTimeQueue::incrementIterator ( size_t iter) const
inlineprotected

Increment an iterator and wrap around if needed.

Parameters
iterIterator.
Returns
New iterator location.
Since
Kanzi 4.0.0

Member Data Documentation

◆ m_window

chrono::nanoseconds kanzi::FrameTimeQueue::m_window
protected

Time window for frame time error bookkeeping.

Since
Kanzi 4.0.0

◆ m_frameTimes

vector<chrono::nanoseconds> kanzi::FrameTimeQueue::m_frameTimes
protected

Array containing frame times for FPS calculation.

Since
Kanzi 4.0.0
  • Renamed from m_frames.
  • Changed the type to vector<chrono::nanoseconds>.

◆ m_frameTimeCount

size_t kanzi::FrameTimeQueue::m_frameTimeCount
protected

Frame time element count.

Since
Kanzi 4.0.0 renamed from m_frameCount.

◆ m_insertionIndex

size_t kanzi::FrameTimeQueue::m_insertionIndex
protected

Frame time insertion index.

Insertion index being identical to removal index indicates the array being empty.

Since
Kanzi 4.0.0

◆ m_removeIndex

size_t kanzi::FrameTimeQueue::m_removeIndex
protected

Frame time removal index.

If insertion would increment the insertion index to the removal index, the array must be grown.

Since
Kanzi 4.0.0 renamed from m_firstFrame.

◆ m_totalTime

chrono::nanoseconds kanzi::FrameTimeQueue::m_totalTime
protected

Total time spent within the frame time window.

◆ m_fps

float kanzi::FrameTimeQueue::m_fps
protected

Frame rate cache.

◆ m_errorTermCalculator

ErrorTermCalculator kanzi::FrameTimeQueue::m_errorTermCalculator
protected

Calculator for frame time error term.

Since
Kanzi 4.0.0

The documentation for this class was generated from the following file: