#include <fps.h>
Collaboration diagram for FramePerSecond:
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< uint > | nb_frames |
uint | time_in_second |
Text * | text |
Static Private Attributes | |
static const uint | MIN_NB_VALUES = 4 |
Definition at line 28 of file fps.h.
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 | ( | ) |
void FramePerSecond::AddOneFrame | ( | ) |
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:
double FramePerSecond::average [private] |
const uint FramePerSecond::MIN_NB_VALUES = 4 [static, private] |
std::list<uint> FramePerSecond::nb_frames [private] |
int FramePerSecond::nb_valid_values [private] |
Text* FramePerSecond::text [private] |
uint FramePerSecond::time_in_second [private] |