Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

FramesPerSecond.h

Go to the documentation of this file.
00001 #ifndef OglGui_FramesPerSecond_h
00002 #define OglGui_FramesPerSecond_h
00003 
00004 /*
00005 #ifndef OglGui_time_included
00006 #include <time.h>
00007 #define OglGui_time_included
00008 #endif
00009 */
00010 
00011 #ifndef OglGui_StaticText_h
00012 #include "OglGui/StaticText.h"
00013 #endif
00014 
00015 namespace OglGui
00016 {
00017 
00018 class FramesPerSecond : public StaticText
00019 {
00020 public:
00021 
00022     FramesPerSecond(Window* parent, int x, int y, int width, int height) :
00023         StaticText(parent, x, y, width, height, "")
00024     {
00025         Init();
00026     }
00027 
00028     FramesPerSecond(Window* parent, int width, int height) :
00029         StaticText(parent, width, height, "")
00030     {
00031         Init();
00032     }
00033 
00034     virtual void
00035     DisplayFunc()
00036     {
00037         char    buf[40];
00038         float   elapsedSec;
00039 
00040         if (!mInitialized)
00041         {
00042             mInitialized = true;
00043             mFrameCount = mIntervalFrameCount = 0;
00044             mLastInterval = mStartTime = OglClock();
00045         }
00046 
00047         mFrameCount++;
00048         mIntervalFrameCount++;
00049 
00050         elapsedSec = OglClock() - mLastInterval;
00051 
00052         // Wait 3 tenth of a second after a reset before computing fps
00053         // This prevents too strong changes in fps at interval resets
00054         if (elapsedSec > 0.3f)
00055             mFramesPerSecond = mIntervalFrameCount / elapsedSec;
00056         
00057         sprintf(buf,"%.1f fps", mFramesPerSecond);
00058         SetText(buf);
00059 
00060         // To prevent misguided information when the display has been
00061         // interrupted reset every 5 seconds
00062         if (elapsedSec > 5)
00063         {
00064             elapsedSec = 0.0f;
00065             mIntervalFrameCount = 0;
00066             mLastInterval = OglClock();
00067         }
00068 
00069         StaticText::DisplayFunc();
00070     }
00071 
00072 private :
00073 
00074     double mStartTime; // Not used yet
00075     double mLastInterval;
00076     float   mFramesPerSecond;
00077     int     mFrameCount; // Not used yet
00078     int     mIntervalFrameCount;
00079     bool    mInitialized;
00080 
00081     void
00082     Init()
00083     {
00084         mFramesPerSecond = 0.0f;
00085         mInitialized = false;
00086         SetBorderType(BEV_LINE);
00087     }
00088 };
00089 
00090 } // namespace OglGui
00091 
00092 #endif

Generated on Fri Mar 19 09:31:35 2010 for ImpalaSrc by  doxygen 1.5.1