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

#include <AAnimatableObjectManager.h>

Inheritance diagram for AAnimatableObjectManager:

Public Types

using ThisClass = AAnimatableObjectManager
 
using BaseClass = Toshi::TTask
 

Public Member Functions

virtual Toshi::TClass * GetClass () override
 
 AAnimatableObjectManager ()
 
 ~AAnimatableObjectManager ()
 
virtual TBOOL OnUpdate (TFLOAT a_fDeltaTime) override
 
AAnimatableObjectCreateAnimatableObject (AAnimatableObjectType *a_pObjectType, void *a_Unk1=nullptr, TUINT a_eFlags=0)
 
void LoadTypesFromLibrary (const TCHAR *a_szLibName)
 
void LoadAnimObjType (const TCHAR *a_szName, const PBProperties *a_pProperties, TBOOL a_bNoBreakpoints)
 
void LoadAnimObjType (const Toshi::TPString8 &a_rcName, const PBProperties *a_pProperties, TBOOL a_bNoBreakpoints)
 
TBOOL LoadAnimSoundBreakpoints (const TCHAR *a_szFilePath)
 
TINT FindNumAnimationSoundBreakpoints (const Toshi::TPString8 &a_rcModelName, ANamedAnimation *a_pAnimation)
 
AAnimatableObjectTypeFindType (const Toshi::TPString8 &a_rcName)
 
void DetachObject (AAnimatableObject *a_pObject, AAnimatableObject *a_pParent)
 
void DestroyType (const Toshi::TPString8 &a_rcName)
 
void DestroyAnimatableObject (AAnimatableObject *a_pAnimatableObject)
 
void DestroyAttachedObjects (AAnimatableObject *a_pAnimatableObject)
 

Static Public Member Functions

static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static __forceinline Toshi::TClass * GetClassStatic ()
 

Static Public Attributes

static constexpr Toshi::TClass * PARENTCLASS = & Toshi::TTask::ms_oClass
 
static Toshi::TClass ms_oClass = Toshi::TClass( "AAnimatableObjectManager", AAnimatableObjectManager::PARENTCLASS, AAnimatableObjectManager::CreateTObject, AAnimatableObjectManager::CreateTObjectInPlace, AAnimatableObjectManager::InitialiseClass, AAnimatableObjectManager::DeinitialiseClass, 0, 1, sizeof( AAnimatableObjectManager ), alignof( AAnimatableObjectManager ) )
 

Detailed Description

Definition at line 16 of file AAnimatableObjectManager.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 21 of file AAnimatableObjectManager.h.

◆ ThisClass

Constructor & Destructor Documentation

◆ AAnimatableObjectManager()

AAnimatableObjectManager::AAnimatableObjectManager ( )

Definition at line 23 of file AAnimatableObjectManager.cpp.

24 : m_pAnimSoundBPsTRB( TNULL )
25 , m_pSoundBreakpoints( TNULL )
26{
27}
#define TNULL
Definition Typedefs.h:23

◆ ~AAnimatableObjectManager()

AAnimatableObjectManager::~AAnimatableObjectManager ( )

Definition at line 31 of file AAnimatableObjectManager.cpp.

32{
33 if ( m_pAnimSoundBPsTRB )
34 {
35 delete m_pAnimSoundBPsTRB;
36 m_pAnimSoundBPsTRB = TNULL;
37 m_pSoundBreakpoints = TNULL;
38 }
39
40 m_llObjectTypes.DeleteAll();
41 m_llAnimatableObjects.DeleteAll();
42}

Member Function Documentation

◆ CreateAnimatableObject()

AAnimatableObject * AAnimatableObjectManager::CreateAnimatableObject ( AAnimatableObjectType * a_pObjectType,
void * a_Unk1 = nullptr,
TUINT a_eFlags = 0 )

Definition at line 45 of file AAnimatableObjectManager.cpp.

46{
47 AAnimatableObject* pObject = new AAnimatableObject();
48
49 m_llAnimatableObjects.PushBack( pObject );
50 pObject->Create( a_pObjectType, a_Unk1, a_eFlags );
51
52 return pObject;
53}
TBOOL Create(AAnimatableObjectType *a_pObjectType, void *a_Unk1, CREATE_FLAGS a_eFlags=CREATE_FLAGS_NONE)

◆ CreateTObject()

Toshi::TObject * AAnimatableObjectManager::CreateTObject ( )
static

Definition at line 15 of file AAnimatableObjectManager.cpp.

◆ CreateTObjectInPlace()

Toshi::TObject * AAnimatableObjectManager::CreateTObjectInPlace ( void * a_pPtr)
static

Definition at line 15 of file AAnimatableObjectManager.cpp.

◆ DeinitialiseClass()

void AAnimatableObjectManager::DeinitialiseClass ( )
static

Definition at line 15 of file AAnimatableObjectManager.cpp.

◆ DestroyAnimatableObject()

void AAnimatableObjectManager::DestroyAnimatableObject ( AAnimatableObject * a_pAnimatableObject)

Definition at line 183 of file AAnimatableObjectManager.cpp.

184{
185 if ( !a_pAnimatableObject )
186 return;
187
188 if ( m_llAnimatableObjects.Exists( a_pAnimatableObject ) )
189 {
190 // Destroy all attached objects
191 DestroyAttachedObjects( a_pAnimatableObject );
192
193 // Detach from a parent
194 if ( a_pAnimatableObject->m_oAttachmentInfo.pParentObject )
195 DetachObject( a_pAnimatableObject, a_pAnimatableObject->m_oAttachmentInfo.pParentObject );
196
197 a_pAnimatableObject->Remove();
198 delete a_pAnimatableObject;
199 }
200}
void DetachObject(AAnimatableObject *a_pObject, AAnimatableObject *a_pParent)
void DestroyAttachedObjects(AAnimatableObject *a_pAnimatableObject)

◆ DestroyAttachedObjects()

void AAnimatableObjectManager::DestroyAttachedObjects ( AAnimatableObject * a_pAnimatableObject)

Definition at line 203 of file AAnimatableObjectManager.cpp.

204{
205 if ( !a_pAnimatableObject )
206 return;
207
208 while ( a_pAnimatableObject->m_llAttachedObjects.IsLinked() )
209 {
210 AAnimatableObject* pAttachedObject = a_pAnimatableObject->m_llAttachedObjects.Begin();
211 DestroyAnimatableObject( pAttachedObject );
212 }
213}
void DestroyAnimatableObject(AAnimatableObject *a_pAnimatableObject)

◆ DestroyType()

void AAnimatableObjectManager::DestroyType ( const Toshi::TPString8 & a_rcName)

Definition at line 169 of file AAnimatableObjectManager.cpp.

170{
171 AAnimatableObjectType* pType = FindType( a_rcName );
172
173 if ( pType )
174 {
175 pType->Remove();
176 delete pType;
177
178 AModelRepos::GetSingleton()->UnloadUnusedModels();
179 }
180}
AAnimatableObjectType * FindType(const Toshi::TPString8 &a_rcName)

◆ DetachObject()

void AAnimatableObjectManager::DetachObject ( AAnimatableObject * a_pObject,
AAnimatableObject * a_pParent )

Definition at line 161 of file AAnimatableObjectManager.cpp.

162{
163 TASSERT( a_pObject->m_oAttachmentInfo.pParentObject == a_pParent );
164 a_pObject->m_oAttachmentInfo.pParentObject = TNULL;
165 a_pParent->m_llAttachedObjects.Erase( a_pObject );
166}
#define TASSERT(X,...)
Definition Defines.h:138

◆ FindNumAnimationSoundBreakpoints()

TINT AAnimatableObjectManager::FindNumAnimationSoundBreakpoints ( const Toshi::TPString8 & a_rcModelName,
ANamedAnimation * a_pAnimation )

Definition at line 239 of file AAnimatableObjectManager.cpp.

