Skip to content

Commit

Permalink
Apply NestedInput initial values
Browse files Browse the repository at this point in the history
This update applies the initial values for nested inputs (as set in the Inputs panel of the Editor), so that NestedInputs behave in the same way as regular StateMachineInputs. There are a couple of reasons to do this:

1. Currently if you have a nested artboard and set the initial nested input value, it will only apply in the editor when viewing that artboard. If you nest that artboard in another artboard, the initial values do not apply. Similarly, initial nested values do not apply in the runtimes. Currently StateMachineInputs do apply initial values, so this brings NestedInputs in line with that.

2. There was a bug Hernan noticed where there in certain cases, NestedInput values that were keyed on a timeline did not apply properly in cases where the keyed value was the same as the default value. In these cases, the keyed value is ignored because it and the default values were the same. In addition, since the initial value wasn't being applied, the state wasn't being update properly based on the nested input's value.

Diffs=
6d9aa0179 Apply NestedInput initial values (#6140)

Co-authored-by: Philip Chung <[email protected]>
  • Loading branch information
philter and philter committed Oct 25, 2023
1 parent ef1a6dc commit 92fbbd4
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
92c8f1164db98bb5462f26dd73c89da4fa2c8b76
6d9aa017961638f7576a2ea52a8928c813e28dbb
2 changes: 2 additions & 0 deletions include/rive/animation/nested_bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace rive
class NestedBool : public NestedBoolBase
{
public:
void applyValue() override;

protected:
void nestedValueChanged() override;
};
Expand Down
13 changes: 13 additions & 0 deletions include/rive/animation/nested_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ namespace rive
class NestedInput : public NestedInputBase
{
public:
StatusCode onAddedDirty(CoreContext* context) override
{
StatusCode result = Super::onAddedDirty(context);
auto parent = this->parent();
if (parent != nullptr && parent->is<NestedStateMachine>())
{
parent->as<NestedStateMachine>()->addNestedInput(this);
}
return result;
}

virtual void applyValue() {}

protected:
SMIInput* input()
{
Expand Down
2 changes: 2 additions & 0 deletions include/rive/animation/nested_number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace rive
class NestedNumber : public NestedNumberBase
{
public:
void applyValue() override;

protected:
void nestedValueChanged() override;
};
Expand Down
4 changes: 4 additions & 0 deletions include/rive/animation/nested_state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
namespace rive
{
class ArtboardInstance;
class NestedInput;
class StateMachineInstance;
class NestedStateMachine : public NestedStateMachineBase
{
private:
std::unique_ptr<StateMachineInstance> m_StateMachineInstance;
std::vector<NestedInput*> m_nestedInputs;

public:
NestedStateMachine();
Expand All @@ -24,6 +26,8 @@ class NestedStateMachine : public NestedStateMachineBase
void pointerMove(Vec2D position);
void pointerDown(Vec2D position);
void pointerUp(Vec2D position);

void addNestedInput(NestedInput* input);
};
} // namespace rive

Expand Down
1 change: 1 addition & 0 deletions include/rive/animation/nested_trigger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace rive
class NestedTrigger : public NestedTriggerBase
{
public:
void applyValue() override;
void fire(const CallbackData& value) override;
};
} // namespace rive
Expand Down
4 changes: 3 additions & 1 deletion src/animation/nested_bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using namespace rive;
class StateMachineInstance;

void NestedBool::nestedValueChanged()
void NestedBool::nestedValueChanged() { this->applyValue(); }

void NestedBool::applyValue()
{
auto inputInstance = input();
if (inputInstance != nullptr)
Expand Down
4 changes: 3 additions & 1 deletion src/animation/nested_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using namespace rive;
class StateMachineInstance;

void NestedNumber::nestedValueChanged()
void NestedNumber::nestedValueChanged() { this->applyValue(); }

void NestedNumber::applyValue()
{
auto inputInstance = input();
if (inputInstance != nullptr)
Expand Down
17 changes: 16 additions & 1 deletion src/animation/nested_state_machine.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "rive/animation/nested_bool.hpp"
#include "rive/animation/nested_input.hpp"
#include "rive/animation/nested_number.hpp"
#include "rive/animation/nested_state_machine.hpp"
#include "rive/animation/state_machine_instance.hpp"

Expand All @@ -17,6 +20,16 @@ void NestedStateMachine::advance(float elapsedSeconds)
void NestedStateMachine::initializeAnimation(ArtboardInstance* artboard)
{
m_StateMachineInstance = artboard->stateMachineAt(animationId());
auto count = m_nestedInputs.size();
for (size_t i = 0; i < count; i++)
{
auto nestedInput = m_nestedInputs[i];
if (nestedInput->is<NestedBool>() || nestedInput->is<NestedNumber>())
{
nestedInput->applyValue();
}
}
m_nestedInputs.clear();
}

StateMachineInstance* NestedStateMachine::stateMachineInstance()
Expand Down Expand Up @@ -46,4 +59,6 @@ void NestedStateMachine::pointerUp(Vec2D position)
{
m_StateMachineInstance->pointerUp(position);
}
}
}

void NestedStateMachine::addNestedInput(NestedInput* input) { m_nestedInputs.push_back(input); }
4 changes: 3 additions & 1 deletion src/animation/nested_trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using namespace rive;
class StateMachineInstance;

void NestedTrigger::fire(const CallbackData& value)
void NestedTrigger::fire(const CallbackData& value) { this->applyValue(); }

void NestedTrigger::applyValue()
{
auto inputInstance = input();
if (inputInstance != nullptr)
Expand Down

0 comments on commit 92fbbd4

Please sign in to comment.