OpenBarnyard
 
Loading...
Searching...
No Matches
TAnimation Class Reference

#include <TAnimation.h>

Inheritance diagram for TAnimation:
TQList< T >::TNode

Public Types

enum  Flags_ : Flags {
  Flags_None = 0 , Flags_Active = BITFLAG( 0 ) , Flags_Managed = BITFLAG( 1 ) , Flags_Unknown2 = BITFLAG( 2 ) ,
  Flags_UpdateStateOnRemove = BITFLAG( 3 )
}
 
enum  State_ : State { STATE_BLENDING_IN , STATE_PLAYING , STATE_BLENDING_OUT }
 
using Flags = TUINT16
 
using State = TUINT32
 
- Public Types inherited from TQList< T >::TNode
using Iterator = Toshi::T2Iterator<T, TNode>
 

Public Member Functions

 TAnimation ()
 
 ~TAnimation ()
 
TBOOL UpdateTime (TFLOAT a_fDeltaTime)
 
void RemoveAnimation (TFLOAT a_fVal)
 
void SetState (State a_eState)
 
TFLOAT SetSpeed (TFLOAT a_fSpeed)
 
TFLOAT SetDestWeight (TFLOAT a_fDestWeight, TFLOAT a_fBlendInSpeed)
 
void SetBlendInSpeed (TFLOAT a_fBlendInSpeed)
 
void SetBlendOutSpeed (TFLOAT a_fBlendOutSpeed)
 
void ChangeToManaged (TFLOAT a_fBlendOutSpeed)
 
Flags GetFlags () const
 
State GetState () const
 
TBOOL IsActive () const
 
TBOOL IsManaged () const
 
TBOOL IsUpdateStateOnRemove () const
 
TUINT16 GetSequence () const
 
class TSkeletonSequenceGetSequencePtr () const
 
TSkeletonInstanceGetSkeletonInstance () const
 
TFLOAT GetSpeed () const
 
TFLOAT GetSeqTime () const
 
TFLOAT GetTotalTime () const
 
TFLOAT GetWeight () const
 
TFLOAT GetDestWeight () const
 
TFLOAT GetBlendInSpeed () const
 
TFLOAT GetBlendOutSpeed () const
 
TAnimationBoneGetBones ()
 
TAnimationBoneGetBone (TINT a_iIndex)
 
- Public Member Functions inherited from TQList< T >::TNode
 TNode ()
 
 ~TNode ()
 
TBOOL IsLinked () const
 
T * Next () const
 
T * Prev () const
 
void Remove ()
 

Friends

class TSkeletonInstance
 

Additional Inherited Members

- Public Attributes inherited from TQList< T >::TNode
friend TQList
 

Detailed Description

Definition at line 22 of file TAnimation.h.

Member Typedef Documentation

◆ Flags

Definition at line 25 of file TAnimation.h.

◆ State

Definition at line 35 of file TAnimation.h.

Member Enumeration Documentation

◆ Flags_

Enumerator
Flags_None 
Flags_Active 
Flags_Managed 
Flags_Unknown2 
Flags_UpdateStateOnRemove 

Definition at line 26 of file TAnimation.h.

27 {
28 Flags_None = 0,
29 Flags_Active = BITFLAG( 0 ),
33 };
#define BITFLAG(x)
Definition Defines.h:10
@ Flags_UpdateStateOnRemove
Definition TAnimation.h:32

◆ State_

Enumerator
STATE_BLENDING_IN 
STATE_PLAYING 
STATE_BLENDING_OUT 

Definition at line 36 of file TAnimation.h.

Constructor & Destructor Documentation

◆ TAnimation()

TAnimation::TAnimation ( )

Definition at line 125 of file TAnimation.cpp.

126{
127}

◆ ~TAnimation()

TAnimation::~TAnimation ( )

Definition at line 129 of file TAnimation.cpp.

130{
131}

Member Function Documentation

◆ ChangeToManaged()

void TAnimation::ChangeToManaged ( TFLOAT a_fBlendOutSpeed)

Definition at line 134 of file TAnimation.cpp.

135{
136 if ( IsActive() && !IsManaged() )
137 {
138 TFLOAT fSeqDuration = m_pSkeletonInstance->GetSkeleton()->GetSequence( m_iSeqID )->GetDuration();
139
140 m_eFlags |= Flags_Managed;
141 m_fBlendOutSpeed = a_fBlendOutSpeed;
142 m_fSeqTime = m_fSeqTime - TMath::FloorToInt( m_fSeqTime / fSeqDuration ) * fSeqDuration;
143 m_fTotalTime = m_fSeqTime;
144 }
145}
float TFLOAT
Definition Typedefs.h:4
TFORCEINLINE TINT FloorToInt(TFLOAT a_fVal)
TBOOL IsActive() const
Definition TAnimation.h:60
TBOOL IsManaged() const
Definition TAnimation.h:61

