Kale
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Kale::StateAnimatable< S > Class Template Reference

#include <StateAnimatable.hpp>

Public Member Functions

 StateAnimatable ()
 
 StateAnimatable (JSON json)
 
void updateState (float deltaTime)
 
template<typename T >
void addStructure (T state, const S &structure)
 
template<typename T >
void removeStructure (T state)
 
template<typename T >
S getStructure (T state) const
 
template<typename T >
void animateTo (T state, float duration)
 
template<typename T >
void animateOnce (std::vector< std::pair< T, float > > stages)
 
template<typename T >
void animateLoop (std::vector< std::pair< T, float > > stages)
 
template<typename T >
void setState (T state)
 
template<typename T >
T getCurrentState () const
 
template<typename T >
std::vector< std::pair< T, float > > getStateComposition () const
 
bool isTransitioning () const
 

Protected Attributes

int state
 
int transitionState
 
bool transitioning
 
float transitionTime
 
float transitionDuration
 
std::unordered_map< int, Sstructures
 
std::vector< std::pair< int, float > > animationInfo
 
size_t animationIndex
 
bool animationLoop
 

Detailed Description

template<typename S>
class Kale::StateAnimatable< S >

This class allows for nodes to have animation states and to lerp between them.

Template Parameters
SA structure holding the data for a particular state

Definition at line 39 of file StateAnimatable.hpp.

Constructor & Destructor Documentation

◆ StateAnimatable() [1/2]

template<typename S >
Kale::StateAnimatable< S >::StateAnimatable ( )
inline

Default constructor

Definition at line 92 of file StateAnimatable.hpp.

◆ StateAnimatable() [2/2]

template<typename S >
Kale::StateAnimatable< S >::StateAnimatable ( JSON json)
inline

Creates a state animatable from a JSON config

Parameters
jsonThe json

Definition at line 98 of file StateAnimatable.hpp.

Member Function Documentation

◆ addStructure()

template<typename S >
template<typename T >
void Kale::StateAnimatable< S >::addStructure ( T state,
const S & structure )
inline

Adds a structure to the map of states

Template Parameters
Anenum containing all the states, the underlying type must be int.
Parameters
stateThe state to add the structure to
structureTHe structure to add

Definition at line 171 of file StateAnimatable.hpp.

◆ animateLoop()

template<typename S >
template<typename T >
void Kale::StateAnimatable< S >::animateLoop ( std::vector< std::pair< T, float > > stages)
inline

Animates through multiple states in an infinite loop

Template Parameters
TAn enum containing all the states, the underlying type must be int.
Parameters
stagesAn array of pairs of each state with the duration to spend animating to the state

Definition at line 232 of file StateAnimatable.hpp.

◆ animateOnce()

template<typename S >
template<typename T >
void Kale::StateAnimatable< S >::animateOnce ( std::vector< std::pair< T, float > > stages)
inline

Animates through multiple states once

Template Parameters
TAn enum containing all the states, the underlying type must be int.
Parameters
stagesAn array of pairs of each state with the duration to spend animating to the state

Definition at line 214 of file StateAnimatable.hpp.

◆ animateTo()

template<typename S >
template<typename T >
void Kale::StateAnimatable< S >::animateTo ( T state,
float duration )
inline

Animates to a state in a duration, thread safe. If called in pre-update then the state may be updated next frame depending on whether or not preUpdate has already been called.

Template Parameters
Anenum containing all the states, the underlying type must be int.
Parameters
stateThe state to animate to
durationThe duration of the animation, set 0 to immediately change

Definition at line 201 of file StateAnimatable.hpp.

◆ getCurrentState()

template<typename S >
template<typename T >
T Kale::StateAnimatable< S >::getCurrentState ( ) const
inline

Gets the current state, if the node is currently animating between two states then the state closer to the current one is used Thread safe if called in update. If called in pre-update, there may be a data race as to whether or not the animation has been updated for this frame.

Template Parameters
Anenum containing all the states, the underlying type must be int.
Returns
The current state

Definition at line 264 of file StateAnimatable.hpp.

◆ getStateComposition()

