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

#include <AModelRepos.h>

Inheritance diagram for AModelRepos:

Public Types

using ModelsMap = Toshi::T2Map<Toshi::TPString8, AModel*, Toshi::TPString8::Comparator>
 

Public Member Functions

 TDECLARE_CLASS (AModelRepos, Toshi::TObject)
 
 AModelRepos ()
 
 ~AModelRepos ()
 
AModelGetModel (const Toshi::TPString8 &a_rcName)
 
AModelGetUnusedModel (const Toshi::TPString8 &a_rName)
 
AModelInstanceInstantiateModel (AModel *a_pModel)
 
AModelInstanceInstantiateNewModel (const Toshi::TPString8 &a_rName, Toshi::TTRB *a_pTRB)
 
void DestroyModelInstance (AModelInstance *a_pInstance)
 
void LoadModel (const Toshi::TPString8 &a_rcName, Toshi::TTRB *a_pTRB)
 
void UnloadModel (const Toshi::TPString8 &a_rcName, TBOOL a_bDestroy)
 
void Update (TFLOAT a_fDeltaTime)
 
void RenderModels (TUINT a_uiMask)
 
void UnloadAllModels ()
 
void UnloadUnusedModels ()
 

Static Public Attributes

static constexpr TSIZE MAX_UNUSED_MODELS_NUM = 9
 

Protected Attributes

Toshi::T2DList< AModelm_UnusedModels
 
ModelsMap m_UsedModels
 
ModelsMap m_AllModels
 

Detailed Description

Definition at line 7 of file AModelRepos.h.

Member Typedef Documentation

◆ ModelsMap

using AModelRepos::ModelsMap = Toshi::T2Map<Toshi::TPString8, AModel*, Toshi::TPString8::Comparator>

Definition at line 13 of file AModelRepos.h.

Constructor & Destructor Documentation

◆ AModelRepos()

AModelRepos::AModelRepos ( )

Definition at line 16 of file AModelRepos.cpp.

18{
19}
ModelsMap m_AllModels
Definition AModelRepos.h:46
ModelsMap m_UsedModels
Definition AModelRepos.h:45
@ POOL_Misc
Definition AMemory.h:35
static Toshi::T2Allocator * GetAllocator(POOL a_ePool)
Definition AMemory.cpp:31

◆ ~AModelRepos()

AModelRepos::~AModelRepos ( )

Definition at line 23 of file AModelRepos.cpp.

24{
25 TIMPLEMENT();
27 MarkAllModelsUnused();
29}
#define TIMPLEMENT()
Definition Defines.h:136
void UnloadUnusedModels()
void UnloadAllModels()

Member Function Documentation

◆ DestroyModelInstance()

void AModelRepos::DestroyModelInstance ( AModelInstance * a_pInstance)

Definition at line 214 of file AModelRepos.cpp.

215{
216 {
217 // Remove from the list of all models
218 auto it = m_AllModels.FindByValue( a_pInstance->GetModel() );
219
220 if ( m_AllModels.IsValid( it ) )
221 {
222 AModel* pModel = it->GetSecond();
223 pModel->DestroyInstance( a_pInstance );
224 }
225 }
226
227 {
228 // Remove from the list of used models
229 auto it = m_UsedModels.FindByValue( a_pInstance->GetModel() );
230
231 if ( m_UsedModels.IsValid( it ) )
232 {
233 AModel* pModel = it->GetSecond();
234 pModel->DestroyInstance( a_pInstance );
235
236 if ( pModel->GetNumInstances() < 1 )
237 {
238 MarkModelUnused( pModel );
239 }
240 }
241 }
242}
AModel * GetModel() const
Definition AModel.h:50
void DestroyInstance(AModelInstance *a_pInstance)
Definition AModel.cpp:150
TSIZE GetNumInstances() const
Definition AModel.cpp:155

◆ GetModel()

AModel * AModelRepos::GetModel ( const Toshi::TPString8 & a_rcName)

Definition at line 44 of file AModelRepos.cpp.

45{
46 {
47 // Look in the list of all models
48 auto pRes = m_AllModels.Find( a_rName );
49 if ( m_AllModels.IsValid( pRes ) ) return pRes->GetSecond();
50 }
51
52 {
53 // Look in the list used models
54 auto pRes = m_UsedModels.Find( a_rName );
55 if ( m_UsedModels.IsValid( pRes ) ) return pRes->GetSecond();
56 }
57
58 return TNULL;
59}
#define TNULL
Definition Typedefs.h:23

◆ GetUnusedModel()

AModel * AModelRepos::GetUnusedModel ( const Toshi::TPString8 & a_rName)

Definition at line 62 of file AModelRepos.cpp.

63{
65 {
66 if ( it->GetName() == a_rName )
67 {
68 return it;
69 }
70 }
71
72 return TNULL;
73}
#define T2_FOREACH(vecName, iteratorName)
Definition T2Iterator.h:4
Toshi::T2DList< AModel > m_UnusedModels
Definition AModelRepos.h:44

◆ InstantiateModel()

AModelInstance * AModelRepos::InstantiateModel ( AModel * a_pModel)

Definition at line 177 of file AModelRepos.cpp.

178{
179 TVALIDPTR( a_pModel );
180 return a_pModel->CreateInstance().Get();
181}
#define TVALIDPTR(PTR)
Definition Defines.h:139
AModelInstanceRef CreateInstance()
Definition AModel.cpp:134

◆ InstantiateNewModel()

AModelInstance * AModelRepos::InstantiateNewModel ( const Toshi::TPString8 & a_rName,
Toshi::TTRB * a_pTRB )

Definition at line 184 of file AModelRepos.cpp.

