FramePerSecond Class Reference

#include <fps.h>

Collaboration diagram for FramePerSecond:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FramePerSecond ()
 ~FramePerSecond ()
void Reset ()
void AddOneFrame ()
void Refresh ()
void Draw ()

Public Attributes

bool display

Private Attributes

int nb_valid_values
double average
std::list< uintnb_frames
uint time_in_second
Texttext

Static Private Attributes

static const uint MIN_NB_VALUES = 4

Detailed Description

Definition at line 28 of file fps.h.


Constructor & Destructor Documentation

FramePerSecond::FramePerSecond (  ) 

Definition at line 38 of file fps.cpp.

00038                               {
00039   text = NULL;
00040   display = true;
00041   average = -1;
00042   
00043   for( uint i=0; i<=MIN_NB_VALUES; ++i )
00044     nb_frames.push_back (0);
00045   
00046   time_in_second = 0;
00047   nb_valid_values = -1;
00048 }

FramePerSecond::~FramePerSecond (  ) 

Definition at line 34 of file fps.cpp.

00034                                {
00035   delete text;
00036 }    


Member Function Documentation

void FramePerSecond::AddOneFrame (  ) 

Definition at line 64 of file fps.cpp.

00064                                 {
00065   ++nb_frames.front();
00066 }

Here is the caller graph for this function:

void FramePerSecond::Draw (  ) 

Definition at line 96 of file fps.cpp.

00096                          {
00097   if( !display )
00098     return;
00099   if( average < 0 )
00100     return;
00101   
00102   char buffer[20];
00103   
00104   snprintf(buffer, sizeof(buffer)-1, "%.1f", average);
00105   buffer[sizeof(buffer)-1] = '\0';
00106   text->Set (Format(_("%s fps"), buffer));
00107   text->DrawTopRight(AppWormux::GetInstance()->video.window.GetWidth()-1,0);
00108 }

Here is the call graph for this function:

Here is the caller graph for this function:

void FramePerSecond::Refresh (  ) 

Definition at line 68 of file fps.cpp.

00069 {
00070   uint nv_temps = SDL_GetTicks();   
00071    
00072   // Pas encore l'heure de recalculer : exit !
00073   if (nv_temps <= time_in_second)
00074     return;
00075 
00076   // On décale !
00077   while (time_in_second < nv_temps){
00078     time_in_second += 1000;
00079     nb_frames.pop_back();
00080     nb_frames.push_front(0);
00081     if (nb_valid_values < (int)nb_frames.size()-1)
00082       nb_valid_values++;
00083   }
00084 
00085   // Recalcule la average
00086   if (0 < nb_valid_values){
00087     average = 0;
00088     std::list<uint>::const_iterator it=nb_frames.begin();
00089     ++it;
00090     for (int i=1; i<=nb_valid_values; ++i, ++it)
00091       average += *it;
00092     average /= nb_valid_values;
00093   }
00094 }

Here is the caller graph for this function:

void FramePerSecond::Reset (  ) 

Definition at line 50 of file fps.cpp.

00050                           {
00051   average = -1;
00052   nb_frames.clear();
00053   
00054   for( uint i=0; i<=MIN_NB_VALUES; ++i )
00055     nb_frames.push_back (0);
00056   
00057   time_in_second = SDL_GetTicks()+1000;
00058   nb_valid_values = -1;
00059 
00060   if(text == NULL)
00061     text = new Text("");
00062 }

Here is the caller graph for this function:


Member Data Documentation

double FramePerSecond::average [private]

Definition at line 35 of file fps.h.

bool FramePerSecond::display

Definition at line 41 of file fps.h.

const uint FramePerSecond::MIN_NB_VALUES = 4 [static, private]

Definition at line 32 of file fps.h.

std::list<uint> FramePerSecond::nb_frames [private]

Definition at line 36 of file fps.h.

int FramePerSecond::nb_valid_values [private]

Definition at line 34 of file fps.h.

Text* FramePerSecond::text [private]

Definition at line 38 of file fps.h.

uint FramePerSecond::time_in_second [private]

Definition at line 37 of file fps.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:46:16 2007 for Wormux by  doxygen 1.4.7