OpenBarnyard
 
Loading...
Searching...
No Matches
TAnimation.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "TAnimation.h"
3#include "TSkeleton.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
13// $Barnyard: FUNCTION 006caea0
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}
92
93// $Barnyard: FUNCTION 006cb0c0
95{
96 if ( m_pSkeletonInstance )
97 m_pSkeletonInstance->RemoveAnimation( this, a_fVal );
98}
99
100TFLOAT TAnimation::SetDestWeight( TFLOAT a_fDestWeight, TFLOAT a_fBlendInSpeed )
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}
119
121{
122 return m_pSkeletonInstance->GetSkeleton()->GetSequence( m_iSeqID );
123}
124
128
132
133// $Barnyard: FUNCTION 006ca230
134void TAnimation::ChangeToManaged( TFLOAT a_fBlendOutSpeed )
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}
146
#define HASANYFLAG(STATE, FLAG)
Definition Defines.h:5
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
float TFLOAT
Definition Typedefs.h:4
int TINT
Definition Typedefs.h:7
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE TINT FloorToInt(TFLOAT a_fVal)
void ChangeToManaged(TFLOAT a_fBlendOutSpeed)
@ Flags_UpdateStateOnRemove
Definition TAnimation.h:32
TBOOL UpdateTime(TFLOAT a_fDeltaTime)
void RemoveAnimation(TFLOAT a_fVal)
TFLOAT SetDestWeight(TFLOAT a_fDestWeight, TFLOAT a_fBlendInSpeed)
TBOOL IsActive() const
Definition TAnimation.h:60
class TSkeletonSequence * GetSequencePtr() const
TAnimationBone * GetBone(TINT a_iIndex)
Definition TAnimation.h:76
@ STATE_BLENDING_IN
Definition TAnimation.h:38
@ STATE_BLENDING_OUT
Definition TAnimation.h:40
TBOOL IsManaged() const
Definition TAnimation.h:61
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