◆ GetBlendInSpeed()

TFLOAT TAnimation::GetBlendInSpeed ( ) const
inline

Definition at line 72 of file TAnimation.h.

72{ return m_fBlendInSpeed; }

◆ GetBlendOutSpeed()

TFLOAT TAnimation::GetBlendOutSpeed ( ) const
inline

Definition at line 73 of file TAnimation.h.

73{ return m_fBlendOutSpeed; }

◆ GetBone()

TAnimationBone * TAnimation::GetBone ( TINT a_iIndex)
inline

Definition at line 76 of file TAnimation.h.

76{ return &TREINTERPRETCAST( TAnimationBone*, this + 1 )[ a_iIndex ]; }
unsigned short TAnimationBone
Definition TAnimation.h:18
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68

◆ GetBones()

TAnimationBone * TAnimation::GetBones ( )
inline

Definition at line 75 of file TAnimation.h.

75{ return TREINTERPRETCAST( TAnimationBone*, this + 1 ); }

◆ GetDestWeight()

TFLOAT TAnimation::GetDestWeight ( ) const
inline

Definition at line 71 of file TAnimation.h.

71{ return m_fDestWeight; }

◆ GetFlags()

Flags TAnimation::GetFlags ( ) const
inline

Definition at line 58 of file TAnimation.h.

58{ return m_eFlags; }

◆ GetSeqTime()

TFLOAT TAnimation::GetSeqTime ( ) const
inline

Definition at line 68 of file TAnimation.h.

68{ return m_fSeqTime; }

◆ GetSequence()

TUINT16 TAnimation::GetSequence ( ) const
inline

Definition at line 64 of file TAnimation.h.

64{ return m_iSeqID; }

◆ GetSequencePtr()

TSkeletonSequence * TAnimation::GetSequencePtr ( ) const

Definition at line 120 of file TAnimation.cpp.

121{
122 return m_pSkeletonInstance->GetSkeleton()->GetSequence( m_iSeqID );
123}

◆ GetSkeletonInstance()

TSkeletonInstance * TAnimation::GetSkeletonInstance ( ) const
inline

Definition at line 66 of file TAnimation.h.

66{ return m_pSkeletonInstance; }

◆ GetSpeed()

TFLOAT TAnimation::GetSpeed ( ) const
inline

Definition at line 67 of file TAnimation.h.

67{ return m_fSpeed; }

◆ GetState()

State TAnimation::GetState ( ) const
inline

Definition at line 59 of file TAnimation.h.

59{ return m_eState; }

◆ GetTotalTime()

TFLOAT TAnimation::GetTotalTime ( ) const
inline

Definition at line 69 of file TAnimation.h.

69{ return m_fTotalTime; }

◆ GetWeight()

TFLOAT TAnimation::GetWeight ( ) const
inline

Definition at line 70 of file TAnimation.h.

70{ return m_fWeight; }

◆ IsActive()

TBOOL TAnimation::IsActive ( ) const
inline

Definition at line 60 of file TAnimation.h.

60{ return m_eFlags & Flags_Active; }

◆ IsManaged()

TBOOL TAnimation::IsManaged ( ) const
inline

Definition at line 61 of file TAnimation.h.

61{ return m_eFlags & Flags_Managed; }

◆ IsUpdateStateOnRemove()

TBOOL TAnimation::IsUpdateStateOnRemove ( ) const
inline

Definition at line 62 of file TAnimation.h.

62{ return m_eFlags & Flags_UpdateStateOnRemove; }

◆ RemoveAnimation()

void TAnimation::RemoveAnimation ( TFLOAT a_fVal)

Definition at line 94 of file TAnimation.cpp.

95{
96 if ( m_pSkeletonInstance )
97 m_pSkeletonInstance->RemoveAnimation( this, a_fVal );
98}

◆ SetBlendInSpeed()

void TAnimation::SetBlendInSpeed ( TFLOAT a_fBlendInSpeed)
inline

Definition at line 53 of file TAnimation.h.

53{ m_fBlendInSpeed = a_fBlendInSpeed; }

◆ SetBlendOutSpeed()

void TAnimation::SetBlendOutSpeed ( TFLOAT a_fBlendOutSpeed)
inline

Definition at line 54 of file TAnimation.h.

54{ m_fBlendOutSpeed = a_fBlendOutSpeed; }

◆ SetDestWeight()

TFLOAT TAnimation::SetDestWeight ( TFLOAT a_fDestWeight,
TFLOAT a_fBlendInSpeed )

Definition at line 100 of file TAnimation.cpp.

