From f7b4866811c63ae24c366d9452e53d24e504336f Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 12 Dec 2024 19:47:59 +0100 Subject: fps fix + regression test --- src/test/LoopTimerTest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/test/LoopTimerTest.cpp') diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp index 5e1eccf..c468567 100644 --- a/src/test/LoopTimerTest.cpp +++ b/src/test/LoopTimerTest.cpp @@ -76,3 +76,19 @@ TEST_F(LoopTimerTest, getCurrentTime) { ASSERT_NEAR(loop_timer.get_elapsed_time().count(), elapsed_time, 5); } +TEST_F(LoopTimerTest, getFPS) { + // Set the target FPS to 60 (which gives a target time per frame of ~16.67 ms) + loop_timer.set_target_framerate(60); + + auto start_time = steady_clock::now(); + loop_timer.enforce_frame_rate(); + + auto elapsed_time = steady_clock::now() - start_time; + loop_timer.update(); + unsigned int fps = loop_timer.get_fps(); + auto elapsed_ms = duration_cast(elapsed_time).count(); + + // For 60 FPS, the target frame time is around 16.67ms + ASSERT_NEAR(elapsed_ms, 16.7, 1); + ASSERT_NEAR(fps, 60, 2); +} -- cgit v1.2.3