ezEngine  Milestone 9
Clock_inl.h
1 #pragma once
2 
4 
5 inline void ezClock::SetClockName(const char* szName)
6 {
7  m_sName = szName;
8 }
9 
10 inline const char* ezClock::GetClockName() const
11 {
12  return m_sName.GetData();
13 }
14 
16 {
17  m_pTimeStepSmoother = pSmoother;
18 
19  if (m_pTimeStepSmoother)
20  m_pTimeStepSmoother->Reset(this);
21 }
22 
24 {
25  return m_pTimeStepSmoother;
26 }
27 
28 inline void ezClock::SetPaused(bool bPaused)
29 {
30  m_bPaused = bPaused;
31 
32  // when we enter a pause, inform the time step smoother to throw away his statistics
33  if (bPaused && m_pTimeStepSmoother)
34  m_pTimeStepSmoother->Reset(this);
35 }
36 
37 inline bool ezClock::GetPaused() const
38 {
39  return m_bPaused;
40 }
41 
43 {
44  return m_FixedTimeStep;
45 }
46 
48 {
49  return m_AccumulatedTime;
50 }
51 
53 {
54  return m_LastTimeDiff;
55 }
56 
57 inline double ezClock::GetSpeed() const
58 {
59  return m_Speed;
60 }
61 
63 {
64  EZ_ASSERT_DEV(tMin >= ezTime::Seconds(0.0), "Time flows in one direction only.");
65 
66  m_MinTimeStep = tMin;
67 }
68 
70 {
71  EZ_ASSERT_DEV(tMax >= ezTime::Seconds(0.0), "Time flows in one direction only.");
72 
73  m_MaxTimeStep = tMax;
74 }
75 
77 {
78  return m_MinTimeStep;
79 }
80 
82 {
83  return m_MaxTimeStep;
84 }
85 
87 {
88  EZ_ASSERT_DEV(m_FixedTimeStep.GetSeconds() >= 0.0, "Fixed Time Stepping cannot reverse time!");
89 
90  m_FixedTimeStep = tDiff;
91 }
92 
93 inline void ezClock::SetSpeed(double fFactor)
94 {
95  EZ_ASSERT_DEV(fFactor >= 0.0, "Time cannot run backwards.");
96 
97  m_Speed = fFactor;
98 }
99 
ezTime GetFixedTimeStep() const
Returns the value for the fixed time step (zero if it is disabled).
Definition: Clock_inl.h:42
const char * GetClockName() const
Returns the name of the clock. All clocks get default names 'Clock N', unless the user specifies anot...
Definition: Clock_inl.h:10
void SetMaximumTimeStep(ezTime tMax)
Sets the maximum time that may pass between clock updates.
Definition: Clock_inl.h:69
ezTimeStepSmoothing * GetTimeStepSmoothing() const
Returns the object used for time step smoothing (if any).
Definition: Clock_inl.h:23
void SetFixedTimeStep(ezTime tDiff=ezTime())
Sets a fixed time step for updating the clock.
Definition: Clock_inl.h:86
Base class for all time step smoothing algorithms.
Definition: Clock.h:174
void SetPaused(bool bPaused)
Sets the clock to be paused or running.
Definition: Clock_inl.h:28
bool GetPaused() const
Returns the paused state.
Definition: Clock_inl.h:37
void SetSpeed(double fFactor)
The factor with which to scale the time step during calls to Update().
Definition: Clock_inl.h:93
void SetClockName(const char *szName)
Sets the name of the clock. Useful to identify the clock in tools such as ezInspector.
Definition: Clock_inl.h:5
ezTime GetAccumulatedTime() const
Returns the accumulated time since the last call to Reset().
Definition: Clock_inl.h:47
#define EZ_ASSERT_DEV(bCondition, szErrorMsg,...)
Macro to raise an error, if a condition is not met.
Definition: Assert.h:116
The time class encapsulates a double value storing the time in seconds.
Definition: Time.h:10
ezTime GetMinimumTimeStep() const
Returns the value for the minimum time step.
Definition: Clock_inl.h:76
ezTime GetMaximumTimeStep() const
Returns the value for the maximum time step.
Definition: Clock_inl.h:81
void SetMinimumTimeStep(ezTime tMin)
Sets the minimum time that must pass between clock updates.
Definition: Clock_inl.h:62
double GetSpeed() const
Returns the clock speed multiplier.
Definition: Clock_inl.h:57
EZ_ALWAYS_INLINE static constexpr ezTime Seconds(double fSeconds)
Creates an instance of ezTime that was initialized from seconds.
Definition: Time.h:26
void SetTimeStepSmoothing(ezTimeStepSmoothing *pSmoother)
Sets a time step smoother for this clock. Pass nullptr to deactivate time step smoothing.
Definition: Clock_inl.h:15
constexpr double GetSeconds() const
Returns the seconds value.
Definition: Time_inl.h:35
virtual void Reset(const ezClock *pClock)=0
Called when ezClock::Reset(), ezClock::Load() or ezClock::SetPaused(true) was called.
ezTime GetTimeDiff() const
Returns the time difference between the last two calls to Update().
Definition: Clock_inl.h:52
const char * GetData() const
Returns a pointer to the internal Utf8 string.
Definition: String_inl.h:71