16 TimeWarp(uint32_t realTimeNow,
float initialTimeScale = 1.0f)
17 : mRealTime(realTimeNow), mLastRealTime(realTimeNow),
18 mStartTime(realTimeNow), mTimeScale(initialTimeScale) {}
19 void setTimeScale(
float timeScale) { mTimeScale = timeScale; }
20 float getTimeScale()
const {
return mTimeScale; }
21 void update(uint32_t timeNow) {
29 uint32_t getTime()
const {
return mRealTime; }
30 uint32_t reset(uint32_t timeNow,
float timeScale = 1.0f) {
32 mLastRealTime = timeNow;
34 mTimeScale = timeScale;
38 void setMode(MODE mode) { mMode = mode; }
41 void applyExact(uint32_t timeNow) {
42 uint32_t elapsedRealTime = timeNow - mLastRealTime;
43 int32_t diff =
static_cast<int32_t
>(elapsedRealTime * mTimeScale);
45 if (mRealTime + diff < mStartTime) {
46 mRealTime = mStartTime;
47 mLastRealTime = mStartTime;
50 uint32_t newRealTime = mRealTime + diff;
51 if (newRealTime > mRealTime) {
53 mRealTime = mStartTime;
54 mLastRealTime = mStartTime;
59 mLastRealTime = timeNow;
62 uint32_t mRealTime = 0;
63 uint32_t mLastRealTime = 0;
64 uint32_t mStartTime = 0;
65 float mTimeScale = 1.0f;