From 33bfdc0bd30f0c453c14d06fe89808b07a7843e6 Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:44:38 +0000 Subject: [PATCH] corrected implementation of GetRealElapseTime (#6422) Signed-off-by: amzn-sean <75276488+amzn-sean@users.noreply.github.com> --- Code/Framework/AzCore/AzCore/Time/TimeSystem.cpp | 7 ++++++- Code/Framework/AzCore/AzCore/Time/TimeSystem.h | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzCore/AzCore/Time/TimeSystem.cpp b/Code/Framework/AzCore/AzCore/Time/TimeSystem.cpp index a5e0908ac4..f8e254d32d 100644 --- a/Code/Framework/AzCore/AzCore/Time/TimeSystem.cpp +++ b/Code/Framework/AzCore/AzCore/Time/TimeSystem.cpp @@ -62,6 +62,7 @@ namespace AZ TimeSystem::TimeSystem() { m_lastInvokedTimeUs = static_cast(AZStd::GetTimeNowMicroSecond()); + m_realLastInvokedTimeUs = static_cast(AZStd::GetTimeNowMicroSecond()); AZ::Interface::Register(this); ITimeRequestBus::Handler::BusConnect(); } @@ -101,7 +102,11 @@ namespace AZ TimeUs TimeSystem::GetRealElapsedTimeUs() const { - return static_cast(AZStd::GetTimeNowMicroSecond()); + const TimeUs currentTime = static_cast(AZStd::GetTimeNowMicroSecond()); + m_realAccumulatedTimeUs += currentTime - m_realLastInvokedTimeUs; + m_realLastInvokedTimeUs = currentTime; + + return m_realAccumulatedTimeUs; } TimeUs TimeSystem::GetSimulationTickDeltaTimeUs() const diff --git a/Code/Framework/AzCore/AzCore/Time/TimeSystem.h b/Code/Framework/AzCore/AzCore/Time/TimeSystem.h index ded70c9be5..9d5f2a6d7c 100644 --- a/Code/Framework/AzCore/AzCore/Time/TimeSystem.h +++ b/Code/Framework/AzCore/AzCore/Time/TimeSystem.h @@ -64,6 +64,14 @@ namespace AZ //! Mutable to allow GetElapsedTimeMs/TimeUs() to be a const functions. mutable TimeUs m_accumulatedTimeUs = AZ::Time::ZeroTimeUs; + //! Used to calculate the delta time between calls to GetRealElapsedTimeMs/TimeUs(). + //! Mutable to allow GetRealElapsedTimeMs/TimeUs() to be a const functions. + mutable TimeUs m_realLastInvokedTimeUs = AZ::Time::ZeroTimeUs; + + //! Accumulates the delta time of GetRealElapsedTimeMs/TimeUs() calls. + //! Mutable to allow GetRealElapsedTimeMs/TimeUs() to be a const functions. + mutable TimeUs m_realAccumulatedTimeUs = AZ::Time::ZeroTimeUs; + //! The current game tick delta time. //! Can be affected by time system cvars. //! Updated in AdvanceTickDeltaTimes().