00001
00008
00009
00010
00011
00012
00013 #if ENG_VIEW_CC // only eng_view.cc needs this
00014 #ifndef ENG_VIEW_FPS_HH
00015 #define ENG_VIEW_FPS_HH 1
00016
00017 namespace eng {
00018
00022 class FPS
00023 {
00024 friend class TimerFunctor;
00025 private:
00027 class TimerFunctor : public Timer::Functor
00028 {
00029 public:
00030 TimerFunctor( FPS& fps ) : mFPS(fps), mSeconds(0) { }
00031 void operator()(const Milliseconds millisecElapsed)
00032 {
00033 mSeconds = mSeconds + Seconds(1);
00034 mFPS.CalcFPS();
00035 #if 0
00036 if ( (int(mSeconds) % 5) == 0 )
00037 {
00038 COUT << "FPS = " << mFPS.GetFPS() << endl;
00039 }
00040 #endif
00041 }
00042 public:
00043 FPS& mFPS;
00044 Seconds mSeconds;
00045 };
00046
00047 public:
00048 FPS( void )
00049 : mFrameCnt(View::INVALID_FRAME_CNT),
00050 mFrameCntPrev(View::INVALID_FRAME_CNT),
00051 mFPS(0)
00052 {
00053
00054 shptr<Timer::Functor> functor = new TimerFunctor( *this );
00055 Timer::GetInstance().Register( functor, Milliseconds(Seconds(1)) );
00056 }
00057
00058 ~FPS() { }
00059
00061 void IncFrameCnt( void )
00062 {
00063 ++mFrameCnt;
00064 }
00065
00067 uint GetFPS( void )
00068 {
00069 return mFPS;
00070 }
00071
00072 private:
00074 void CalcFPS( void )
00075 {
00076
00077 if ( mFrameCntPrev != View::INVALID_FRAME_CNT )
00078 {
00079 mFPS = mFrameCnt - mFrameCntPrev;
00080 }
00081 mFrameCntPrev = mFrameCnt;
00082 }
00083
00084 private:
00085 uint mFrameCnt;
00086 uint mFrameCntPrev;
00087 uint mFPS;
00088 };
00089
00090 }
00091
00092 #endif // ENG_VIEW_HH
00093 #endif // ENG_VIEW_CC