Now have a timer for animations that does ticks with deltatime...maybe it works.

This commit is contained in:
Zed A. Shaw 2026-01-27 12:52:33 -05:00
parent c0f69ed026
commit b7394f832d
5 changed files with 121 additions and 6 deletions

View file

@ -51,12 +51,16 @@ Animate2 crafter() {
return {sheet, sequence, transform};
}
void FAKE_RENDER() {
std::this_thread::sleep_for(Random::milliseconds(5, 32));
}
void PLAY_TEST(Animate2 &anim) {
anim.play();
while(anim.playing) {
anim.update();
std::this_thread::sleep_for(Random::milliseconds(1, 100));
FAKE_RENDER();
}
REQUIRE(anim.playing == false);
@ -114,6 +118,7 @@ TEST_CASE("new animation system", "[animation-new]") {
};
}
TEST_CASE("confirm frame sequencing works", "[animation-new]") {
textures::init();
animation::init();
@ -165,15 +170,37 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
anim.play();
sf::Clock clock;
clock.start();
sf::Time start;
sf::Time delta;
while(anim.playing) {
start = clock.getElapsedTime();
anim.update();
anim.motion(pos, scale);
std::this_thread::sleep_for(10ms);
fmt::println("POSITION: {},{}; SCALE: {},{}; current: {}; subframe: {}",
pos.x, pos.y, scale.x, scale.y, anim.$sequence.current, anim.$sequence.subframe);
delta = clock.getElapsedTime() - start;
fmt::println("FRAME RATE {}", 1.0f / delta.asSeconds());
}
REQUIRE(anim.playing == false);
REQUIRE(pos != sf::Vector2f{0,0});
REQUIRE(scale != sf::Vector2f{0,0});
}
TEST_CASE("playing with delta time", "[animation-new]") {
animate2::Timer timer;
for(int i = 0; i < 20; i++) {
timer.begin();
FAKE_RENDER();
auto [tick_count, alpha] = timer.commit();
fmt::println("tick: {}, alpha: {}", tick_count, alpha);
}
}