OpenBarnyard
 
Loading...
Searching...
No Matches
ANamedAnimationSet.cpp
Go to the documentation of this file.
1#include "pch.h"
3
4//-----------------------------------------------------------------------------
5// Enables memory debugging.
6// Note: Should be the last include!
7//-----------------------------------------------------------------------------
9
11
13
14// $Barnyard: FUNCTION 00580e30
16 : m_mapAnimations( GetGlobalAllocator() )
17{
18 m_pAllocator = GetGlobalAllocator();
19 m_eOverlayType = OVERLAYTYPE_NONE;
20}
21
22// $Barnyard: FUNCTION 00580ea0
23ANamedAnimationSet::ANamedAnimationSet( Toshi::T2Allocator* a_pAllocator )
24 : m_mapAnimations( a_pAllocator )
25{
26 m_pAllocator = a_pAllocator;
27 m_eOverlayType = OVERLAYTYPE_NONE;
28}
29
30// $Barnyard: FUNCTION 00581820
31// $Barnyard: FUNCTION 005815e0
36
37TPSTRING8_DECLARE( Name );
38TPSTRING8_DECLARE( null );
39TPSTRING8_DECLARE( blink );
40TPSTRING8_DECLARE( lookl );
41TPSTRING8_DECLARE( lookr );
42TPSTRING8_DECLARE( looku );
43TPSTRING8_DECLARE( lookd );
44
45// $Barnyard: FUNCTION 00581840
46TBOOL ANamedAnimationSet::CreateFromProperties( const PBProperties* a_pProperties, Toshi::TSkeleton* a_pSkeleton )
47{
48 // Get animation set name
49 TPString8 strSetName;
50 a_pProperties->GetOptionalPropertyValue( strSetName, TPS8( Name ) );
51
52 m_strName = strSetName;
53 auto pNullAnim = m_mapAnimations.Find( TPS8( null ) );
54
55 if ( !m_mapAnimations.IsValid( pNullAnim ) || pNullAnim.GetValue()->GetSecond() == TNULL )
56 {
57 // Create null (default) animation if it's not created yet
58 ANamedAnimation oUnused( m_pAllocator );
59
60 ANamedAnimation* pNullAnim = new ANamedAnimation( m_pAllocator );
61 pNullAnim->Reset();
62
63 m_mapAnimations.Insert( TPS8( null ), pNullAnim );
64 }
65
66 // Load all named animations
67 T2_FOREACH( ( *a_pProperties ), it )
68 {
69 if ( it->GetValue()->GetType() == PBPropertyValue::Type::Properties &&
70 it->GetName().GetString()[ 0 ] == 'N' )
71 {
72 // NamedAnimation
73 ANamedAnimation* pAnim = LoadNamedAnimation( it->GetValue()->GetProperties(), a_pSkeleton );
74
75 if ( pAnim && pAnim->IsOverlay() )
76 {
77 if ( pAnim->GetName() == TPS8( blink ) )
78 m_eOverlayType = OVERLAYTYPE_BLINK;
79 else if ( pAnim->GetName() == TPS8( lookl ) )
80 m_eOverlayType = OVERLAYTYPE_LOOK_LEFT;
81 else if ( pAnim->GetName() == TPS8( lookr ) )
82 m_eOverlayType = OVERLAYTYPE_LOOK_RIGHT;
83 else if ( pAnim->GetName() == TPS8( looku ) )
84 m_eOverlayType = OVERLAYTYPE_LOOK_UP;
85 else if ( pAnim->GetName() == TPS8( lookd ) )
86 m_eOverlayType = OVERLAYTYPE_LOOK_DOWN;
87 }
88 }
89 }
90
91 // Load transitions
92 T2_FOREACH( ( *a_pProperties ), it )
93 {
94 if ( it->GetValue()->GetType() == PBPropertyValue::Type::Properties &&
95 it->GetName().GetString()[ 0 ] == 'A' )
96 {
97 TBOOL bRes = LoadAnimationTransition( it->GetValue()->GetProperties() );
98
99 TASSERT( bRes == TTRUE );
100 }
101 }
102
103 return TTRUE;
104}
105
107{
108 // Delete all named animations
109 while ( !m_mapAnimations.IsEmpty() )
110 {
111 auto it = m_mapAnimations.Begin();
112 ANamedAnimation* pAnim = it->GetSecond();
113
114 if ( pAnim )
115 delete pAnim;
116
117 m_mapAnimations.Remove( it );
118 }
119
120 m_eOverlayType = OVERLAYTYPE_NONE;
121 m_strName = TPString8();
122}
123
124// $Barnyard: FUNCTION 00580d50
125TBOOL ANamedAnimationSet::AddSoundBreakpoint( ASoundBreakpoint* a_pSoundBreakpoint, Toshi::TSkeleton* a_pSkeleton )
126{
127 TASSERT( !"TODO" );
128 return TTRUE;
129}
130
131// $Barnyard: FUNCTION 00580c50
132ANamedAnimation* ANamedAnimationSet::GetNamedAnimation( const Toshi::TPString8& a_strName )
133{
134 auto it = m_mapAnimations.Find( a_strName );
135
136 if ( it != m_mapAnimations.End() )
137 return it->second;
138
139 return TNULL;
140}
141
142// $Barnyard: FUNCTION 00581700
143ANamedAnimation* ANamedAnimationSet::LoadNamedAnimation( const PBProperties* a_pProperties, Toshi::TSkeleton* a_pSkeleton )
144{
145 // Get animation name
146 TPString8 strName;
147 a_pProperties->GetOptionalPropertyValue( strName, TPS8( Name ) );
148
149 ANamedAnimation* pNamedAnimation = new ANamedAnimation( m_pAllocator );
150
151 if ( pNamedAnimation->Create( a_pProperties, a_pSkeleton ) )
152 {
153 m_mapAnimations.Insert( strName, pNamedAnimation );
154 return pNamedAnimation;
155 }
156
157 // Couldn't create animation, free memory
158 delete pNamedAnimation;
159 return TNULL;
160}
161
162TPSTRING8_DECLARE( BlendInTime );
163TPSTRING8_DECLARE( BlendOutTime );
164TPSTRING8_DECLARE( TransitionName );
165TPSTRING8_DECLARE( AutoTransition );
166TPSTRING8_DECLARE( FinishType );
167TPSTRING8_DECLARE( LinkTo );
168
169// $Barnyard: FUNCTION 00580f10
170TBOOL ANamedAnimationSet::LoadAnimationTransition( const PBProperties* a_pProperties )
171{
172 TFLOAT fBlendInTime;
173 TBOOL bHasBlendIn = a_pProperties->GetOptionalPropertyValue( fBlendInTime, TPS8( BlendInTime ) );
174
175 TFLOAT fBlendOutTime;
176 TBOOL bHasBlendOut = a_pProperties->GetOptionalPropertyValue( fBlendOutTime, TPS8( BlendOutTime ) );
177
178 TPString8 strTransitionName;
179 a_pProperties->GetOptionalPropertyValue( strTransitionName, TPS8( TransitionName ) );
180
181 TBOOL bIsAutoTransition;
182 a_pProperties->GetOptionalPropertyValue( bIsAutoTransition, TPS8( AutoTransition ) );
183
184 TPString8 strFinishType;
186 TBOOL bHasFinishType = a_pProperties->GetOptionalPropertyValue( strFinishType, TPS8( FinishType ) );
187
188 if ( bHasFinishType )
189 eFinishType = ANamedAnimation::GetFinishType( strFinishType );
190
191 // Get animation to link to
192 TPString8 strLinkTo;
193 a_pProperties->GetOptionalPropertyValue( strLinkTo, TPS8( LinkTo ) );
194
195 auto pLinkTo = m_mapAnimations.Find( strLinkTo );
196 if ( m_mapAnimations.IsValid( pLinkTo ) && pLinkTo->GetSecond() != TNULL )
197 {
198 const PBPropertyValue* pLinkFromProperty = a_pProperties->GetProperty( "LinkFrom" );
199 TVALIDPTR( pLinkFromProperty );
200
201 if ( pLinkFromProperty->GetType() == PBPropertyValue::Type::String )
202 {
203 auto pLinkFrom = m_mapAnimations.Find( pLinkFromProperty->GetTPString8() );
204
205 if ( !m_mapAnimations.IsValid( pLinkFrom ) || pLinkFrom->GetSecond() == TNULL )
206 {
207 TERROR( "Invalid LinkFrom property specified." );
208 return TFALSE;
209 }
210
211 TASSERT( !"Not implemented" );
212 return TTRUE;
213 }
214 }
215
216 return TFALSE;
217}
#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
TFORCEINLINE T2Allocator * GetGlobalAllocator()
Definition T2Allocator.h:49
#define T2_FOREACH(vecName, iteratorName)
Definition T2Iterator.h:4
#define TDEFINE_CLASS(...)
Definition TObject.h:120
#define TPSTRING8_DECLARE(STR)
Definition TPString8.h:15
#define TPS8(STR)
Definition TPString8.h:16
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
Type GetType() const
const PBPropertyValue * GetProperty(const TCHAR *a_szName) const
TBOOL GetOptionalPropertyValue(T &a_rOutValue, const TCHAR *a_szName) const
static FINISHTYPE GetFinishType(const Toshi::TPString8 &a_rcFinishType)
TBOOL Create(const PBProperties *a_pProperties, Toshi::TSkeleton *a_pSkeleton)
const Toshi::TPString8 & GetName() const
TBOOL IsOverlay() const
TBOOL AddSoundBreakpoint(ASoundBreakpoint *a_pSoundBreakpoint, Toshi::TSkeleton *a_pSkeleton)
ANamedAnimation * GetNamedAnimation(const Toshi::TPString8 &a_strName)
TBOOL CreateFromProperties(const PBProperties *a_pProperties, Toshi::TSkeleton *a_pSkeleton)