1 #ifndef _RIVE_STATE_TRANSITION_HPP_
2 #define _RIVE_STATE_TRANSITION_HPP_
3 #include "animation/state_transition_flags.hpp"
4 #include "generated/animation/state_transition_base.hpp"
11 class StateMachineLayerImporter;
12 class StateTransitionImporter;
13 class TransitionCondition;
16 class LinearAnimation;
17 class LinearAnimationInstance;
19 enum class AllowTransition : unsigned char
26 class StateTransition : public StateTransitionBase
28 friend class StateMachineLayerImporter;
29 friend class StateTransitionImporter;
32 StateTransitionFlags transitionFlags() const
34 return static_cast<StateTransitionFlags>(flags());
36 LayerState* m_StateTo = nullptr;
38 std::vector<TransitionCondition*> m_Conditions;
39 void addCondition(TransitionCondition* condition);
43 const LayerState* stateTo() const { return m_StateTo; }
45 StatusCode onAddedDirty(CoreContext* context) override;
46 StatusCode onAddedClean(CoreContext* context) override;
48 /// Whether the transition is marked disabled (usually done in the
50 bool isDisabled() const
52 return (transitionFlags() & StateTransitionFlags::Disabled) ==
53 StateTransitionFlags::Disabled;
56 /// Returns AllowTransition::yes when this transition can be taken from
57 /// stateFrom with the given inputs.
58 AllowTransition allowed(StateInstance* stateFrom,
60 bool ignoreTriggers) const;
62 /// Whether the animation is held at exit or if it keeps advancing
64 bool pauseOnExit() const
66 return (transitionFlags() & StateTransitionFlags::PauseOnExit) ==
67 StateTransitionFlags::PauseOnExit;
70 /// Whether exit time is enabled. All other conditions still apply, the
71 /// exit time is effectively an AND with the rest of the conditions.
72 bool enableExitTime() const
74 return (transitionFlags() & StateTransitionFlags::EnableExitTime) ==
75 StateTransitionFlags::EnableExitTime;
78 StatusCode import(ImportStack& importStack) override;
80 size_t conditionCount() const { return m_Conditions.size(); }
81 TransitionCondition* condition(size_t index) const
83 if (index < m_Conditions.size())
85 return m_Conditions[index];
90 /// The amount of time to mix the outgoing animation onto the incoming
91 /// one when changing state. Only applies when going out from an
93 float mixTime(const LayerState* stateFrom) const;
95 /// Computes the exit time in seconds of the stateFrom. Set absolute to
96 /// true if you want the returned time to be relative to the entire
97 /// animation. Set absolute to false if you want it relative to the work
99 float exitTimeSeconds(const LayerState* stateFrom,
100 bool absolute = false) const;
102 /// Provide the animation instance to use for computing percentage
103 /// durations for exit time.
104 virtual const LinearAnimationInstance*
105 exitTimeAnimationInstance(const StateInstance* from) const;
107 /// Provide the animation to use for computing percentage durations for
109 virtual const LinearAnimation*
110 exitTimeAnimation(const LayerState* from) const;
112 /// Retruns true when we need to hold the exit time, also applies the
113 /// correct time to the animation instance in the stateFrom, when
114 /// applicable (when it's an AnimationState).
115 bool applyExitCondition(StateInstance* stateFrom) const;