aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Timer.h
diff options
context:
space:
mode:
authorChaouki Dhib <chaodhib@gmail.com>2019-04-15 23:31:25 +0200
committerShauren <shauren.trinity@gmail.com>2021-11-30 22:11:36 +0100
commitc19a4db1c12b8864d6c486ee8e2f0e058fb4155a (patch)
tree1976d6734054eb05eb03322be9d76da9a0c1840c /src/common/Utilities/Timer.h
parent2f6f1c708960bfb23a0d69ce967b67b38e72b3fa (diff)
Core/Movement: Add time synchronisation (#18189)
(cherry picked from commit 975f1e364a6a68be2beca261a64ea8aecc16f6f6)
Diffstat (limited to 'src/common/Utilities/Timer.h')
-rw-r--r--src/common/Utilities/Timer.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/common/Utilities/Timer.h b/src/common/Utilities/Timer.h
index 0996c7e9dae..4abd6cc8ca1 100644
--- a/src/common/Utilities/Timer.h
+++ b/src/common/Utilities/Timer.h
@@ -21,13 +21,20 @@
#include "Define.h"
#include <chrono>
-inline uint32 getMSTime()
+inline std::chrono::steady_clock::time_point GetApplicationStartTime()
{
using namespace std::chrono;
static const steady_clock::time_point ApplicationStartTime = steady_clock::now();
- return uint32(duration_cast<milliseconds>(steady_clock::now() - ApplicationStartTime).count());
+ return ApplicationStartTime;
+}
+
+inline uint32 getMSTime()
+{
+ using namespace std::chrono;
+
+ return uint32(duration_cast<milliseconds>(steady_clock::now() - GetApplicationStartTime()).count());
}
inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
@@ -39,6 +46,14 @@ inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
return newMSTime - oldMSTime;
}
+inline uint32 getMSTimeDiff(uint32 oldMSTime, std::chrono::steady_clock::time_point newTime)
+{
+ using namespace std::chrono;
+
+ uint32 newMSTime = uint32(duration_cast<milliseconds>(newTime - GetApplicationStartTime()).count());
+ return getMSTimeDiff(oldMSTime, newMSTime);
+}
+
inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
{
return getMSTimeDiff(oldMSTime, getMSTime());