ezEngine  Milestone 9
Clock.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Foundation/Basics.h>
6 #include <Foundation/Communication/Event.h>
7 #include <Foundation/Containers/DynamicArray.h>
8 #include <Foundation/IO/Stream.h>
9 #include <Foundation/Time/Time.h>
10 
12 
14 class EZ_FOUNDATION_DLL ezClock
15 {
16 public:
18  static ezClock* GetGlobalClock() { return s_pGlobalClock; }
19 
20 public:
22  ezClock(const char* szName); // [tested]
23 
28  void Reset(bool bEverything); // [tested]
29 
35  void Update(); // [tested]
36 
40  void SetTimeStepSmoothing(ezTimeStepSmoothing* pSmoother);
41 
43  ezTimeStepSmoothing* GetTimeStepSmoothing() const; // [tested]
44 
46  void SetPaused(bool bPaused); // [tested]
47 
49  bool GetPaused() const; // [tested]
50 
57  void SetFixedTimeStep(ezTime tDiff = ezTime()); // [tested]
58 
60  ezTime GetFixedTimeStep() const; // [tested]
61 
68  void SetAccumulatedTime(ezTime t); // [tested]
69 
75  ezTime GetAccumulatedTime() const; // [tested]
76 
81  ezTime GetTimeDiff() const; // [tested]
82 
84  void SetSpeed(double fFactor); // [tested]
85 
87  double GetSpeed() const; // [tested]
88 
96  void SetMinimumTimeStep(ezTime tMin); // [tested]
97 
105  void SetMaximumTimeStep(ezTime tMax); // [tested]
106 
109  ezTime GetMinimumTimeStep() const; // [tested]
110 
113  ezTime GetMaximumTimeStep() const; // [tested]
114 
116  void Save(ezStreamWriter& Stream) const;
117 
119  void Load(ezStreamReader& Stream);
120 
122  void SetClockName(const char* szName);
123 
126  const char* GetClockName() const;
127 
128 
129 public:
131  struct EventData
132  {
133  const char* m_szClockName;
134 
135  ezTime m_RawTimeStep;
136  ezTime m_SmoothedTimeStep;
137  };
138 
140 
142  static void AddEventHandler(Event::Handler handler) { s_TimeEvents.AddEventHandler(handler); }
143 
145  static void RemoveEventHandler(Event::Handler handler) { s_TimeEvents.RemoveEventHandler(handler); }
146 
147 
148 private:
149  EZ_MAKE_SUBSYSTEM_STARTUP_FRIEND(Foundation, Clock);
150 
151  static Event s_TimeEvents;
152  static ezClock* s_pGlobalClock;
153 
154  ezString m_sName;
155 
156  ezTime m_AccumulatedTime;
157  ezTime m_LastTimeDiff;
158  ezTime m_FixedTimeStep;
159  ezTime m_LastTimeUpdate;
160  ezTime m_MinTimeStep;
161  ezTime m_MaxTimeStep;
162 
163  double m_Speed;
164  bool m_bPaused;
165 
166  ezTimeStepSmoothing* m_pTimeStepSmoother;
167 };
168 
169 
174 class EZ_FOUNDATION_DLL ezTimeStepSmoothing
175 {
176 public:
177  virtual ~ezTimeStepSmoothing() {}
178 
190  virtual ezTime GetSmoothedTimeStep(ezTime RawTimeStep, const ezClock* pClock) = 0;
191 
196  virtual void Reset(const ezClock* pClock) = 0;
197 };
198 
199 
200 
201 #include <Foundation/Time/Implementation/Clock_inl.h>
202 
Base class for all time step smoothing algorithms.
Definition: Clock.h:174
Definition: String.h:136
Interface for binary in (read) streams.
Definition: Stream.h:14
static ezClock * GetGlobalClock()
Returns the global clock.
Definition: Clock.h:18
Definition: Event.h:136
static void AddEventHandler(Event::Handler handler)
Allows to register a function as an event receiver. All receivers will be notified in the order that ...
Definition: Clock.h:142
The time class encapsulates a double value storing the time in seconds.
Definition: Time.h:10
Interface for binary out (write) streams.
Definition: Stream.h:86
#define EZ_MAKE_SUBSYSTEM_STARTUP_FRIEND(GroupName, SubsystemName)
This inserts a friend declaration into a class, such that the given group/subsystem can access privat...
Definition: StaticSubSystem.h:107
A clock that can be speed up, slowed down, paused, etc. Useful for updating game logic, rendering, etc.
Definition: Clock.h:14
static void RemoveEventHandler(Event::Handler handler)
Unregisters a previously registered receiver. It is an error to unregister a receiver that was not re...
Definition: Clock.h:145
The data that is sent through the event interface.
Definition: Clock.h:131