From 422241479cf54aac49fe0a8c8cadc41b98cfaf1b Mon Sep 17 00:00:00 2001 From: Light Date: Fri, 9 Jul 2021 11:56:06 +0430 Subject: [PATCH] Time - Fixed DeltaTimer --- Engine/src/Engine/Time/Timer.cpp | 6 +++--- Engine/src/Engine/Time/Timer.h | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Engine/src/Engine/Time/Timer.cpp b/Engine/src/Engine/Time/Timer.cpp index 8a645a0..8e379fd 100644 --- a/Engine/src/Engine/Time/Timer.cpp +++ b/Engine/src/Engine/Time/Timer.cpp @@ -5,9 +5,9 @@ namespace Light { void DeltaTimer::Update() { - auto current = std::chrono::steady_clock::now(); - m_DeltaTime = ((std::chrono::duration_cast(current - m_Previous)).count()) / 1000.0f; - m_Previous = current; + float currentFrame = timer.GetElapsedTime(); + m_DeltaTime = currentFrame - m_PreviousFrame; + m_PreviousFrame = currentFrame; } } \ No newline at end of file diff --git a/Engine/src/Engine/Time/Timer.h b/Engine/src/Engine/Time/Timer.h index 84f363f..afdb6a3 100644 --- a/Engine/src/Engine/Time/Timer.h +++ b/Engine/src/Engine/Time/Timer.h @@ -22,13 +22,12 @@ namespace Light { class DeltaTimer { private: - std::chrono::time_point m_Previous; + Timer timer; + float m_PreviousFrame = 0.0f; float m_DeltaTime = 60.0f / 1000.0f; - + public: - DeltaTimer(): m_Previous(std::chrono::steady_clock::now()) { } - void Update(); inline float GetDeltaTime() const { return m_DeltaTime; }