Skip to content

Commit

Permalink
Fix scaling frame duration twice in Timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mogemimi committed Aug 25, 2018
1 parent 352c038 commit 01790cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Application/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/FrameworkTest/Application/TimerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Pomdog/Application/GameClock.hpp>
#include <gtest/iutest_switch.hpp>
#include <chrono>
#include <thread>

using namespace Pomdog;

Expand Down Expand Up @@ -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);
}

0 comments on commit 01790cd

Please sign in to comment.