From 975f1e364a6a68be2beca261a64ea8aecc16f6f6 Mon Sep 17 00:00:00 2001 From: Chaouki Dhib Date: Mon, 15 Apr 2019 23:31:25 +0200 Subject: Core/Movement: Add time synchronisation (#18189) --- src/common/Utilities/Timer.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/Utilities/Timer.h b/src/common/Utilities/Timer.h index be0f28a95ee..11f9cb2accc 100644 --- a/src/common/Utilities/Timer.h +++ b/src/common/Utilities/Timer.h @@ -22,13 +22,20 @@ #include "Define.h" #include -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(steady_clock::now() - ApplicationStartTime).count()); + return ApplicationStartTime; +} + +inline uint32 getMSTime() +{ + using namespace std::chrono; + + return uint32(duration_cast(steady_clock::now() - GetApplicationStartTime()).count()); } inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime) @@ -40,6 +47,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(newTime - GetApplicationStartTime()).count()); + return getMSTimeDiff(oldMSTime, newMSTime); +} + inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime) { return getMSTimeDiff(oldMSTime, getMSTime()); -- cgit v1.2.3