comparison engine/core/util/time/timemanager.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE 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 *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_TIMEMANAGER_H
23 #define FIFE_TIMEMANAGER_H
24
25 // Standard C++ library includes
26 #include <vector>
27
28 // 3rd party library includes
29
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "util/base/singleton.h"
35
36 namespace FIFE {
37
38 class TimeEvent;
39
40 /** Time Manager
41 *
42 * This class is in charge of storing the current time,
43 * average frame time, as well as controlling periodic events.
44 * Users of this class will have to manually register and
45 * unregister events.
46 *
47 * @see TimeEvent
48 */
49 class TimeManager : public DynamicSingleton<TimeManager> {
50 public:
51 /** Default constructor.
52 */
53 TimeManager();
54
55 /** Destructor.
56 */
57 virtual ~TimeManager();
58
59 /** Called once a frame and updates the timer objects and events.
60 */
61 void update();
62
63 /** Adds a TimeEvent.
64 *
65 * The event will be updated regularly, depending on its settings.
66 * @param event The TimeEvent object to be added.
67 */
68 void registerEvent(TimeEvent* event);
69
70 /** Removes a TimeEvent.
71 *
72 * Removes an event from the list. It will not be deleted.
73 * @param event The TimeEvent object to be removed.
74 */
75 void unregisterEvent(TimeEvent* event);
76
77 /** Get the time.
78 *
79 * @return The time in milliseconds.
80 */
81 unsigned long getTime() const;
82
83 /** Get the time since the last frame.
84 *
85 * @return Time since last frame in milliseconds.
86 */
87 unsigned long getTimeDelta() const;
88
89 /** Gets average frame time
90 *
91 * @return Average frame time in milliseconds.
92 */
93 double getAverageFrameTime() const;
94
95 /** Prints Timer statistics
96 */
97 void printStatistics() const;
98
99 private:
100 /// Current time in milliseconds.
101 unsigned long m_current_time;
102 /// Time since last frame in milliseconds.
103 unsigned long m_time_delta;
104 /// Average frame time in milliseconds.
105 double m_average_frame_time;
106
107 /// List of active TimeEvents.
108 std::vector<TimeEvent*> m_events_list;
109 };
110
111 }//FIFE
112
113 #endif