Fix up the animation test so that it works with random timings even if the example has a timing.
This commit is contained in:
parent
dea0607901
commit
bdfc2397e2
4 changed files with 16 additions and 15 deletions
4
Makefile
4
Makefile
|
|
@ -37,7 +37,7 @@ tracy_build:
|
||||||
meson compile -j 10 -C builddir
|
meson compile -j 10 -C builddir
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
./builddir/runtests -d yes "[animation-new]"
|
./builddir/runtests -d yes
|
||||||
|
|
||||||
run: build test
|
run: build test
|
||||||
ifeq '$(OS)' 'Windows_NT'
|
ifeq '$(OS)' 'Windows_NT'
|
||||||
|
|
@ -60,7 +60,7 @@ clean:
|
||||||
meson compile --clean -C builddir
|
meson compile --clean -C builddir
|
||||||
|
|
||||||
debug_test: build
|
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:
|
win_installer:
|
||||||
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'
|
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'
|
||||||
|
|
|
||||||
17
animate2.cpp
17
animate2.cpp
|
|
@ -58,17 +58,18 @@ namespace animate2 {
|
||||||
dbc::check(sequence.frame_count == sequence.frames.size(), "frame_count doesn't match frame.size()");
|
dbc::check(sequence.frame_count == sequence.frames.size(), "frame_count doesn't match frame.size()");
|
||||||
|
|
||||||
auto duration = sequence.durations.at(sequence.current);
|
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;
|
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.timer.restart();
|
||||||
sequence.current++;
|
sequence.current++;
|
||||||
if(sequence.subframe > SUB_FRAME_SENSITIVITY) sequence.subframe = 0.0f;
|
if(sequence.subframe > SUB_FRAME_SENSITIVITY) sequence.subframe = 0.0f;
|
||||||
frame_change = true;
|
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) {
|
if(sequence.current >= sequence.frame_count) {
|
||||||
|
|
@ -152,9 +153,9 @@ namespace animate2 {
|
||||||
|
|
||||||
motion(*this, pos_out, scale_out, tick);
|
motion(*this, pos_out, scale_out, tick);
|
||||||
|
|
||||||
fmt::println("sub: {}, tick: {}, tr: {},{}; pos: {},{}; scale: {},{}",
|
// fmt::println("sub: {}, tick: {}, tr: {},{}; pos: {},{}; scale: {},{}",
|
||||||
seq.subframe, tick, min_y, max_y, pos_out.x, pos_out.y,
|
// seq.subframe, tick, min_y, max_y, pos_out.x, pos_out.y,
|
||||||
scale_out.x, scale_out.y);
|
// scale_out.x, scale_out.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Animate2 load(const std::string &file, const std::string &anim_name) {
|
Animate2 load(const std::string &file, const std::string &anim_name) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
},
|
},
|
||||||
"sequence": {
|
"sequence": {
|
||||||
"frames": [0, 1],
|
"frames": [0, 1],
|
||||||
"durations": [33, 33]
|
"durations": [800, 200]
|
||||||
},
|
},
|
||||||
"transform": {
|
"transform": {
|
||||||
"min_x": 0.6,
|
"min_x": 0.6,
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ TEST_CASE("new animation system", "[animation-new]") {
|
||||||
textures::init();
|
textures::init();
|
||||||
|
|
||||||
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
|
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
|
||||||
|
anim.sequence.durations = {Random::milliseconds(5, 33), Random::milliseconds(5, 33)};
|
||||||
PLAY_TEST(anim);
|
PLAY_TEST(anim);
|
||||||
|
|
||||||
bool onLoop_ran = false;
|
bool onLoop_ran = false;
|
||||||
|
|
@ -110,7 +111,7 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
|
||||||
|
|
||||||
while(anim.playing) {
|
while(anim.playing) {
|
||||||
anim.update();
|
anim.update();
|
||||||
// NOTE: possibly find a way to only run apply on frame change?
|
FAKE_RENDER();
|
||||||
}
|
}
|
||||||
|
|
||||||
REQUIRE(loop_ran == true);
|
REQUIRE(loop_ran == true);
|
||||||
|
|
@ -139,8 +140,7 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
|
||||||
while(anim.playing) {
|
while(anim.playing) {
|
||||||
anim.update();
|
anim.update();
|
||||||
anim.motion(sprite, pos, scale);
|
anim.motion(sprite, pos, scale);
|
||||||
|
FAKE_RENDER();
|
||||||
std::this_thread::sleep_for(10ms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
REQUIRE(anim.playing == false);
|
REQUIRE(anim.playing == false);
|
||||||
|
|
@ -155,6 +155,6 @@ TEST_CASE("playing with delta time", "[animation-new]") {
|
||||||
for(int i = 0; i < 20; i++) {
|
for(int i = 0; i < 20; i++) {
|
||||||
FAKE_RENDER();
|
FAKE_RENDER();
|
||||||
auto [tick_count, alpha] = timer.commit();
|
auto [tick_count, alpha] = timer.commit();
|
||||||
fmt::println("tick: {}, alpha: {}", tick_count, alpha);
|
// fmt::println("tick: {}, alpha: {}", tick_count, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue