OpenBarnyard
 
Loading...
Searching...
No Matches
ANamedAnimation.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "ANamedAnimation.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
17
18// $Barnyard: FUNCTION 00581b40
22
24{
25 m_strTransitionName = a_strName;
26}
27
28// $Barnyard: FUNCTION 00583330
30{
31 m_strAnimationName = a_strName;
32}
33
35{
36 return m_strTransitionName;
37}
38
40{
41 return m_strAnimationName;
42}
43
45{
46 m_fBlendInTime = a_fTime;
47}
48
50{
51 return m_fBlendInTime;
52}
53
55{
56 m_fBlendOutTime = a_fTime;
57}
58
60{
61 return m_fBlendOutTime;
62}
63
65{
66 m_bAutoTransition = a_bAutoTransition;
67}
68
70{
71 m_bManaged = a_bManaged;
72}
73
75{
76 return m_bAutoTransition;
77}
78
80{
81 return m_bManaged;
82}
83
84// $Barnyard: FUNCTION 00581d90
86 : m_pAnimation( a_pNamedAnimation )
87 , m_mapTransitions( a_pAllocator )
88 , m_bUnk3( TFALSE )
89{
90}
91
92// $Barnyard: FUNCTION 00582170
96
97// $Barnyard: FUNCTION 00581ff0
98void ANamedAnimationTransitionSet::AddTransition( ANamedAnimation* a_pAnimation, const TPString8& a_strTransitionName, TFLOAT a_fBlendOutTime, TFLOAT a_fBlendInTime, TBOOL a_bIsAutoTransition, TBOOL a_bManaged )
99{
100 TVALIDPTR( a_pAnimation );
101
102 // Create new transition object
103 ANamedAnimationTransition transition;
104 transition.m_strTransitionName = a_strTransitionName;
105 transition.m_strAnimationName = a_pAnimation->GetName();
106 transition.m_fBlendOutTime = a_fBlendOutTime;
107 transition.m_fBlendInTime = a_fBlendInTime;
108 transition.m_bAutoTransition = a_bIsAutoTransition != '\0';
109 transition.m_bManaged = a_bManaged;
110
111 m_mapTransitions.Insert( a_pAnimation->GetName(), transition );
112
113 if ( a_bIsAutoTransition )
114 m_strAnimationName = a_pAnimation->GetName();
115}
116
117// $Barnyard: FUNCTION 00581ad0
119{
120 auto it = m_mapTransitions[ a_strName ];
121 return ( it == m_mapTransitions.End() ) ? TNULL : &it.GetValue()->second;
122}
123
124// $Barnyard: FUNCTION 00581b10
126{
127 if ( !m_strAnimationName.IsEmpty() )
128 {
129 return FindTransition( m_strAnimationName );
130 }
131
132 return TNULL;
133}
134
135// $Barnyard: FUNCTION 00580520
136ANamedAnimation::ANamedAnimation( T2Allocator* a_pAllocator )
137 : m_vecBreakpoints( a_pAllocator, 0, 0 )
138 , m_oTransitionSet( this, a_pAllocator )
139{
140 m_iSequenceId = -1;
141 m_eFlags = FLAGS_NONE;
142 m_fDefaultBlendOutTime = 0.3f;
143 m_fDefaultBlendInTime = 0.3f;
144 m_fDefaultWeight = 1.0f;
145 m_fSpeed = 1.0f;
146 m_pAllocator = a_pAllocator;
147
148 m_eFlags = FLAGS_NONE;
149 m_eFlags = m_eFlags | FLAGS_LOOP;
150}
151
152// $Barnyard: FUNCTION 005805b0
154{
155 // Delete breakpoints
156 T2_FOREACH( m_vecBreakpoints, it )
157 {
158 delete ( *it );
159 }
160
161 m_vecBreakpoints.Clear();
162}
163
164TPSTRING8_DECLARE( EndOfAnim );
165
166// $Barnyard: FUNCTION 00581a90
168{
169 return ( !a_rcFinishType.GetString8().IsEmpty() && a_rcFinishType == TPS8( EndOfAnim ) ) ? FINISHTYPE_AUTO : FINISHTYPE_MANUAL;
170}
171
172// $Barnyard: FUNCTION 00580150 TODO
173static AAnimationBreakpoint* CreateBreakpointRuntime( const PBProperties* a_pProperties, TBOOL a_bTimedCall )
174{
175 TIMPLEMENT();
176
177 return TNULL;
178}
179
180TPSTRING8_DECLARE( Model );
181
182// $Barnyard: FUNCTION 00580760
183TBOOL ANamedAnimation::Create( const PBProperties* a_pProperties, TSkeleton* a_pSkeleton )
184{
185 m_eFlags &= ~FLAGS_LOOP;
186 m_fDefaultBlendInTime = 0.3f;
187 m_fDefaultBlendOutTime = 0.3f;
188 m_fDefaultWeight = 1.0f;
189
190 TINT iNumBreakpoints = 0;
191 TPString8 strDefaultFinishType;
192
193 T2_FOREACH( ( *a_pProperties ), it )
194 {
195 const TCHAR* pchPropertyName = it->GetName().GetString();
196
197 switch ( *pchPropertyName )
198 {
199 case 'B':
200 // Breakpoint
201 iNumBreakpoints += 1;
202 break;
203 case 'D':
204 if ( !T2String8::Compare( pchPropertyName, "DefaultBlendInTime" ) )
205 {
206 m_fDefaultBlendInTime = it->GetValue()->GetFloat();
207 }
208 else if ( !T2String8::Compare( pchPropertyName, "DefaultBlendOutTime" ) )
209 {
210 m_fDefaultBlendOutTime = it->GetValue()->GetFloat();
211 }
212 else if ( !T2String8::Compare( pchPropertyName, "DefaultFinishType" ) )
213 {
214 strDefaultFinishType = it->GetValue()->GetTPString8();
215 }
216 else if ( !T2String8::Compare( pchPropertyName, "DefaultWeight" ) )
217 {
218 m_fDefaultWeight = it->GetValue()->GetFloat();
219 }
220 else if ( !T2String8::Compare( pchPropertyName, "DefaultSpeed" ) )
221 {
222 m_fSpeed = it->GetValue()->GetFloat();
223 }
224
225 break;
226 case 'E':
227 // ExportedName
228 m_strExportedName = it->GetValue()->GetTPString8();
229 break;
230 case 'L':
231 // Loop
232
233 if ( it->GetValue()->GetBoolean() )
234 m_eFlags |= FLAGS_LOOP;
235 else
236 m_eFlags &= ~FLAGS_LOOP;
237
238 break;
239 case 'N':
240 // Name
241 m_strName = it->GetValue()->GetTPString8();
242 break;
243 case 'R':
244 // Reverse
245
246 if ( it->GetValue()->GetBoolean() )
247 m_eFlags |= FLAGS_REVERSE;
248 else
249 m_eFlags &= ~FLAGS_REVERSE;
250
251 break;
252 case 'S':
253 if ( !T2String8::Compare( pchPropertyName, "Static" ) )
254 {
255 if ( it->GetValue()->GetBoolean() )
256 m_eFlags |= FLAGS_STATIC;
257 else
258 m_eFlags &= ~FLAGS_STATIC;
259 }
260 else if ( !T2String8::Compare( pchPropertyName, "Speed" ) )
261 {
262 m_fSpeed = it->GetValue()->GetFloat();
263 }
264
265 break;
266 }
267 }
268
269 TASSERT( !m_strName.IsEmpty() );
270 TASSERT( !m_strExportedName.IsEmpty() );
271
272 m_iSequenceId = a_pSkeleton->GetSequenceID( m_strExportedName, 0 );
273 TASSERT( m_iSequenceId != -1 );
274
275 if ( m_iSequenceId != -1 )
276 {
277 TSkeletonSequence* pSequence = a_pSkeleton->GetSequence( m_iSequenceId );
278
279 if ( pSequence->IsOverlay() )
280 m_eFlags |= FLAGS_OVERLAY;
281 else
282 m_eFlags &= ~FLAGS_OVERLAY;
283
284 m_fDuration = pSequence->GetDuration();
285
287 m_eFlags |= ( GetFinishType( strDefaultFinishType ) == FINISHTYPE_AUTO ) ? FLAGS_FINISH_ON_ANIM_END : FLAGS_FINISH_MANUAL;
288
289 TPString8 strModelName;
290 a_pProperties->GetParentProperties()->GetParentProperties()->GetOptionalPropertyValue( strModelName, TPS8( Model ) );
291
292 // Allocate space to store breakpoints
293 TINT iNumSoundBreakpoints = AAnimatableObjectManager::GetSingleton()->FindNumAnimationSoundBreakpoints( strModelName, this );
294 m_vecBreakpoints.AccessContainer()->Reserve( iNumBreakpoints + iNumSoundBreakpoints + 4 );
295
296 // Read breakpoints stored in the properties
297
298 T2_FOREACH( ( *a_pProperties ), it )
299 {
300 const TCHAR* pchPropertyName = it->GetName().GetString();
301
302 if ( *pchPropertyName == 'B' )
303 {
304 // Breakpoint
305 AAnimationBreakpoint* pBreakpoint = CreateBreakpointRuntime( it->GetValue()->GetProperties(), TTRUE );
306
307 if ( pBreakpoint )
308 {
309 m_vecBreakpoints.Push( pBreakpoint );
310 }
311 }
312 }
313
314 return TTRUE;
315 }
316 else
317 {
318 TERROR( "Couldn't get '%s' (Exported Name: '%s') animation from an animation set!", m_strName.GetString(), m_strExportedName.GetString() );
319 return TFALSE;
320 }
321}
322
323TPSTRING8_DECLARE( null );
324
325// $Barnyard: FUNCTION 00580680
327{
328 m_strName = TPS8( null );
329 m_strExportedName = TPS8( null );
330
331 m_eFlags &= ~FLAGS_LOOP;
332 m_eFlags &= ~FLAGS_NO_ANIM_REF;
333 m_fDefaultBlendOutTime = 0.3f;
334 m_fDefaultBlendInTime = 0.3f;
335 m_fDefaultWeight = 1.0f;
336 m_fSpeed = 1.0f;
337 m_iSequenceId = -1;
338
340 m_eFlags |= FLAGS_FINISH_MANUAL;
341}
342
343// $Barnyard: FUNCTION 00580750
345{
346 m_vecBreakpoints.Push( a_pBreakpoint );
347}
348
349// Various template functions:
350// $Barnyard: FUNCTION 00580710
351// $Barnyard: FUNCTION 00580440
352// $Barnyard: FUNCTION 006cbde0
#define TIMPLEMENT()
Definition Defines.h:136
#define TASSERT(X,...)
Definition Defines.h:138
#define TERROR(...)
Definition Defines.h:153
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define T2_FOREACH(vecName, iteratorName)
Definition T2Iterator.h:4
#define TPSTRING8_DECLARE(STR)
Definition TPString8.h:15
#define TPS8(STR)
Definition TPString8.h:16
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
const PBProperties * GetParentProperties() const
TBOOL GetOptionalPropertyValue(T &a_rOutValue, const TCHAR *a_szName) const
TFLOAT GetDuration() const
Definition TSkeleton.h:75
TBOOL IsOverlay() const
Definition TSkeleton.h:70
TINT GetSequenceID(const TCHAR *a_sSequenceName, TUINT32 a_iLength=0)
Definition TSkeleton.cpp:98
TSkeletonSequence * GetSequence(TINT a_iSequence)
Definition TSkeleton.h:154
static TINT Compare(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:52
TFORCEINLINE const TString8 & GetString8() const
Definition TPString8.h:172
TBOOL IsEmpty() const
Definition TString8.h:104
const Toshi::TPString8 & GetAnimationName()
void SetBlendOutTime(TFLOAT a_fTime)
void SetAutoTransition(TBOOL a_bAutoTransition)
void SetManaged(TBOOL a_bManaged)
const Toshi::TPString8 & GetTransitionName()
void SetTransitionName(const Toshi::TPString8 &a_strName)
void SetBlendInTime(TFLOAT a_fTime)
void SetAnimationName(const Toshi::TPString8 &a_strName)
ANamedAnimationTransitionSet(ANamedAnimation *a_pNamedAnimation, Toshi::T2Allocator *a_pAllocator)
ANamedAnimationTransition * GetDestTransition()
ANamedAnimationTransition * FindTransition(const Toshi::TPString8 &a_strName)
void AddTransition(ANamedAnimation *a_pAnimation, const Toshi::TPString8 &a_strTransitionName, TFLOAT a_fBlendOutTime, TFLOAT a_fBlendInTime, TBOOL a_bIsAutoTransition, TBOOL a_bManaged)
static FINISHTYPE GetFinishType(const Toshi::TPString8 &a_rcFinishType)
void AttachBreakpoint(AAnimationBreakpoint *a_pBreakpoint)
ANamedAnimation(Toshi::T2Allocator *a_pAllocator)
TBOOL Create(const PBProperties *a_pProperties, Toshi::TSkeleton *a_pSkeleton)
const Toshi::TPString8 & GetName() const