template<typename S >
template<typename T >
std::vector< std::pair< T, float > > Kale::StateAnimatable< S >::getStateComposition ( ) const
inline

Gets the state composition for this frame. Thread safe if called in update. If called in pre-update, there may be a data race as to whether or not the animation has been updated for this frame.

Template Parameters
Anenum containing all the states, the underlying type must be int.
Returns
The composition for this frame

Definition at line 276 of file StateAnimatable.hpp.

◆ getStructure()

template<typename S >
template<typename T >
S Kale::StateAnimatable< S >::getStructure ( T state) const
inline

Gets a structure for a specific state

Template Parameters
Anenum containing all the states, the underlying type must be int.
Parameters
stateThe state to get the structure for
Returns
A copy of the structure at this state (a copy is used to avoid references across threads)

Definition at line 190 of file StateAnimatable.hpp.

◆ isTransitioning()

template<typename S >
bool Kale::StateAnimatable< S >::isTransitioning ( ) const
inline

Returns whether or not the animation is transitioning between two states. Thread safe if called in update. If called in pre-update, there may be a data race as to whether or not the animation has been updated for this frame.

Returns
Whether or not the animation is transitioning between two states

Definition at line 294 of file StateAnimatable.hpp.

◆ removeStructure()

template<typename S >
template<typename T >
void Kale::StateAnimatable< S >::removeStructure ( T state)
inline

Removes a structure from the map of states

Template Parameters
Anenum containing all the states, the underlying type must be int.
Parameters
stateThe state to remove the structure from

Definition at line 180 of file StateAnimatable.hpp.

◆ setState()

template<typename S >
template<typename T >
void Kale::StateAnimatable< S >::setState ( T state)
inline

Instantly sets a state, thread safe. If called in pre-update then the state may be updated next frame depending on whether or not preUpdate has already been called.

Template Parameters
Anenum containing all the states, the underlying type must be int.
Parameters
stateThe state to set

Definition at line 251 of file StateAnimatable.hpp.

◆ updateState()

template<typename S >
void Kale::StateAnimatable< S >::updateState ( float deltaTime)
inline

Updates the state of the node

Note
There is no need to call this manually, it is the responsibility of the node which contains this state animatable to update.
Parameters
deltaTimeThe duration of the last frame in microseconds

Definition at line 131 of file StateAnimatable.hpp.

Member Data Documentation

◆ animationIndex

template<typename S >
size_t Kale::StateAnimatable< S >::animationIndex
protected

The current animation index in animationInfo

Definition at line 80 of file StateAnimatable.hpp.

◆ animationInfo

template<typename S >
std::vector<std::pair<int, float> > Kale::StateAnimatable< S >::animationInfo
protected

Information regarding the current animation. If set, it means we're currently animating through a series of states and durations

Definition at line 75 of file StateAnimatable.hpp.

◆ animationLoop

template<typename S >
bool Kale::StateAnimatable< S >::animationLoop
protected

Whether or not we are to loop through the information in animationInfo in an infinite loop

Definition at line 85 of file StateAnimatable.hpp.

◆ state

template<typename S >
int Kale::StateAnimatable< S >::state
protected

The path state currently being rendered

Definition at line 45 of file StateAnimatable.hpp.

◆ structures

template<typename S >
std::unordered_map<int, S> Kale::StateAnimatable< S >::structures
protected

Contains structures for each state

Definition at line 70 of file StateAnimatable.hpp.

◆ transitionDuration

template<typename S >
float Kale::StateAnimatable< S >::transitionDuration
protected

The duration in seconds for the transition to last

Definition at line 65 of file StateAnimatable.hpp.

◆ transitioning

template<typename S >
bool Kale::StateAnimatable< S >::transitioning
protected

Whether or not the path is morphing between two paths

Definition at line 55 of file StateAnimatable.hpp.

◆ transitionState

template<typename S >
int Kale::StateAnimatable< S >::transitionState
protected

The state currently being transitioned to

Definition at line 50 of file StateAnimatable.hpp.

◆ transitionTime

template<typename S >
float Kale::StateAnimatable< S >::transitionTime
protected

The transition time between the two paths

Definition at line 60 of file StateAnimatable.hpp.


The documentation for this class was generated from the following file: