From 01790cddb907e2fad0be4e824746bf889d778dd2 Mon Sep 17 00:00:00 2001 From: mogemimi Date: Sun, 26 Aug 2018 04:47:37 +0900 Subject: [PATCH] Fix scaling frame duration twice in Timer --- src/Application/Timer.cpp | 2 +- test/FrameworkTest/Application/TimerTest.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Application/Timer.cpp b/src/Application/Timer.cpp index aab61df5d..4dd72c54d 100644 --- a/src/Application/Timer.cpp +++ b/src/Application/Timer.cpp @@ -19,7 +19,7 @@ Timer::Timer(GameClock & clock) return; } this->frameDuration = (frameDurationIn * this->scale); - this->totalTime += (frameDuration * this->scale); + totalTime += (frameDurationIn * scale); if (interval && (totalTime >= *interval)) { totalTime = *interval; diff --git a/test/FrameworkTest/Application/TimerTest.cpp b/test/FrameworkTest/Application/TimerTest.cpp index 4de621d0b..3092dbd6a 100644 --- a/test/FrameworkTest/Application/TimerTest.cpp +++ b/test/FrameworkTest/Application/TimerTest.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace Pomdog; @@ -47,3 +48,22 @@ TEST(Timer, Scale) timer.SetScale(-0.5); EXPECT_EQ(-0.5, timer.GetScale()); } + +TEST(Timer, Scaling) +{ + constexpr double scale = 0.4; + constexpr double epsilon = 0.001; + + GameClock clock; + Timer timer(clock); + timer.SetScale(scale); + timer.Start(); + + for (int i = 0; i < 100; i++) { + clock.Tick(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + ASSERT_EQ(scale, timer.GetScale()); + EXPECT_NEAR(clock.GetTotalGameTime().count() * scale, timer.GetTotalTime().count(), epsilon); +}