00001 // /////////////////////////////////////////////////////////////////////////// 00002 // xrb_frameratecalculator.hpp by Victor Dods, created 2004/05/31 00003 // /////////////////////////////////////////////////////////////////////////// 00004 // Unless a different license was explicitly granted in writing by the 00005 // copyright holder (Victor Dods), this software is freely distributable under 00006 // the terms of the GNU General Public License, version 2. Any works deriving 00007 // from this work must also be released under the GNU GPL. See the included 00008 // file LICENSE for details. 00009 // /////////////////////////////////////////////////////////////////////////// 00010 00011 #if !defined(_XRB_FRAMERATECALCULATOR_HPP_) 00012 #define _XRB_FRAMERATECALCULATOR_HPP_ 00013 00014 #include "xrb.hpp" 00015 00016 #include "xrb_circularqueue.hpp" 00017 00018 namespace Xrb 00019 { 00020 00026 class FramerateCalculator 00027 { 00028 public: 00029 00035 FramerateCalculator (Float time_unit_conversion_ratio = 1.0); 00038 ~FramerateCalculator () { } 00039 00042 void AddFrameTime (Float frame_time); 00043 00047 Float Framerate () const; 00048 00049 private: 00050 00051 enum 00052 { 00053 FRAME_COUNT = 32 00054 }; 00055 00056 // the circular queue which stores the frame times 00057 CircularQueue<Float, FRAME_COUNT> m_frame_queue; 00058 // the last frame time (to compute frame deltas) 00059 Float m_last_frame_time; 00060 // time conversion ratio (from input units to output units) 00061 Float m_time_unit_conversion_ratio; 00062 }; // end of class FramerateCalculator 00063 00064 } // end of namespace Xrb 00065 00066 #endif // !defined(_XRB_FRAMERATECALCULATOR_HPP_)