240{
241 TVALIDPTR( m_pSoundBreakpoints );
242
243 TINT iCount = 0;
244
245 for ( TUINT i = 0; i < m_pSoundBreakpoints->uiCount; i++ )
246 {
247 if ( !T2String8::CompareNoCase( m_pSoundBreakpoints->pBreakpoints[ i ].pszModelName, a_rcModelName ) &&
248 !T2String8::CompareNoCase( m_pSoundBreakpoints->pBreakpoints[ i ].pszAnimationName, a_pAnimation->GetExportedName() ) )
249 {
250 iCount += 1;
251 }
252 }
253
254 return iCount;
255}
#define TVALIDPTR(PTR)
Definition Defines.h:139
unsigned int TUINT
Definition Typedefs.h:8
int TINT
Definition Typedefs.h:7
static TINT CompareNoCase(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Definition T2String8.cpp:60
const Toshi::TPString8 & GetExportedName() const

◆ FindType()

AAnimatableObjectType * AAnimatableObjectManager::FindType ( const Toshi::TPString8 & a_rcName)

Definition at line 148 of file AAnimatableObjectManager.cpp.

149{
150 T2_FOREACH( m_llObjectTypes, it )
151 {
152 if ( it->GetName() == a_rcName )
153 return it;
154 }
155
156 TERROR( "AAnimatableObjectManager: unable to find animatable type '%s'\n", a_rcName.GetString() );
157 return TNULL;
158}
#define TERROR(...)
Definition Defines.h:153
#define T2_FOREACH(vecName, iteratorName)
Definition T2Iterator.h:4

◆ GetClass()

Toshi::TClass * AAnimatableObjectManager::GetClass ( )
overridevirtual

Definition at line 15 of file AAnimatableObjectManager.cpp.

◆ GetClassStatic()

static __forceinline Toshi::TClass * AAnimatableObjectManager::GetClassStatic ( )
inlinestatic

Definition at line 21 of file AAnimatableObjectManager.h.

◆ InitialiseClass()

void AAnimatableObjectManager::InitialiseClass ( )
static

Definition at line 15 of file AAnimatableObjectManager.cpp.

◆ LoadAnimObjType() [1/2]

void AAnimatableObjectManager::LoadAnimObjType ( const TCHAR * a_szName,
const PBProperties * a_pProperties,
TBOOL a_bNoBreakpoints )

Definition at line 142 of file AAnimatableObjectManager.cpp.

143{
144 LoadAnimObjType( TPString8( a_szName ), a_pProperties, a_bNoBreakpoints );
145}
void LoadAnimObjType(const TCHAR *a_szName, const PBProperties *a_pProperties, TBOOL a_bNoBreakpoints)

◆ LoadAnimObjType() [2/2]

void AAnimatableObjectManager::LoadAnimObjType ( const Toshi::TPString8 & a_rcName,
const PBProperties * a_pProperties,
TBOOL a_bNoBreakpoints )

◆ LoadAnimSoundBreakpoints()

TBOOL AAnimatableObjectManager::LoadAnimSoundBreakpoints ( const TCHAR * a_szFilePath)

Definition at line 216 of file AAnimatableObjectManager.cpp.

217{
218 TASSERT( m_pAnimSoundBPsTRB == TNULL );
219
220 if ( a_szFilePath )
221 {
222 m_pAnimSoundBPsTRB = new TTRB();
223
224 if ( m_pAnimSoundBPsTRB->Load( a_szFilePath ) == TTRB::ERROR_OK )
225 {
226 m_pSoundBreakpoints = m_pAnimSoundBPsTRB->CastSymbol<ASoundBreakpointsTable>( "Main" );
227 TVALIDPTR( m_pSoundBreakpoints );
228 }
229 else
230 {
231 TASSERT( !"Unable to load info about sound breakpoints" );
232 }
233 }
234
235 return TTRUE;
236}
#define TTRUE
Definition Typedefs.h:25
@ ERROR_OK
Definition TTRB.h:258

◆ LoadTypesFromLibrary()

void AAnimatableObjectManager::LoadTypesFromLibrary ( const TCHAR * a_szLibName)

Definition at line 56 of file AAnimatableObjectManager.cpp.

57{
58 TString8 strLibPath;
59 strLibPath.Format( "%slibs\\%s.trb", MODELTYPES_DIR, a_szLibName );
60
61 TTRB oTRB;
62 TUINT8 eLoadRes = oTRB.Load( strLibPath );
63 TASSERT( eLoadRes == TTRB::ERROR_OK );
64
65 if ( eLoadRes == TTRB::ERROR_OK )
66 {
67 const PBProperties* pProperties = PBProperties::LoadFromTRB( oTRB );
68 oTRB.DeleteSymbolTable();
69
70 // Skip file if the first type's name is starting with _ (why?)
71 if ( pProperties->Begin()->GetName().GetString()[ 0 ] != '_' )
72 {
73 TINT iLoadScreenUpdateCounter = 0;
74
75 T2_FOREACH( ( *pProperties ), it )
76 {
77 LoadAnimObjType( it->GetName().GetString(), it->GetValue()->GetProperties(), TFALSE );
78
79 // Update load screen only each N type
80 if ( ++iLoadScreenUpdateCounter > 5 )
81 {
82 iLoadScreenUpdateCounter = 0;
84 }
85 }
86 }
87
88 oTRB.Close();
89 }
90
92}
uint8_t TUINT8
Definition Typedefs.h:17
#define TFALSE
Definition Typedefs.h:24
ALoadScreen g_oLoadScreen
void DeleteSymbolTable()
Definition TTRB.cpp:319
ERROR Load(const TCHAR *a_szFilePath, TUINT32 a_uiUnknown=0)
Definition TTRB.cpp:38
void Close()
Definition TTRB.cpp:289
const TCHAR * GetString() const
PBProperty * Begin()
PBPropertyName & GetName()
TString8 & Format(const TCHAR *a_pcFormat,...)
Definition TString8.cpp:176
void Update(TFLOAT a_fDeltaTime=1.0f, TBOOL a_bRender=true)

◆ OnUpdate()

TBOOL AAnimatableObjectManager::OnUpdate ( TFLOAT a_fDeltaTime)
overridevirtual

Definition at line 258 of file AAnimatableObjectManager.cpp.

259{
260 T2_FOREACH( m_llAnimatableObjects, it )
261 {
262 // Find out whether the animation of this object needs to be updated or not
263 TBOOL bUpdateAnim = it->IsAnimated();
264
265 if ( bUpdateAnim )
266 {
267 AModelInstanceRef modelInstance = it->GetModelInstance();
268
269 // Also, don't update animations when skeleton is not updating and no animations are queued
270 if ( !modelInstance->IsUpdatingSkeleton() && it->GetQueuedAnimations().Size() <= 0 )
271 bUpdateAnim = TFALSE;
272 }
273
274 if ( bUpdateAnim )
275 it->Update( a_fDeltaTime );
276 }
277
278 return TTRUE;
279}
bool TBOOL
Definition Typedefs.h:6
Toshi::TRef< AModelInstance > AModelInstanceRef
Definition AModel.h:78

Member Data Documentation

◆ ms_oClass

◆ PARENTCLASS

Toshi::TClass* AAnimatableObjectManager::PARENTCLASS = & Toshi::TTask::ms_oClass
staticconstexpr

Definition at line 21 of file AAnimatableObjectManager.h.


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