185{
186 AModel* pModel = TNULL;
187 ModelsMap::Iterator pModels2Res = m_AllModels.Find( a_rName );
188
189 if ( pModels2Res != m_AllModels.End() )
190 {
191 pModel = pModels2Res->GetSecond();
192 }
193 else
194 {
195 ModelsMap::Iterator pUsedModelsRes = m_UsedModels.Find( a_rName );
196
197 if ( m_UsedModels.IsValid( pUsedModelsRes ) )
198 {
199 pModel = pUsedModelsRes->GetSecond();
200 }
201 }
202
203 if ( !pModel )
204 {
205 pModel = AllocateAModel( a_rName, a_pTRB );
206 m_UsedModels.Insert( a_rName, pModel );
207 }
208
209 TVALIDPTR( pModel );
210 return InstantiateModel( pModel );
211}
AModelInstance * InstantiateModel(AModel *a_pModel)

◆ LoadModel()

void AModelRepos::LoadModel ( const Toshi::TPString8 & a_rcName,
Toshi::TTRB * a_pTRB )

Definition at line 245 of file AModelRepos.cpp.

246{
247 if ( m_AllModels.Find( a_rName ) == m_AllModels.End() )
248 {
249 AModel* pModel = TNULL;
250 auto pUsedModelsRes = m_UsedModels.Find( a_rName );
251
252 if ( !m_UsedModels.IsValid( pUsedModelsRes ) )
253 {
254 pModel = GetUnusedModel( a_rName );
255
256 if ( pModel )
257 {
258 pModel->Remove();
259 }
260 else
261 {
262 pModel = AllocateAModel( a_rName, a_pTRB );
263 }
264 }
265 else
266 {
267 pModel = pUsedModelsRes->GetSecond();
268 m_UsedModels.Remove( pUsedModelsRes );
269 }
270
271 TVALIDPTR( pModel );
272 m_AllModels.Insert( a_rName, pModel );
273 }
274}
AModel * GetUnusedModel(const Toshi::TPString8 &a_rName)

◆ RenderModels()

void AModelRepos::RenderModels ( TUINT a_uiMask)

Definition at line 90 of file AModelRepos.cpp.

91{
92 // Render used models
94 {
95 if ( HASANYFLAG( a_uiMask, 1 ) )
96 it->GetSecond()->Render( 1 );
97
98 if ( HASANYFLAG( a_uiMask, 2 ) )
99 it->GetSecond()->Render( 0 );
100 }
101
102 // Render other (all?) models
104 {
105 if ( HASANYFLAG( a_uiMask, 1 ) )
106 it->GetSecond()->Render( 1 );
107
108 if ( HASANYFLAG( a_uiMask, 2 ) )
109 it->GetSecond()->Render( 0 );
110 }
111}
#define HASANYFLAG(STATE, FLAG)
Definition Defines.h:5

◆ TDECLARE_CLASS()

AModelRepos::TDECLARE_CLASS ( AModelRepos ,
Toshi::TObject  )

◆ UnloadAllModels()

void AModelRepos::UnloadAllModels ( )

Definition at line 158 of file AModelRepos.cpp.

159{
160 for ( ModelsMap::Iterator it = m_AllModels.Begin(); it != m_AllModels.End(); )
161 {
162 ModelsMap::Iterator next = it.Next();
163 AModel* pModel = it->GetSecond();
164
165 if ( pModel->GetNumInstances() < 1 )
166 {
167 m_AllModels.Remove( it );
168
169 m_UnusedModels.PushFront( pModel );
170 }
171
172 it = next;
173 }
174}

◆ UnloadModel()

void AModelRepos::UnloadModel ( const Toshi::TPString8 & a_rcName,
TBOOL a_bDestroy )

Definition at line 277 of file AModelRepos.cpp.

278{
279 auto pModelNode = m_AllModels.Find( a_rcName );
280
281 if ( m_AllModels.IsValid( pModelNode ) && pModelNode->GetSecond()->GetNumInstances() == 0 )
282 {
283 AModel* pModel = pModelNode->GetSecond();
284 m_AllModels.Remove( pModelNode );
285
286 if ( a_bDestroy )
287 {
288 if ( pModel->IsLinked() )
289 pModel->Remove();
290
291 delete pModel;
292 }
293 else
294 {
295 m_UnusedModels.PushFront( pModel );
296 }
297 }
298}

◆ UnloadUnusedModels()

void AModelRepos::UnloadUnusedModels ( )

Definition at line 32 of file AModelRepos.cpp.

33{
34 while ( !m_UnusedModels.IsEmpty() )
35 {
36 auto pModel = m_UnusedModels.Head();
37
38 pModel->Remove();
39 delete pModel;
40 }
41}

◆ Update()

void AModelRepos::Update ( TFLOAT a_fDeltaTime)

Definition at line 76 of file AModelRepos.cpp.

77{
79 {
80 it->GetSecond()->Update( a_fDeltaTime );
81 }
82
84 {
85 it->GetSecond()->Update( a_fDeltaTime );
86 }
87}

Member Data Documentation

◆ m_AllModels

ModelsMap AModelRepos::m_AllModels
protected

Definition at line 46 of file AModelRepos.h.

◆ m_UnusedModels

Toshi::T2DList<AModel> AModelRepos::m_UnusedModels
protected

Definition at line 44 of file AModelRepos.h.

◆ m_UsedModels

ModelsMap AModelRepos::m_UsedModels
protected

Definition at line 45 of file AModelRepos.h.

◆ MAX_UNUSED_MODELS_NUM

TSIZE AModelRepos::MAX_UNUSED_MODELS_NUM = 9
staticconstexpr

Definition at line 15 of file AModelRepos.h.


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