You.i Engine
YiTime.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_TIME_H_
3 #define _YI_TIME_H_
4 
5 #include "framework/YiPredef.h"
6 #include "signal/YiSignal.h"
7 
8 #include <chrono>
9 
21 class CYITime
22 {
23 public:
24  static const uint32_t UPDATE_STATUS_NONE;
25  static const uint32_t UPDATE_STATUS_DISABLE_INPUT;
26  static const uint32_t UPDATE_STATUS_SCENE_DIRTY;
27 
29  {
30  friend class CYITime;
31 
32  public:
33  static const uint32_t DEFAULT_UPDATE_PRIORITY = 0;
34 
36  virtual ~UpdateListener();
37 
43  virtual bool OnFrameTimeUpdated(std::chrono::microseconds frameTime) = 0;
44 
49  virtual bool GetDisablesInput();
50 
51  private:
52  size_t m_index;
53  bool m_isRegistered;
54  };
55 
56  CYITime();
57  virtual ~CYITime();
58 
66  void UpdateTime(bool notifyListeners = true);
67 
76  void UpdateTime(std::chrono::microseconds deltaTime, bool notifyListeners = true);
77 
82 
87 
94  bool HasListeners() const;
95 
102  uint64_t GetListenerCount() const;
103 
107  std::chrono::microseconds GetFrameTime();
108 
113  uint64_t GetRefTime();
114 
118  uint32_t GetLastUpdateStatus();
119 
128  void EnableFixedTimeStep(std::chrono::microseconds fixedTimeStep);
129 
136  bool IsFixedTimeStepEnabled() const;
137 
143  void DisableFixedTimeStep();
144 
153  void SetTimeDilationFactor(float factor);
154 
159  float GetTimeDilationFactor() const;
160 
162 
163 protected:
164  void NotifyTimeUpdated(std::chrono::microseconds frameTime);
165 
166 private:
167  void OnTimeConfigurationChanged();
168 
169  std::chrono::microseconds m_frameTime;
170  std::chrono::microseconds m_refTime; // When frame count was last reset (in microSecond)
171 
172  std::vector<CYITime::UpdateListener *> m_timeUpdateListeners;
173  size_t m_timeUpdateListenersCount;
174 
175  uint32_t m_lastUpdateStatusFlags;
176 
177  std::chrono::microseconds m_fixedTimeStep;
178  float m_dilationFactor; // when larger than 1.0, causes time to appear to pass slower; when smaller than 1.0, causes time to appear to pass faster
179  std::chrono::microseconds m_previousFrameTime;
180 };
181 
184 #endif // _YI_TIME_H_
bool HasListeners() const
float GetTimeDilationFactor() const
void UpdateTime(bool notifyListeners=true)
bool IsFixedTimeStepEnabled() const
virtual bool OnFrameTimeUpdated(std::chrono::microseconds frameTime)=0
uint32_t GetLastUpdateStatus()
friend class CYITime
Definition: YiTime.h:30
uint64_t GetRefTime()
Definition: YiTime.h:28
uint64_t GetListenerCount() const
void UnregisterTimeUpdateListener(CYITime::UpdateListener *pListener)
static const uint32_t UPDATE_STATUS_NONE
A bitfield value indicating no update status.
Definition: YiTime.h:24
static const uint32_t UPDATE_STATUS_DISABLE_INPUT
A bitfield value indicating that input is disabled.
Definition: YiTime.h:25
global class used to notify the system of time updates
Definition: YiTime.h:21
void NotifyTimeUpdated(std::chrono::microseconds frameTime)
virtual bool GetDisablesInput()
virtual ~CYITime()
void SetTimeDilationFactor(float factor)
CYISignal TimeConfigurationChanged
Definition: YiTime.h:161
static const uint32_t UPDATE_STATUS_SCENE_DIRTY
A bitfield value indicating that the scene is dirty.
Definition: YiTime.h:26
static const uint32_t DEFAULT_UPDATE_PRIORITY
Definition: YiTime.h:33
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:168
void EnableFixedTimeStep(std::chrono::microseconds fixedTimeStep)
void RegisterTimeUpdateListener(CYITime::UpdateListener *pListener)
std::chrono::microseconds GetFrameTime()
void DisableFixedTimeStep()