fix state machine advanceAndApply
this almost fixes the issue with ios. but somehow this ends up returning false sometimes still... it seem to stop in a similar position each time, a little nudge being enough to get it moving again for a longer while
also
```
- (bool)advanceBy:(double)elapsedSeconds
{
return instance->advanceAndApply(elapsedSeconds);
}
```
note the intervals at which we call this function are somewhat laughable,

Diffs=
8db7cac50 fix state machine advanceAndApply (#7183)
Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
diff --git a/.rive_head b/.rive_head
index ca0ca4d..ceeb57a 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-a55f1ffb6cabe9b918fa0b8fd1ad11b4d656ae1c
+8db7cac50c53ab10838da0cd80c869917c51c72a
diff --git a/include/rive/animation/nested_remap_animation.hpp b/include/rive/animation/nested_remap_animation.hpp
index c83002c..3b304fd 100644
--- a/include/rive/animation/nested_remap_animation.hpp
+++ b/include/rive/animation/nested_remap_animation.hpp
@@ -8,7 +8,7 @@
{
public:
void timeChanged() override;
- void advance(float elapsedSeconds) override;
+ bool advance(float elapsedSeconds) override;
void initializeAnimation(ArtboardInstance*) override;
};
} // namespace rive
diff --git a/include/rive/animation/nested_simple_animation.hpp b/include/rive/animation/nested_simple_animation.hpp
index 41bc958..ce04aa4 100644
--- a/include/rive/animation/nested_simple_animation.hpp
+++ b/include/rive/animation/nested_simple_animation.hpp
@@ -7,7 +7,7 @@
class NestedSimpleAnimation : public NestedSimpleAnimationBase
{
public:
- void advance(float elapsedSeconds) override;
+ bool advance(float elapsedSeconds) override;
};
} // namespace rive
diff --git a/include/rive/animation/nested_state_machine.hpp b/include/rive/animation/nested_state_machine.hpp
index fe0cded..489d631 100644
--- a/include/rive/animation/nested_state_machine.hpp
+++ b/include/rive/animation/nested_state_machine.hpp
@@ -20,7 +20,7 @@
public:
NestedStateMachine();
~NestedStateMachine() override;
- void advance(float elapsedSeconds) override;
+ bool advance(float elapsedSeconds) override;
void initializeAnimation(ArtboardInstance*) override;
StateMachineInstance* stateMachineInstance();
diff --git a/include/rive/nested_animation.hpp b/include/rive/nested_animation.hpp
index dae7877..843739e 100644
--- a/include/rive/nested_animation.hpp
+++ b/include/rive/nested_animation.hpp
@@ -12,7 +12,7 @@
StatusCode onAddedDirty(CoreContext* context) override;
// Advance animations and apply them to the artboard.
- virtual void advance(float elapsedSeconds) = 0;
+ virtual bool advance(float elapsedSeconds) = 0;
// Initialize the animation (make instances as necessary) from the
// source artboard.
diff --git a/src/animation/nested_remap_animation.cpp b/src/animation/nested_remap_animation.cpp
index 92b9465..4edc815 100644
--- a/src/animation/nested_remap_animation.cpp
+++ b/src/animation/nested_remap_animation.cpp
@@ -18,10 +18,13 @@
timeChanged();
}
-void NestedRemapAnimation::advance(float elapsedSeconds)
+bool NestedRemapAnimation::advance(float elapsedSeconds)
{
+ bool keepGoing = false;
if (m_AnimationInstance != nullptr && mix() != 0.0f)
{
m_AnimationInstance->apply(mix());
+ keepGoing = true;
}
+ return keepGoing;
}
\ No newline at end of file
diff --git a/src/animation/nested_simple_animation.cpp b/src/animation/nested_simple_animation.cpp
index 89ff29f..dd6bb6e 100644
--- a/src/animation/nested_simple_animation.cpp
+++ b/src/animation/nested_simple_animation.cpp
@@ -3,17 +3,19 @@
using namespace rive;
-void NestedSimpleAnimation::advance(float elapsedSeconds)
+bool NestedSimpleAnimation::advance(float elapsedSeconds)
{
+ bool keepGoing = false;
if (m_AnimationInstance != nullptr)
{
if (isPlaying())
{
- m_AnimationInstance->advance(elapsedSeconds * speed());
+ keepGoing = m_AnimationInstance->advance(elapsedSeconds * speed());
}
if (mix() != 0.0f)
{
m_AnimationInstance->apply(mix());
}
}
+ return keepGoing;
}
\ No newline at end of file
diff --git a/src/animation/nested_state_machine.cpp b/src/animation/nested_state_machine.cpp
index a6b5210..f04477f 100644
--- a/src/animation/nested_state_machine.cpp
+++ b/src/animation/nested_state_machine.cpp
@@ -10,12 +10,14 @@
NestedStateMachine::NestedStateMachine() {}
NestedStateMachine::~NestedStateMachine() {}
-void NestedStateMachine::advance(float elapsedSeconds)
+bool NestedStateMachine::advance(float elapsedSeconds)
{
+ bool keepGoing = false;
if (m_StateMachineInstance != nullptr)
{
- m_StateMachineInstance->advance(elapsedSeconds);
+ keepGoing = m_StateMachineInstance->advance(elapsedSeconds);
}
+ return keepGoing;
}
void NestedStateMachine::initializeAnimation(ArtboardInstance* artboard)
diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp
index c0f5f58..e5e387d 100644
--- a/src/animation/state_machine_instance.cpp
+++ b/src/animation/state_machine_instance.cpp
@@ -744,9 +744,9 @@
bool StateMachineInstance::advanceAndApply(float seconds)
{
- bool more = this->advance(seconds);
- m_artboardInstance->advance(seconds);
- return more;
+ bool keepGoing = this->advance(seconds);
+ keepGoing = m_artboardInstance->advance(seconds) || keepGoing;
+ return keepGoing;
}
void StateMachineInstance::markNeedsAdvance() { m_needsAdvance = true; }
diff --git a/src/nested_artboard.cpp b/src/nested_artboard.cpp
index 18ff098..fdd40b8 100644
--- a/src/nested_artboard.cpp
+++ b/src/nested_artboard.cpp
@@ -129,15 +129,16 @@
bool NestedArtboard::advance(float elapsedSeconds)
{
+ bool keepGoing = false;
if (m_Artboard == nullptr || isCollapsed())
{
- return false;
+ return keepGoing;
}
for (auto animation : m_NestedAnimations)
{
- animation->advance(elapsedSeconds);
+ keepGoing = keepGoing || animation->advance(elapsedSeconds);
}
- return m_Artboard->advance(elapsedSeconds);
+ return m_Artboard->advance(elapsedSeconds) || keepGoing;
}
void NestedArtboard::update(ComponentDirt value)
diff --git a/test/assets/ball_test.riv b/test/assets/ball_test.riv
new file mode 100644
index 0000000..e0e618d
--- /dev/null
+++ b/test/assets/ball_test.riv
Binary files differ
diff --git a/test/nested_artboard.cpp b/test/nested_artboard.cpp
index bac597a..db0c21c 100644
--- a/test/nested_artboard.cpp
+++ b/test/nested_artboard.cpp
@@ -37,4 +37,30 @@
auto greenMovingShapes = greenNestedArtboardArtboard->find<rive::Shape>();
auto greenRect = greenMovingShapes.at(0);
REQUIRE(greenRect->x() == 50);
+}
+
+TEST_CASE("nested artboards with looping animations will keep main advanceAndApply advancing",
+ "[nested]")
+{
+ auto file = ReadRiveFile("../../test/assets/ball_test.riv");
+ auto artboard = file->artboard("Artboard")->instance();
+ artboard->advance(0.0f);
+ auto stateMachine = artboard->stateMachineAt(0);
+ REQUIRE(stateMachine->advanceAndApply(0.0f) == true);
+ REQUIRE(stateMachine->advanceAndApply(1.0f) == true);
+ REQUIRE(stateMachine->advanceAndApply(1.0f) == true);
+}
+TEST_CASE("nested artboards with one shot animations will not main advanceAndApply advancing",
+ "[nested]")
+{
+
+ auto file = ReadRiveFile("../../test/assets/ball_test.riv");
+ auto artboard = file->artboard("Artboard 2")->instance();
+ artboard->advance(0.0f);
+ auto stateMachine = artboard->stateMachineAt(0);
+ REQUIRE(stateMachine->advanceAndApply(0.0f) == true);
+ REQUIRE(stateMachine->advanceAndApply(0.9f) == true);
+ REQUIRE(stateMachine->advanceAndApply(0.1f) == true);
+ // nested artboards animation is 1s long
+ REQUIRE(stateMachine->advanceAndApply(0.1f) == false);
}
\ No newline at end of file