Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_UTILITY_FPS_COUNTER_H
00002 #define OPENTISSUE_UTILITY_UTILITY_FPS_COUNTER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/utility_timer.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace utility
00017 {
00018
00019
00020
00021 template<typename real_type>
00022 class FPSCounter
00023 {
00024 public:
00025 FPSCounter()
00026 : m_fps(0)
00027 , m_fpscnt(0)
00028 , m_time(0.)
00029 {
00030 m_hrc.start();
00031 }
00032
00033
00034
00035
00036 unsigned long operator()() const
00037 {
00038 return m_fps;
00039
00040 }
00041
00042
00043
00044
00045 bool frame()
00046 {
00047 m_hrc.stop();
00048 m_time += m_hrc();
00049 m_fpscnt++;
00050 if (m_time >= 1.) {
00051
00052 m_time = 0.;
00053 m_fps = m_fpscnt;
00054 m_fpscnt = 0;
00055 }
00056 m_hrc.start();
00057 return 0 == m_fpscnt;
00058 }
00059
00060 private:
00061
00062 Timer<real_type> m_hrc;
00063 unsigned long m_fps;
00064 unsigned long m_fpscnt;
00065 double m_time;
00066 };
00067
00068 }
00069
00070 }
00071
00072
00073 #endif