101{
102 TFLOAT fOldValue = m_fDestWeight;
103
104 m_fDestWeight = a_fDestWeight;
105 m_fBlendInSpeed = a_fBlendInSpeed;
106
107 if ( 0.0f < a_fBlendInSpeed )
108 {
109 m_eState = STATE_BLENDING_IN;
110 }
111 else
112 {
113 m_fWeight = a_fDestWeight;
114 m_eState = STATE_PLAYING;
115 }
116
117 return fOldValue;
118}

◆ SetSpeed()

TFLOAT TAnimation::SetSpeed ( TFLOAT a_fSpeed)
inline

Definition at line 51 of file TAnimation.h.

51{ return std::exchange( m_fSpeed, a_fSpeed ); }

◆ SetState()

void TAnimation::SetState ( State a_eState)
inline

Definition at line 50 of file TAnimation.h.

50{ m_eState = a_eState; }

◆ UpdateTime()

TBOOL TAnimation::UpdateTime ( TFLOAT a_fDeltaTime)

Definition at line 14 of file TAnimation.cpp.

15{
16 TSkeleton* pSkeleton = m_pSkeletonInstance->GetSkeleton();
17 TSkeletonSequence* pSeq = pSkeleton->GetSequence( m_iSeqID );
18
19 TFLOAT fSeqDuration = pSeq->GetDuration();
20
21 m_fTotalTime += m_fSpeed * a_fDeltaTime;
22 m_fSeqTime += m_fSpeed * a_fDeltaTime;
23
24 if ( pSeq->GetUnk2() == 0 && !HASANYFLAG( m_eFlags, Flags_Managed ) )
25 {
26 if ( 0.0f <= m_fSpeed || 0.0f <= m_fSeqTime )
27 {
28 if ( fSeqDuration <= m_fSeqTime )
29 {
30 // Make m_fSeqTime less than animation duration
31 m_fSeqTime -= TMath::FloorToInt( m_fSeqTime / fSeqDuration ) * fSeqDuration;
32
33 // Reset states of all bones
34 for ( TINT i = 0; i < pSkeleton->GetAutoBoneCount(); i++ )
35 *GetBone( i ) = 0;
36 }
37 }
38 else
39 {
40 m_fSeqTime = fSeqDuration;
41 }
42 }
43 else
44 {
45 if ( m_fSeqTime < 0.0f && m_fSpeed < 0.0f )
46 m_fSeqTime = fSeqDuration;
47
48 if ( 0.0f <= m_fSeqTime )
49 {
50 if ( fSeqDuration < m_fSeqTime )
51 {
52 m_fSeqTime = fSeqDuration;
53 }
54 }
55 else
56 {
57 m_fSeqTime = 0.0f;
58 }
59 }
60
61 if ( m_eState == STATE_BLENDING_IN )
62 {
63 m_fWeight = ( m_fBlendInSpeed == 0.0f ) ? m_fDestWeight : m_fWeight + ( 1.0f / m_fBlendInSpeed ) * a_fDeltaTime;
64
65 if ( m_fDestWeight <= m_fWeight )
66 {
67 m_fWeight = m_fDestWeight;
68 m_eState = STATE_PLAYING;
69 }
70 }
71 else if ( m_eState == STATE_PLAYING )
72 {
73 if ( HASANYFLAG( m_eFlags, Flags_Managed ) && fSeqDuration <= m_fTotalTime )
74 {
75 m_eState = STATE_BLENDING_OUT;
76 return TTRUE;
77 }
78 }
79 else if ( m_eState == STATE_BLENDING_OUT )
80 {
81 m_fWeight = ( m_fBlendOutSpeed == 0.0f ) ? -1.0f : m_fWeight - ( 1.0f / m_fBlendOutSpeed ) * a_fDeltaTime;
82
83 if ( m_fWeight <= 0.0f )
84 {
85 m_pSkeletonInstance->RemoveAnimation( this, 0.0f );
86 return HASANYFLAG( m_eFlags, Flags_UpdateStateOnRemove );
87 }
88 }
89
90 return TTRUE;
91}
#define HASANYFLAG(STATE, FLAG)
Definition Defines.h:5
int TINT
Definition Typedefs.h:7
#define TTRUE
Definition Typedefs.h:25
TAnimationBone * GetBone(TINT a_iIndex)
Definition TAnimation.h:76
TINT16 GetUnk2() const
Definition TSkeleton.h:78
TFLOAT GetDuration() const
Definition TSkeleton.h:75
TSkeletonSequence * GetSequence(TINT a_iSequence)
Definition TSkeleton.h:154
TINT GetAutoBoneCount() const
Definition TSkeleton.h:150

Friends And Related Symbol Documentation

◆ TSkeletonInstance

friend class TSkeletonInstance
friend

Definition at line 92 of file TAnimation.h.


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