00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xrb_frameratecalculator.hpp"
00012
00013 namespace Xrb
00014 {
00015
00016 FramerateCalculator::FramerateCalculator (Float const time_unit_conversion_ratio)
00017 {
00018 m_last_frame_time = 0.0f;
00019 m_time_unit_conversion_ratio =
00020 (time_unit_conversion_ratio > 0.0) ?
00021 time_unit_conversion_ratio :
00022 1.0f;
00023 }
00024
00025 void FramerateCalculator::AddFrameTime (Float const frame_time)
00026 {
00027
00028 if (m_frame_queue.IsFull())
00029 m_frame_queue.Dequeue();
00030
00031
00032 m_frame_queue.Enqueue(frame_time - m_last_frame_time);
00033
00034 m_last_frame_time = frame_time;
00035 }
00036
00037 Float FramerateCalculator::Framerate () const
00038 {
00039 Float total = 0.0f;
00040
00041
00042 for (Uint32 i = 0; i < m_frame_queue.EntryCount(); ++i)
00043 total += m_frame_queue.Entry(i);
00044
00045
00046 if (total == 0.0f)
00047 total = 1.0f;
00048
00049 return m_time_unit_conversion_ratio * m_frame_queue.EntryCount() / total;
00050 }
00051
00052 }