From bdfc2397e2fa7ac37d551ec17a3f73db7d7f6f27 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 3 Feb 2026 11:17:36 -0500 Subject: [PATCH] Fix up the animation test so that it works with random timings even if the example has a timing. --- Makefile | 4 ++-- animate2.cpp | 17 +++++++++-------- assets/animate2.json | 2 +- tests/animate2.cpp | 8 ++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 015f334..9b12693 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests -d yes "[animation-new]" + ./builddir/runtests -d yes run: build test ifeq '$(OS)' 'Windows_NT' @@ -60,7 +60,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests -e "[animation-new]" + gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/animate2.cpp b/animate2.cpp index 7d96c42..2b57eb2 100644 --- a/animate2.cpp +++ b/animate2.cpp @@ -58,17 +58,18 @@ namespace animate2 { dbc::check(sequence.frame_count == sequence.frames.size(), "frame_count doesn't match frame.size()"); auto duration = sequence.durations.at(sequence.current); + auto elapsed = sequence.timer.getElapsedTime().toDuration(); + // std::cout << "subframe: " << sequence.subframe << " elapsed: " << elapsed << " duration: " << duration << std::endl; bool frame_change = false; - if(sequence.timer.getElapsedTime() >= duration) { + if(elapsed < duration) { + // BUG: subframe will just run crazy because I don't actually do delta time difference here vvvvv + sequence.subframe = std::lerp(sequence.subframe, 1.0, sequence.timer.DELTA * transform.ease_rate); + } else { sequence.timer.restart(); sequence.current++; if(sequence.subframe > SUB_FRAME_SENSITIVITY) sequence.subframe = 0.0f; frame_change = true; - } else { - sequence.subframe = std::lerp(sequence.subframe, 1.0, sequence.timer.DELTA * transform.ease_rate); - - std::cout << "subframe: " << sequence.subframe << " duration: " << duration << std::endl; } if(sequence.current >= sequence.frame_count) { @@ -152,9 +153,9 @@ namespace animate2 { motion(*this, pos_out, scale_out, tick); - fmt::println("sub: {}, tick: {}, tr: {},{}; pos: {},{}; scale: {},{}", - seq.subframe, tick, min_y, max_y, pos_out.x, pos_out.y, - scale_out.x, scale_out.y); + // fmt::println("sub: {}, tick: {}, tr: {},{}; pos: {},{}; scale: {},{}", + // seq.subframe, tick, min_y, max_y, pos_out.x, pos_out.y, + // scale_out.x, scale_out.y); } Animate2 load(const std::string &file, const std::string &anim_name) { diff --git a/assets/animate2.json b/assets/animate2.json index 6d4bc10..736820d 100644 --- a/assets/animate2.json +++ b/assets/animate2.json @@ -7,7 +7,7 @@ }, "sequence": { "frames": [0, 1], - "durations": [33, 33] + "durations": [800, 200] }, "transform": { "min_x": 0.6, diff --git a/tests/animate2.cpp b/tests/animate2.cpp index a061a75..64c2cb4 100644 --- a/tests/animate2.cpp +++ b/tests/animate2.cpp @@ -45,6 +45,7 @@ TEST_CASE("new animation system", "[animation-new]") { textures::init(); auto anim = animate2::load("assets/animate2.json", "rat_king_boss"); + anim.sequence.durations = {Random::milliseconds(5, 33), Random::milliseconds(5, 33)}; PLAY_TEST(anim); bool onLoop_ran = false; @@ -110,7 +111,7 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") { while(anim.playing) { anim.update(); - // NOTE: possibly find a way to only run apply on frame change? + FAKE_RENDER(); } REQUIRE(loop_ran == true); @@ -139,8 +140,7 @@ TEST_CASE("confirm transition changes work", "[animation-new]") { while(anim.playing) { anim.update(); anim.motion(sprite, pos, scale); - - std::this_thread::sleep_for(10ms); + FAKE_RENDER(); } REQUIRE(anim.playing == false); @@ -155,6 +155,6 @@ TEST_CASE("playing with delta time", "[animation-new]") { for(int i = 0; i < 20; i++) { FAKE_RENDER(); auto [tick_count, alpha] = timer.commit(); - fmt::println("tick: {}, alpha: {}", tick_count, alpha); + // fmt::println("tick: {}, alpha: {}", tick_count, alpha); } }