1 /*=============================================================================
2 Blobby Volley 2
3 Copyright (C) 2006 Jonathan Sieber (jonathan_sieber@yahoo.de)
4 Copyright (C) 2006 Daniel Knobe (daniel-knobe@web.de)
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 =============================================================================*/
20 
21 /**
22  * @file SpeedController.h
23  * @brief Contains a class which determine the framerate
24  */
25 
26 #pragma once
27 
28 #include "BlobbyDebug.h"
29 
30 /// \brief class controlling game speed
31 /// \details This class can control the game speed and the displayed FPS.
32 /// It is updated once a frame and waits the necessary time.
33 /// A distinction is made between game FPS and real FPS.
34 /// Game FPS is the number of game loop iterations per second,
35 /// real FPS is the number of screen updates per second. The real
36 /// FPS is reached with framedropping
37 /// The class can report how much time is actually waited. If this value
38 /// is close to zero, the real speed can be altered.
39 
40 
41 class SpeedController : public ObjectCounter<SpeedController>
42 {
43 	public:
44 		SpeedController(float gameFPS);
45 		~SpeedController();
46 
47 		void setGameSpeed(float fps);
getGameSpeed()48 		float getGameSpeed() const{return mGameFPS;}
49 
50 	/// This reports whether a framedrop is necessary to hold the real FPS
51 		bool doFramedrop() const;
52 
53 	/// gives the caller the fps of the drawn frames:
getFPS()54 		int getFPS() const { return mFPS; }
setDrawFPS(bool draw)55 		void setDrawFPS(bool draw) { mDrawFPS = draw; }  //help methods
getDrawFPS()56 		bool getDrawFPS() const { return mDrawFPS; }
57 
58 	/// This updates everything and waits the necessary time
59 		void update();
60 
setMainInstance(SpeedController * inst)61 		static void setMainInstance(SpeedController* inst) { mMainInstance = inst; }
getMainInstance()62 		static SpeedController* getMainInstance() { return mMainInstance; }
63 	private:
64 		float mGameFPS;
65 		int mFPS;
66 		int mFPSCounter;
67 		bool mFramedrop;
68 		bool mDrawFPS;
69 		static SpeedController* mMainInstance;
70 		int mOldTicks;
71 
72 		// internal data
73 		unsigned int mBeginSecond;
74 		int mCounter;
75 };
76 
77 
78