Plasma Engine  2.0
Loading...
Searching...
No Matches
Clock_inl.h
1#pragma once
2
3#include <Foundation/Time/Clock.h>
4
6{
7 m_sName = sName;
8}
9
11{
12 return m_sName;
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
28inline void plClock::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
37inline bool plClock::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
57inline double plClock::GetSpeed() const
58{
59 return m_fSpeed;
60}
61
63{
64 PL_ASSERT_DEV(min >= plTime::MakeFromSeconds(0.0), "Time flows in one direction only.");
65
66 m_MinTimeStep = min;
67}
68
70{
71 PL_ASSERT_DEV(max >= plTime::MakeFromSeconds(0.0), "Time flows in one direction only.");
72
73 m_MaxTimeStep = max;
74}
75
77{
78 return m_MinTimeStep;
79}
80
82{
83 return m_MaxTimeStep;
84}
85
87{
88 PL_ASSERT_DEV(m_FixedTimeStep.GetSeconds() >= 0.0, "Fixed Time Stepping cannot reverse time!");
89
90 m_FixedTimeStep = diff;
91}
92
93inline void plClock::SetSpeed(double fFactor)
94{
95 PL_ASSERT_DEV(fFactor >= 0.0, "Time cannot run backwards.");
96
97 m_fSpeed = fFactor;
98}
plTime GetTimeDiff() const
Returns the time difference between the last two calls to Update().
Definition Clock_inl.h:52
double GetSpeed() const
Returns the clock speed multiplier.
Definition Clock_inl.h:57
plStringView 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 SetMinimumTimeStep(plTime min)
Sets the minimum time that must pass between clock updates.
Definition Clock_inl.h:62
bool GetPaused() const
Returns the paused state.
Definition Clock_inl.h:37
plTime GetMinimumTimeStep() const
Returns the value for the minimum time step.
Definition Clock_inl.h:76
plTimeStepSmoothing * GetTimeStepSmoothing() const
Returns the object used for time step smoothing (if any).
Definition Clock_inl.h:23
void SetPaused(bool bPaused)
Sets the clock to be paused or running.
Definition Clock_inl.h:28
void SetTimeStepSmoothing(plTimeStepSmoothing *pSmoother)
Sets a time step smoother for this clock. Pass nullptr to deactivate time step smoothing.
Definition Clock_inl.h:15
void SetClockName(plStringView sName)
Sets the name of the clock. Useful to identify the clock in tools such as plInspector.
Definition Clock_inl.h:5
plTime GetAccumulatedTime() const
Returns the accumulated time since the last call to Reset().
Definition Clock_inl.h:47
void SetSpeed(double fFactor)
The factor with which to scale the time step during calls to Update().
Definition Clock_inl.h:93
plTime GetFixedTimeStep() const
Returns the value for the fixed time step (zero if it is disabled).
Definition Clock_inl.h:42
void SetFixedTimeStep(plTime diff=plTime())
Sets a fixed time step for updating the clock.
Definition Clock_inl.h:86
plTime GetMaximumTimeStep() const
Returns the value for the maximum time step.
Definition Clock_inl.h:81
void SetMaximumTimeStep(plTime max)
Sets the maximum time that may pass between clock updates.
Definition Clock_inl.h:69
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Base class for all time step smoothing algorithms.
Definition Clock.h:175
virtual void Reset(const plClock *pClock)=0
Called when plClock::Reset(), plClock::Load() or plClock::SetPaused(true) was called.
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30
constexpr double GetSeconds() const
Returns the seconds value.
Definition Time_inl.h:30