diff --git a/.rive_head b/.rive_head index db3938fc..2edbc198 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -35a52873cf0adabbda2670673762a36c91822e96 +1131f30e6a45bee5c0561de3a35b19985bf46820 diff --git a/include/rive/animation/state_machine_instance.hpp b/include/rive/animation/state_machine_instance.hpp index ce34a035..5921adf6 100644 --- a/include/rive/animation/state_machine_instance.hpp +++ b/include/rive/animation/state_machine_instance.hpp @@ -115,7 +115,7 @@ class StateMachineInstance : public Scene, public NestedEventNotifier, public Ne /// Allow anything referencing a concrete StateMachineInstace access to /// the backing artboard (explicitly not allowed on Scenes). - Artboard* artboard() { return m_artboardInstance; } + Artboard* artboard() const { return m_artboardInstance; } void setParentStateMachineInstance(StateMachineInstance* instance) { @@ -136,7 +136,7 @@ class StateMachineInstance : public Scene, public NestedEventNotifier, public Ne /// Gets a reported event at an index < reportedEventCount(). const EventReport reportedEventAt(std::size_t index) const; bool playsAudio() override { return true; } - BindableProperty* bindablePropertyInstance(BindableProperty* bindableProperty); + BindableProperty* bindablePropertyInstance(BindableProperty* bindableProperty) const; DataBind* bindableDataBind(BindableProperty* bindableProperty); #ifdef TESTING size_t hitComponentsCount() { return m_hitComponents.size(); }; diff --git a/include/rive/animation/transition_bool_condition.hpp b/include/rive/animation/transition_bool_condition.hpp index 3a41a166..fa5a03e5 100644 --- a/include/rive/animation/transition_bool_condition.hpp +++ b/include/rive/animation/transition_bool_condition.hpp @@ -7,7 +7,7 @@ namespace rive class TransitionBoolCondition : public TransitionBoolConditionBase { public: - bool evaluate(const SMIInput* inputInstance) const override; + bool evaluate(const StateMachineInstance* stateMachineInstance) const override; protected: bool validateInputType(const StateMachineInput* input) const override; diff --git a/include/rive/animation/transition_comparator.hpp b/include/rive/animation/transition_comparator.hpp index 5757ad2c..38aab796 100644 --- a/include/rive/animation/transition_comparator.hpp +++ b/include/rive/animation/transition_comparator.hpp @@ -14,7 +14,7 @@ class TransitionComparator : public TransitionComparatorBase StatusCode import(ImportStack& importStack) override; virtual bool compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance); + const StateMachineInstance* stateMachineInstance); protected: bool compareNumbers(float left, float right, TransitionConditionOp op); diff --git a/include/rive/animation/transition_condition.hpp b/include/rive/animation/transition_condition.hpp index 5336f4d8..9fc8db6a 100644 --- a/include/rive/animation/transition_condition.hpp +++ b/include/rive/animation/transition_condition.hpp @@ -1,6 +1,7 @@ #ifndef _RIVE_TRANSITION_CONDITION_HPP_ #define _RIVE_TRANSITION_CONDITION_HPP_ #include "rive/generated/animation/transition_condition_base.hpp" +#include "rive/animation/state_machine_instance.hpp" namespace rive { @@ -15,6 +16,8 @@ class TransitionCondition : public TransitionConditionBase StatusCode import(ImportStack& importStack) override; + virtual bool evaluate(const StateMachineInstance* stateMachineInstance) const { return true; } + protected: virtual bool validateInputType(const StateMachineInput* input) const { return true; } }; diff --git a/include/rive/animation/transition_input_condition.hpp b/include/rive/animation/transition_input_condition.hpp index b6c65174..90ab05a7 100644 --- a/include/rive/animation/transition_input_condition.hpp +++ b/include/rive/animation/transition_input_condition.hpp @@ -7,8 +7,6 @@ namespace rive class TransitionInputCondition : public TransitionInputConditionBase { public: - virtual bool evaluate(const SMIInput* inputInstance) const { return true; } - StatusCode import(ImportStack& importStack) override; }; } // namespace rive diff --git a/include/rive/animation/transition_number_condition.hpp b/include/rive/animation/transition_number_condition.hpp index e8c88d93..d7940970 100644 --- a/include/rive/animation/transition_number_condition.hpp +++ b/include/rive/animation/transition_number_condition.hpp @@ -10,7 +10,7 @@ class TransitionNumberCondition : public TransitionNumberConditionBase bool validateInputType(const StateMachineInput* input) const override; public: - bool evaluate(const SMIInput* inputInstance) const override; + bool evaluate(const StateMachineInstance* stateMachineInstance) const override; }; } // namespace rive diff --git a/include/rive/animation/transition_property_viewmodel_comparator.hpp b/include/rive/animation/transition_property_viewmodel_comparator.hpp index 6dec8ed1..6c5bd87c 100644 --- a/include/rive/animation/transition_property_viewmodel_comparator.hpp +++ b/include/rive/animation/transition_property_viewmodel_comparator.hpp @@ -2,6 +2,7 @@ #define _RIVE_TRANSITION_PROPERTY_VIEW_MODEL_COMPARATOR_HPP_ #include "rive/generated/animation/transition_property_viewmodel_comparator_base.hpp" #include "rive/data_bind/bindable_property.hpp" +#include "rive/animation/state_machine_instance.hpp" #include namespace rive { @@ -11,12 +12,18 @@ class TransitionPropertyViewModelComparator : public TransitionPropertyViewModel StatusCode import(ImportStack& importStack) override; bool compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) override; - float propertyValueNumber(StateMachineInstance* stateMachineInstance); - std::string propertyValueString(StateMachineInstance* stateMachineInstance); - int propertyValueColor(StateMachineInstance* stateMachineInstance); - bool propertyValueBoolean(StateMachineInstance* stateMachineInstance); - uint16_t propertyValueEnum(StateMachineInstance* stateMachineInstance); + const StateMachineInstance* stateMachineInstance) override; + template + U value(const StateMachineInstance* stateMachineInstance) + { + if (m_bindableProperty->is()) + { + auto bindableInstance = + stateMachineInstance->bindablePropertyInstance(m_bindableProperty); + return bindableInstance->as()->propertyValue(); + } + return (new T())->propertyValue(); + }; protected: BindableProperty* m_bindableProperty; diff --git a/include/rive/animation/transition_trigger_condition.hpp b/include/rive/animation/transition_trigger_condition.hpp index cb535668..7ad999fd 100644 --- a/include/rive/animation/transition_trigger_condition.hpp +++ b/include/rive/animation/transition_trigger_condition.hpp @@ -7,7 +7,7 @@ namespace rive class TransitionTriggerCondition : public TransitionTriggerConditionBase { public: - bool evaluate(const SMIInput* inputInstance) const override; + bool evaluate(const StateMachineInstance* stateMachineInstance) const override; protected: bool validateInputType(const StateMachineInput* input) const override; diff --git a/include/rive/animation/transition_value_boolean_comparator.hpp b/include/rive/animation/transition_value_boolean_comparator.hpp index de5590bb..fc8b51ce 100644 --- a/include/rive/animation/transition_value_boolean_comparator.hpp +++ b/include/rive/animation/transition_value_boolean_comparator.hpp @@ -9,7 +9,7 @@ class TransitionValueBooleanComparator : public TransitionValueBooleanComparator public: bool compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) override; + const StateMachineInstance* stateMachineInstance) override; }; } // namespace rive diff --git a/include/rive/animation/transition_value_color_comparator.hpp b/include/rive/animation/transition_value_color_comparator.hpp index 6e13bb1c..c75c0627 100644 --- a/include/rive/animation/transition_value_color_comparator.hpp +++ b/include/rive/animation/transition_value_color_comparator.hpp @@ -9,7 +9,7 @@ class TransitionValueColorComparator : public TransitionValueColorComparatorBase public: bool compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) override; + const StateMachineInstance* stateMachineInstance) override; }; } // namespace rive diff --git a/include/rive/animation/transition_value_number_comparator.hpp b/include/rive/animation/transition_value_number_comparator.hpp index cd882076..daf644ce 100644 --- a/include/rive/animation/transition_value_number_comparator.hpp +++ b/include/rive/animation/transition_value_number_comparator.hpp @@ -9,7 +9,7 @@ class TransitionValueNumberComparator : public TransitionValueNumberComparatorBa public: bool compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) override; + const StateMachineInstance* stateMachineInstance) override; }; } // namespace rive diff --git a/include/rive/animation/transition_value_string_comparator.hpp b/include/rive/animation/transition_value_string_comparator.hpp index ac0136dd..c634db8f 100644 --- a/include/rive/animation/transition_value_string_comparator.hpp +++ b/include/rive/animation/transition_value_string_comparator.hpp @@ -9,7 +9,7 @@ class TransitionValueStringComparator : public TransitionValueStringComparatorBa public: bool compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) override; + const StateMachineInstance* stateMachineInstance) override; }; } // namespace rive diff --git a/include/rive/animation/transition_viewmodel_condition.hpp b/include/rive/animation/transition_viewmodel_condition.hpp index 2d5efb9e..508807d6 100644 --- a/include/rive/animation/transition_viewmodel_condition.hpp +++ b/include/rive/animation/transition_viewmodel_condition.hpp @@ -14,9 +14,9 @@ class TransitionViewModelCondition : public TransitionViewModelConditionBase TransitionComparator* m_rightComparator; public: - bool evaluateCondition(StateMachineInstance* stateMachineInstance); - TransitionComparator* leftComparator() { return m_leftComparator; }; - TransitionComparator* rightComparator() { return m_rightComparator; }; + bool evaluate(const StateMachineInstance* stateMachineInstance) const override; + TransitionComparator* leftComparator() const { return m_leftComparator; }; + TransitionComparator* rightComparator() const { return m_rightComparator; }; void comparator(TransitionComparator* value) { if (m_leftComparator == nullptr) diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index c49745fe..dcc6ff67 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp @@ -1258,7 +1258,8 @@ void StateMachineInstance::notifyEventListeners(const std::vector& } } -BindableProperty* StateMachineInstance::bindablePropertyInstance(BindableProperty* bindableProperty) +BindableProperty* StateMachineInstance::bindablePropertyInstance( + BindableProperty* bindableProperty) const { auto bindablePropertyInstance = m_bindablePropertyInstances.find(bindableProperty); if (bindablePropertyInstance == m_bindablePropertyInstances.end()) diff --git a/src/animation/state_transition.cpp b/src/animation/state_transition.cpp index 560f82ce..f419c4b5 100644 --- a/src/animation/state_transition.cpp +++ b/src/animation/state_transition.cpp @@ -150,26 +150,10 @@ AllowTransition StateTransition::allowed(StateInstance* stateFrom, for (auto condition : m_Conditions) { - if (condition->is()) + if ((ignoreTriggers && condition->is()) || + !condition->evaluate(stateMachineInstance)) { - auto inputCondition = condition->as(); - // N.B. state machine instance sanitizes these for us... - auto input = stateMachineInstance->input(inputCondition->inputId()); - - if ((ignoreTriggers && inputCondition->is()) || - !inputCondition->evaluate(input)) - { - return AllowTransition::no; - } - } - else if (condition->is()) - { - auto transitionViewModelCondition = condition->as(); - - if (!transitionViewModelCondition->evaluateCondition(stateMachineInstance)) - { - return AllowTransition::no; - } + return AllowTransition::no; } } diff --git a/src/animation/transition_bool_condition.cpp b/src/animation/transition_bool_condition.cpp index 14eb732e..f50a84e8 100644 --- a/src/animation/transition_bool_condition.cpp +++ b/src/animation/transition_bool_condition.cpp @@ -13,8 +13,9 @@ bool TransitionBoolCondition::validateInputType(const StateMachineInput* input) return input == nullptr || input->is(); } -bool TransitionBoolCondition::evaluate(const SMIInput* inputInstance) const +bool TransitionBoolCondition::evaluate(const StateMachineInstance* stateMachineInstance) const { + auto inputInstance = stateMachineInstance->input(inputId()); if (inputInstance == nullptr) { return true; diff --git a/src/animation/transition_comparator.cpp b/src/animation/transition_comparator.cpp index 73b9db9b..b14254aa 100644 --- a/src/animation/transition_comparator.cpp +++ b/src/animation/transition_comparator.cpp @@ -95,7 +95,7 @@ bool TransitionComparator::compareColors(int left, int right, TransitionConditio bool TransitionComparator::compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) + const StateMachineInstance* stateMachineInstance) { return false; } \ No newline at end of file diff --git a/src/animation/transition_condition.cpp b/src/animation/transition_condition.cpp index 6385f289..94865162 100644 --- a/src/animation/transition_condition.cpp +++ b/src/animation/transition_condition.cpp @@ -1,4 +1,4 @@ -#include "rive/animation/transition_bool_condition.hpp" +#include "rive/animation/transition_condition.hpp" #include "rive/animation/state_transition.hpp" #include "rive/importers/state_transition_importer.hpp" @@ -10,7 +10,6 @@ StatusCode TransitionCondition::onAddedClean(CoreContext* context) { return Stat StatusCode TransitionCondition::import(ImportStack& importStack) { - auto transitionImporter = importStack.latest(StateTransition::typeKey); if (transitionImporter == nullptr) { diff --git a/src/animation/transition_number_condition.cpp b/src/animation/transition_number_condition.cpp index 102d6314..da820e39 100644 --- a/src/animation/transition_number_condition.cpp +++ b/src/animation/transition_number_condition.cpp @@ -13,8 +13,9 @@ bool TransitionNumberCondition::validateInputType(const StateMachineInput* input return input == nullptr || input->is(); } -bool TransitionNumberCondition::evaluate(const SMIInput* inputInstance) const +bool TransitionNumberCondition::evaluate(const StateMachineInstance* stateMachineInstance) const { + auto inputInstance = stateMachineInstance->input(inputId()); if (inputInstance == nullptr) { return true; diff --git a/src/animation/transition_property_viewmodel_comparator.cpp b/src/animation/transition_property_viewmodel_comparator.cpp index 8d931523..80f92ecb 100644 --- a/src/animation/transition_property_viewmodel_comparator.cpp +++ b/src/animation/transition_property_viewmodel_comparator.cpp @@ -27,61 +27,26 @@ StatusCode TransitionPropertyViewModelComparator::import(ImportStack& importStac return Super::import(importStack); } -float TransitionPropertyViewModelComparator::propertyValueNumber( - StateMachineInstance* stateMachineInstance) -{ - auto bindableInstance = stateMachineInstance->bindablePropertyInstance(m_bindableProperty); - return bindableInstance->as()->propertyValue(); -} - -std::string TransitionPropertyViewModelComparator::propertyValueString( - StateMachineInstance* stateMachineInstance) -{ - auto bindableInstance = stateMachineInstance->bindablePropertyInstance(m_bindableProperty); - return bindableInstance->as()->propertyValue(); -} - -int TransitionPropertyViewModelComparator::propertyValueColor( - StateMachineInstance* stateMachineInstance) -{ - auto bindableInstance = stateMachineInstance->bindablePropertyInstance(m_bindableProperty); - return bindableInstance->as()->propertyValue(); -} - -bool TransitionPropertyViewModelComparator::propertyValueBoolean( - StateMachineInstance* stateMachineInstance) -{ - auto bindableInstance = stateMachineInstance->bindablePropertyInstance(m_bindableProperty); - return bindableInstance->as()->propertyValue(); -} - -uint16_t TransitionPropertyViewModelComparator::propertyValueEnum( - StateMachineInstance* stateMachineInstance) -{ - auto bindableInstance = stateMachineInstance->bindablePropertyInstance(m_bindableProperty); - return bindableInstance->as()->propertyValue(); -} - -bool TransitionPropertyViewModelComparator::compare(TransitionComparator* comparand, - TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) +bool TransitionPropertyViewModelComparator::compare( + TransitionComparator* comparand, + TransitionConditionOp operation, + const StateMachineInstance* stateMachineInstance) { switch (m_bindableProperty->coreType()) { case BindablePropertyNumber::typeKey: if (comparand->is()) { - auto rightValue = - comparand->as()->propertyValueNumber( - stateMachineInstance); - return compareNumbers(propertyValueNumber(stateMachineInstance), + auto rightValue = comparand->as() + ->value(stateMachineInstance); + return compareNumbers(value(stateMachineInstance), rightValue, operation); } else if (comparand->is()) { auto rightValue = comparand->as()->value(); - return compareNumbers(propertyValueNumber(stateMachineInstance), + return compareNumbers(value(stateMachineInstance), rightValue, operation); } @@ -90,34 +55,35 @@ bool TransitionPropertyViewModelComparator::compare(TransitionComparator* compar if (comparand->is()) { auto rightValue = - comparand->as()->propertyValueString( - stateMachineInstance); - return compareStrings(propertyValueString(stateMachineInstance), - rightValue, - operation); + comparand->as() + ->value(stateMachineInstance); + return compareStrings( + value(stateMachineInstance), + rightValue, + operation); } else if (comparand->is()) { auto rightValue = comparand->as()->value(); - return compareStrings(propertyValueString(stateMachineInstance), - rightValue, - operation); + return compareStrings( + value(stateMachineInstance), + rightValue, + operation); } break; case BindablePropertyColor::typeKey: if (comparand->is()) { - auto rightValue = - comparand->as()->propertyValueColor( - stateMachineInstance); - return compareColors(propertyValueColor(stateMachineInstance), + auto rightValue = comparand->as() + ->value(stateMachineInstance); + return compareColors(value(stateMachineInstance), rightValue, operation); } else if (comparand->is()) { auto rightValue = comparand->as()->value(); - return compareColors(propertyValueColor(stateMachineInstance), + return compareColors(value(stateMachineInstance), rightValue, operation); } @@ -125,17 +91,16 @@ bool TransitionPropertyViewModelComparator::compare(TransitionComparator* compar case BindablePropertyBoolean::typeKey: if (comparand->is()) { - auto rightValue = - comparand->as()->propertyValueBoolean( - stateMachineInstance); - return compareBooleans(propertyValueBoolean(stateMachineInstance), + auto rightValue = comparand->as() + ->value(stateMachineInstance); + return compareBooleans(value(stateMachineInstance), rightValue, operation); } else if (comparand->is()) { auto rightValue = comparand->as()->value(); - return compareBooleans(propertyValueBoolean(stateMachineInstance), + return compareBooleans(value(stateMachineInstance), rightValue, operation); } @@ -143,15 +108,18 @@ bool TransitionPropertyViewModelComparator::compare(TransitionComparator* compar case BindablePropertyEnum::typeKey: if (comparand->is()) { - auto rightValue = - comparand->as()->propertyValueEnum( - stateMachineInstance); - return compareEnums(propertyValueEnum(stateMachineInstance), rightValue, operation); + auto rightValue = comparand->as() + ->value(stateMachineInstance); + return compareEnums(value(stateMachineInstance), + rightValue, + operation); } else if (comparand->is()) { auto rightValue = comparand->as()->value(); - return compareEnums(propertyValueEnum(stateMachineInstance), rightValue, operation); + return compareEnums(value(stateMachineInstance), + rightValue, + operation); } break; } diff --git a/src/animation/transition_trigger_condition.cpp b/src/animation/transition_trigger_condition.cpp index 86391fe5..15be1a62 100644 --- a/src/animation/transition_trigger_condition.cpp +++ b/src/animation/transition_trigger_condition.cpp @@ -13,8 +13,9 @@ bool TransitionTriggerCondition::validateInputType(const StateMachineInput* inpu return input == nullptr || input->is(); } -bool TransitionTriggerCondition::evaluate(const SMIInput* inputInstance) const +bool TransitionTriggerCondition::evaluate(const StateMachineInstance* stateMachineInstance) const { + auto inputInstance = stateMachineInstance->input(inputId()); if (inputInstance == nullptr) { return true; diff --git a/src/animation/transition_value_boolean_comparator.cpp b/src/animation/transition_value_boolean_comparator.cpp index e26f8682..74778288 100644 --- a/src/animation/transition_value_boolean_comparator.cpp +++ b/src/animation/transition_value_boolean_comparator.cpp @@ -4,7 +4,7 @@ using namespace rive; bool TransitionValueBooleanComparator::compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) + const StateMachineInstance* stateMachineInstance) { if (comparand->is()) { diff --git a/src/animation/transition_value_color_comparator.cpp b/src/animation/transition_value_color_comparator.cpp index c4fe60e6..9e29e26f 100644 --- a/src/animation/transition_value_color_comparator.cpp +++ b/src/animation/transition_value_color_comparator.cpp @@ -4,7 +4,7 @@ using namespace rive; bool TransitionValueColorComparator::compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) + const StateMachineInstance* stateMachineInstance) { if (comparand->is()) { diff --git a/src/animation/transition_value_number_comparator.cpp b/src/animation/transition_value_number_comparator.cpp index c4f05d55..5c88856a 100644 --- a/src/animation/transition_value_number_comparator.cpp +++ b/src/animation/transition_value_number_comparator.cpp @@ -4,7 +4,7 @@ using namespace rive; bool TransitionValueNumberComparator::compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) + const StateMachineInstance* stateMachineInstance) { if (comparand->is()) { diff --git a/src/animation/transition_value_string_comparator.cpp b/src/animation/transition_value_string_comparator.cpp index d62a1a34..fe6ac06e 100644 --- a/src/animation/transition_value_string_comparator.cpp +++ b/src/animation/transition_value_string_comparator.cpp @@ -4,7 +4,7 @@ using namespace rive; bool TransitionValueStringComparator::compare(TransitionComparator* comparand, TransitionConditionOp operation, - StateMachineInstance* stateMachineInstance) + const StateMachineInstance* stateMachineInstance) { if (comparand->is()) { diff --git a/src/animation/transition_viewmodel_condition.cpp b/src/animation/transition_viewmodel_condition.cpp index 40d2a078..5c6ebbf9 100644 --- a/src/animation/transition_viewmodel_condition.cpp +++ b/src/animation/transition_viewmodel_condition.cpp @@ -8,7 +8,7 @@ using namespace rive; -bool TransitionViewModelCondition::evaluateCondition(StateMachineInstance* stateMachineInstance) +bool TransitionViewModelCondition::evaluate(const StateMachineInstance* stateMachineInstance) const { if (leftComparator() != nullptr && rightComparator() != nullptr) {