Skip to content

Commit

Permalink
animation: test adding/removing vars during ::tick
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma committed Jan 11, 2025
1 parent 5dd4f4a commit db5557e
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions tests/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ class CMyAnimationManager : public CAnimationManager {

const auto SPENT = PAV->getPercent();
const auto PBEZIER = getBezier(PAV->getBezierName());
const auto POINTY = PBEZIER->getYForPoint(SPENT);

if (POINTY >= 1.f || !PAV->enabled()) {
if (SPENT >= 1.f || !PAV->enabled()) {
PAV->warp();
continue;
}

const auto POINTY = PBEZIER->getYForPoint(SPENT);

switch (PAV->m_Type) {
case eAVTypes::INT: {
auto avInt = dynamic_cast<CAnimatedVariable<int>*>(PAV.get());
Expand Down Expand Up @@ -253,6 +254,9 @@ int main(int argc, char** argv, char** envp) {
EXPECT(s.m_iA->getStyle(), "");
EXPECT(s.m_iA->getPercent(), 1.f);

// Reset
animationTree.setConfigForNode("default", 1, 1, "default");

//
// Test callbacks
//
Expand Down Expand Up @@ -282,5 +286,48 @@ int main(int argc, char** argv, char** envp) {
EXPECT(updateCallbackRan, true);
EXPECT(endCallbackRan, true);

std::vector<PANIMVAR<int>> vars;
for (int i = 0; i < 10; i++) {
vars.resize(vars.size() + 1);
gAnimationManager.createAnimation(1, vars.back(), "default");
*vars.back() = 1337;
}

// test adding / removing vars during a tick
s.m_iA->resetAllCallbacks();
s.m_iA->setUpdateCallback([&vars](WP<CBaseAnimatedVariable> v) {
if (v.lock() != vars.back())
vars.back()->warp();
});
s.m_iA->setCallbackOnEnd([&s, &vars](auto) {
vars.resize(vars.size() + 1);
gAnimationManager.createAnimation(1, vars.back(), "default");
*vars.back() = 1337;
});

*s.m_iA = 1000000;

while (gAnimationManager.shouldTickForNext()) {
gAnimationManager.tick();
}

EXPECT(s.m_iA->value(), 1000000);
// all vars should be set to 1337
EXPECT(std::find_if(vars.begin(), vars.end(), [](const auto& v) { return v->value() != 1337; }) == vars.end(), true);

// test one-time callbacks
endCallbackRan = false;
s.m_iA->resetAllCallbacks();
s.m_iA->setCallbackOnEnd([&endCallbackRan](auto) { endCallbackRan = true; }, true);

EXPECT(endCallbackRan, true);

endCallbackRan = false;

s.m_iA->setValueAndWarp(10);

EXPECT(endCallbackRan, false);
EXPECT(s.m_iA->value(), 10);

return ret;
}

0 comments on commit db5557e

Please sign in to comment.