OpenBarnyard
 
Loading...
Searching...
No Matches
AAnimatableObjectType.cpp
Go to the documentation of this file.
1#include "pch.h"
3#include "AModelRepos.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
13// $Barnyard: FUNCTION 0057ed30
15{
16 m_pAModel = TNULL;
17 m_pUnk = TNULL;
18}
19
20// $Barnyard: FUNCTION 0057f2c0
21// $Barnyard: FUNCTION 0057efe0
26
27TPSTRING8_DECLARE( Name );
28TPSTRING8_DECLARE( Model );
29
30// $Barnyard: FUNCTION 0057f450
31TBOOL AAnimatableObjectType::CreateFromProperties( const PBProperties* a_pProperties, const Toshi::TPString8& a_rcName )
32{
33 TVALIDPTR( a_pProperties );
34 m_strName = a_rcName;
35
36 // Get anim object name
37 TPString8 strObjName;
38 a_pProperties->GetOptionalPropertyValue( strObjName, TPS8( Name ) );
39
40 // Get anim object model name
41 TPString8 strObjModel = strObjName;
42 a_pProperties->GetOptionalPropertyValue( strObjModel, TPS8( Model ) );
43
44 // Get full path to the model
45 TString8 strModelPath;
46 strModelPath.Format( "%s%s", "data\\models\\", strObjModel.GetString() );
47
48 TPString8 strPooledModelPath = TPString8( strModelPath.GetString() );
49
50 // Load model
51 AModelRepos* pModelRepos = AModelRepos::GetSingleton();
52 pModelRepos->LoadModel( strPooledModelPath, TNULL );
53
54 m_pAModel = pModelRepos->GetModel( strPooledModelPath );
55 TVALIDPTR( m_pAModel );
56
57 TBOOL bLoadedAnimationSet = TFALSE;
58
59 T2_FOREACH( ( *a_pProperties ), it )
60 {
61 if ( it->GetValue()->GetType() == PBPropertyValue::Type::Properties )
62 {
63 if ( !T2String8::Compare( it->GetName().GetString(), "NamedAnimationSet" ) )
64 {
65 LoadAnimationSet( it->GetValue()->GetProperties() );
66 bLoadedAnimationSet = TTRUE;
67 }
68 else if ( !T2String8::Compare( it->GetName().GetString(), "AnimControllerType" ) )
69 {
70 SetAnimController( it->GetValue()->GetProperties() );
71 }
72 else if ( !T2String8::Compare( it->GetName().GetString(), "Skins" ) )
73 {
74 SetSkins( it->GetValue()->GetProperties() );
75 }
76 }
77 }
78
79 if ( !bLoadedAnimationSet )
80 LoadAnimationSet( TNULL );
81
82 return TTRUE;
83}
84
85// $Barnyard: FUNCTION 0057f2e0
86TBOOL AAnimatableObjectType::Create( const Toshi::TPString8& a_rcName )
87{
88 m_strName = a_rcName;
89
90 // Get full path to the model
91 TString8 strModelPath;
92 strModelPath.Format( "%s%s", "data\\models\\", m_strName.GetString() );
93
94 TPString8 strPooledModelPath = TPString8( strModelPath.GetString() );
95
96 // Load model
97 AModelRepos* pModelRepos = AModelRepos::GetSingleton();
98 pModelRepos->LoadModel( strPooledModelPath, TNULL );
99
100 m_pAModel = pModelRepos->GetModel( strPooledModelPath );
101 TVALIDPTR( m_pAModel );
102
103 LoadAnimationSet( TNULL );
104
105 return TTRUE;
106}
107
111
112// $Barnyard: FUNCTION 0057eeb0
114{
115 m_vecAnimationSets.Clear();
116 m_llAnimControllerTypes.DeleteAll();
117
118 if ( m_pAModel )
119 {
120 AModelRepos::GetSingleton()->UnloadModel( m_pAModel->GetName(), TFALSE );
121 m_pAModel = TNULL;
122 }
123
124 if ( m_pUnk )
125 {
126 TASSERT( !"Destroy m_pUnk" );
127 delete m_pUnk;
128 m_pUnk = TNULL;
129 }
130}
131
132// $Barnyard: FUNCTION 0057ef40
133ANamedAnimationSetRef AAnimatableObjectType::FindAnimationSet( const Toshi::TPString8& a_rcName ) const
134{
135 for ( TINT i = 0; i < m_vecAnimationSets.Size(); i++ )
136 {
137 if ( m_vecAnimationSets[ i ]->GetName() == a_rcName )
138 {
139 return m_vecAnimationSets[ i ];
140 }
141 }
142
143 return TNULL;
144}
145
146// $Barnyard: FUNCTION 0057efb0
148{
149 TASSERT( a_iIndex < MAX_ANIMATION_SETS );
150
151 if ( m_vecAnimationSets[ a_iIndex ].Get() )
152 return m_vecAnimationSets[ a_iIndex ];
153
154 return ANamedAnimationSetRef();
155}
156
157// $Barnyard: FUNCTION 0057ef10
162
164{
165 return m_vecAnimationSets.Size();
166}
167
169{
170 return AModelRepos::GetSingleton()->InstantiateModel( GetModel() );
171}
172
173// $Barnyard: FUNCTION 0057f060
174TBOOL AAnimatableObjectType::LoadAnimationSet( const PBProperties* a_pProperties )
175{
176 TVALIDPTR( m_pAModel );
177
178 TSkeleton* pSkeleton = m_pAModel->GetSkeleton();
179 ANamedAnimationSetRef pAnimationSet = TNULL;
180
181 if ( a_pProperties )
182 {
183 // Get anim object name
184 TPString8 strName;
185 a_pProperties->GetOptionalPropertyValue( strName, TPS8( Name ) );
186
187 // Check if this animation set is already created
188 pAnimationSet = FindAnimationSet( strName ).Get();
189 }
190
191 if ( !pAnimationSet.Get() )
192 {
193 // Create new animation set
194 pAnimationSet = new ( AMemory::GetMemBlock( AMemory::POOL_Misc ) ) ANamedAnimationSet();
195 m_vecAnimationSets.PushBack( pAnimationSet );
196 }
197
198 TVALIDPTR( pAnimationSet );
199 TVALIDPTR( pSkeleton );
200
201 if ( a_pProperties )
202 return pAnimationSet->CreateFromProperties( a_pProperties, pSkeleton );
203
204 return TTRUE;
205}
206
207TPSTRING8_DECLARE( Type );
208
209// $Barnyard: FUNCTION 0057eda0
210TBOOL AAnimatableObjectType::SetAnimController( const PBProperties* a_pProperties )
211{
212 TVALIDPTR( a_pProperties );
213
214 // Get controller type name
215 TPString8 strType;
216 a_pProperties->GetOptionalPropertyValue( strType, TPS8( Type ) );
217
218 TClass* pTypeClass = TClass::Find( strType, &TGetClass( AAnimControllerType ) );
219
220 TASSERT( TNULL != pTypeClass );
221 if ( pTypeClass == TNULL ) return TFALSE;
222
223 // Create the actual controller type
224 AAnimControllerType* pControllerType = TSTATICCAST( AAnimControllerType, pTypeClass->CreateObject() );
225 TVALIDPTR( pControllerType );
226
227 m_llAnimControllerTypes.PushBack( pControllerType );
228
229 return pControllerType->Create( a_pProperties );
230}
231
232TBOOL AAnimatableObjectType::SetSkins( const PBProperties* a_pProperties )
233{
234 TVALIDPTR( a_pProperties );
235 TASSERT( !"Not implemented" );
236
237 return TTRUE;
238}
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#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 TGetClass(CLASS)
Definition TObject.h:13
#define TPSTRING8_DECLARE(STR)
Definition TPString8.h:15
#define TPS8(STR)
Definition TPString8.h:16
#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
Toshi::TRef< ANamedAnimationSet > ANamedAnimationSetRef
TBOOL GetOptionalPropertyValue(T &a_rOutValue, const TCHAR *a_szName) const
static TINT Compare(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:52
class TObject * CreateObject() const
Definition TClass.cpp:116
static TClass * Find(const TCHAR *name, TClass *parent=TNULL)
Definition TClass.cpp:110
TFORCEINLINE const TCHAR * GetString() const
Definition TPString8.h:167
TString8 & Format(const TCHAR *a_pcFormat,...)
Definition TString8.cpp:176
const TCHAR * GetString(TINT a_iIndex=0) const
Definition TString8.cpp:286
const Toshi::TPString8 & GetName() const
ANamedAnimationSetRef GetDefaultAnimationSet() const
ANamedAnimationSetRef FindAnimationSet(const Toshi::TPString8 &a_rcName) const
static constexpr TSIZE MAX_ANIMATION_SETS
ANamedAnimationSetRef GetAnimationSet(TINT a_iIndex) const
virtual TBOOL Create(const Toshi::TPString8 &a_rcName)
virtual TBOOL CreateFromProperties(const PBProperties *a_pProperties, const Toshi::TPString8 &a_rcName)
virtual void OnAnimatableObjectCreated(AAnimatableObject *a_pAnimatableObject)
virtual TBOOL Create(const PBProperties *a_pProperties)
Toshi::TSkeleton * GetSkeleton() const
Definition AModel.h:99
void LoadModel(const Toshi::TPString8 &a_rcName, Toshi::TTRB *a_pTRB)
AModel * GetModel(const Toshi::TPString8 &a_rcName)
@ POOL_Misc
Definition AMemory.h:35
static Toshi::TMemory::MemBlock * GetMemBlock(POOL a_ePool)
Definition AMemory.cpp:38