1 // Description:
2 //   Helpers to count Frames Per Second.
3 //
4 // Copyright (C) 2001 Frank Becker
5 //
6 // This program is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free Software
8 // Foundation;  either version 2 of the License,  or (at your option) any  later
9 // version.
10 //
11 // This program is distributed in the hope that it will be useful,  but  WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
14 //
15 #include "FPS.hpp"
16 
17 #include <stdio.h>
18 #include "Timer.hpp"
19 
WPP(float period)20 WPP::WPP( float period):
21     _cpp(0.0),
22     _period(period),
23     _oldTime(0.0),
24     _count(0)
25 {
26 }
27 
Update(void)28 void WPP::Update( void)
29 {
30     float newTime = Timer::getTime();
31     _count++;
32 
33     if( (newTime-_oldTime) > _period)
34     {
35 	_cpp = ((float)_count)/(newTime-_oldTime);
36 	_count = 0;
37 	_oldTime = newTime;
38     }
39 }
40 
41 WPP FPS::_wpp(1.0);
42 char FPS::_fpsString[10];
43 
GetFPSString(void)44 const char *FPS::GetFPSString( void)
45 {
46     sprintf( _fpsString, "%3.1f", FPS::GetFPS());
47     return _fpsString;
48 }
49