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 #pragma once
22 
23 #include <ctime>
24 #include <string>
25 
26 /*! \class Clock
27 	\brief Game Timing Management
28 	\details This class represents a clock. It can be started, paused, resetted,
29 			and it is possible to get the time in a string for in-game representation
30 */
31 class Clock
32 {
33 	public:
34 		/// default c'tor
35 		Clock();
36 
37 		/// starts/unpauses the clock
38 		void start();
39 		/// pauses the clock
40 		void stop();
41 
42 		/// resets the clock. after this, the clock is paused.
43 		void reset();
44 
45 		/// gets whether the clock is currently running
46 		bool isRunning() const;
47 
48 		/// this function has to be called each frame. It calculates
49 		///	the passed time;
50 		void step();
51 
52 		/// gets the time in seconds as an integer
53 		int getTime() const;
54 
55 		/// set the time to a specified value
56 		/// \param newTime: new time in seconds
57 		void setTime(int newTime);
58 
59 		/// returns the time as a string
60 		std::string getTimeString() const;
61 
62 	private:
63 		/// is the clock currently running?
64 		bool mRunning;
65 
66 		/// recorded time in seconds
67 		time_t mGameTime;
68 
69 		/// last time that step was called.
70 		/// needed to calculate the time difference.
71 		time_t mLastTime;
72 
73 };
74