Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/etc/Games/fps.hpp

Go to the documentation of this file.
00001 // It's a very simple fps counter, which prints information to the
00002 // stream stdout every second. It's only useful for debugging purposes.
00003 
00004 #ifndef __J2K__Jfps_HPP__
00005 #define __J2K__Jfps_HPP__
00006 
00007 #include <j2k/Fred/Standard.hpp>
00008 #include <time.h>
00009 
00010 class Jfps {
00011 public:
00012   inline Jfps();
00013   void calculate();
00014 
00015 private:
00016   long curTime, lateTime, beginTime;
00017   long count, totalFrames;
00018   float msec;
00019   float average;
00020 };
00021 
00022 inline Jfps::Jfps() 
00023 {
00024   time( &beginTime );
00025 }
00026 
00027 void Jfps::calculate() 
00028 {
00029   count++;
00030   time( &curTime );
00031 
00032   if ( lateTime != curTime ) 
00033   {
00034     lateTime = curTime;
00035     msec = (float)1000 / (float)count;
00036     totalFrames += count;
00037     average = (float)totalFrames / (float)(curTime - beginTime);
00038     printf("fps: %4d  AVG: %3.1f  MS: %3.1f\n", (int)count, average, msec);
00039     count = 0;
00040   }
00041 }
00042 
00043 #endif

Generated on Sun Oct 14 18:46:31 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001