1#ifndef _ANIMATIONSTATEMACHINE_HPP_
2#define _ANIMATIONSTATEMACHINE_HPP_
7#include <unordered_map>
75 bool loop =
true,
float speed = 1.0f);
77 int AddTransition(
int from,
int to,
float blendDuration = 0.3f,
78 bool waitForClipEnd =
false);
86 void SetBool(
const std::string& name,
bool value);
87 void SetFloat(
const std::string& name,
float value);
88 void SetInt(
const std::string& name,
int value);
105 void StartTransition(
int transIndex);
107 std::vector<AnimationState> m_states;
108 std::vector<AnimationTransition> m_transitions;
109 std::unordered_map<std::string, ParamValue> m_params;
111 int m_currentState = -1;
112 float m_currentTime = 0.0f;
115 bool m_blending =
false;
116 int m_prevState = -1;
117 float m_prevTime = 0.0f;
118 float m_blendElapsed = 0.0f;
119 float m_blendDuration = 0.0f;
void SetDefaultState(int stateIndex)
Sets the state the machine starts in, with no blend.
AnimationStateMachine()=default
int AddTransition(int from, int to, float blendDuration=0.3f, bool waitForClipEnd=false)
Adds a transition edge from -> to, returning its index.
SampleRequest Update(float deltaTime)
Advances playback/blend time, evaluates transitions, and returns what to sample this frame.
void SetFloat(const std::string &name, float value)
void SetBool(const std::string &name, bool value)
~AnimationStateMachine()=default
void AddTransitionCondition(int transIndex, const std::string ¶mName, CompareOp op, ParamValue threshold)
Appends a guard condition to the transition at transIndex.
int AddState(const std::string &name, AnimationClip *clip, bool loop=true, float speed=1.0f)
Adds a state bound to clip, returning its index for use in AddTransition.
void SetInt(const std::string &name, int value)
const std::string & GetCurrentStateName() const
Root namespace for everything the engine exposes.
std::variant< bool, float, int > ParamValue
std::vector< TransitionCondition > conditions