@@ -22,6 +22,7 @@ CClientIFP::CClientIFP ( class CClientManager* pManager, ElementID ID ) : CClien
22
22
m_pManager = pManager;
23
23
SetTypeName ( " IFP" );
24
24
m_bisIFPLoaded = false ;
25
+ m_pIFPAnimations = nullptr ;
25
26
}
26
27
27
28
CClientIFP::~CClientIFP ( void )
@@ -34,60 +35,45 @@ bool CClientIFP::LoadIFP ( const char* szFilePath, SString strBlockName )
34
35
printf (" \n CClientIFP::LoadIFP: szFilePath %s\n szBlockName: %s\n\n " , szFilePath, strBlockName.c_str ());
35
36
36
37
m_strBlockName = strBlockName;
38
+ m_pIFPAnimations = new SIFPAnimations;
39
+ m_pVecAnimations = &m_pIFPAnimations->vecAnimations ;
37
40
38
- if (LoadIFPFile ( szFilePath) )
41
+ if ( LoadIFPFile ( szFilePath ) )
39
42
{
40
43
m_bisIFPLoaded = true ;
41
- return true ;
42
44
}
43
- return false ;
45
+ else
46
+ {
47
+ delete m_pIFPAnimations;
48
+ }
49
+ return m_bisIFPLoaded;
44
50
}
45
51
46
-
47
52
void CClientIFP::UnloadIFP ( void )
48
53
{
49
54
if ( m_bisIFPLoaded )
50
55
{
51
56
printf (" CClientIFP::UnloadIFP ( ) called!\n " );
52
57
53
58
m_bisIFPLoaded = false ;
54
-
55
- // first remove IFP from map, so we can indicate that it does not exist
59
+
60
+ // Remove IFP from map, so we can indicate that it does not exist
56
61
g_pClientGame->RemoveIFPPointerFromMap ( m_strBlockName );
57
62
58
- // remove IFP animations from replaced animations of peds/players
59
- g_pClientGame->onClientIFPUnload ( *this );
63
+ // Remove IFP animations from replaced animations of peds/players
64
+ g_pClientGame->OnClientIFPUnload ( *this );
60
65
61
- for ( size_t i = 0 ; i < m_Animations. size (); i++ )
62
- {
63
- IFP_Animation * ifpAnimation = &m_Animations[i] ;
66
+ // When all animations from this IFP block stop playing, and
67
+ // the reference count reaches zero, IFP animations will be unloaded
68
+ m_pIFPAnimations-> bUnloadOnZeroReferences = true ;
64
69
65
- OLD_CAnimBlendHierarchy_RemoveFromUncompressedCache ( (int )&ifpAnimation->Hierarchy );
66
-
67
- for (unsigned short SequenceIndex = 0 ; SequenceIndex < ifpAnimation->Hierarchy .m_nSeqCount ; SequenceIndex++)
68
- {
69
- _CAnimBlendSequence * pSequence = (_CAnimBlendSequence*)((BYTE*)ifpAnimation->Hierarchy .m_pSequences + (sizeof (_CAnimBlendSequence) * SequenceIndex));
70
+ // unload IFP animations, if reference count is zero
71
+ if ( m_pIFPAnimations->iReferences == 0 )
72
+ {
73
+ g_pClientGame->UnloadIFPAnimations ( m_pIFPAnimations );
70
74
71
- if ( !( (pSequence->m_nFlags >> 3 ) & 1 ) ) // If ( !OneBigChunkForAllSequences )
72
- {
73
- OLD_CMemoryMgr_Free ( pSequence->m_pFrames ); // *(void **)(pThis + 8)); //pSequence->m_pFrames );
74
- }
75
- else
76
- {
77
- if ( SequenceIndex == 0 )
78
- {
79
- // All frames of all sequences are allocated on one memory block, so free that one
80
- // and break the loop
81
- OLD_CMemoryMgr_Free ( pSequence->m_pFrames );
82
- break ;
83
- }
84
- }
85
-
86
- }
87
- delete ifpAnimation->pSequencesMemory ;
75
+ delete m_pIFPAnimations;
88
76
}
89
-
90
- printf (" IFP unloaded sucessfully with block name '%s'\n " , m_strBlockName.c_str ());
91
77
}
92
78
}
93
79
@@ -138,10 +124,10 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
138
124
{
139
125
readBuffer < IFPHeaderV2 > ( &HeaderV2 );
140
126
141
- m_Animations. resize ( HeaderV2.TotalAnimations );
142
- for (size_t i = 0 ; i < m_Animations. size (); i++)
127
+ m_pVecAnimations-> resize ( HeaderV2.TotalAnimations );
128
+ for (size_t i = 0 ; i < m_pVecAnimations-> size (); i++)
143
129
{
144
- IFP_Animation & ifpAnimation = m_Animations[i] ;
130
+ IFP_Animation & ifpAnimation = m_pVecAnimations-> at ( i ) ;
145
131
146
132
_CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy ;
147
133
@@ -349,10 +335,10 @@ void CClientIFP::ReadIFPVersion1 ( )
349
335
350
336
// ofs << "Total Animations: " << Info.Entries << std::endl;
351
337
352
- m_Animations. resize ( Info.Entries );
353
- for (size_t i = 0 ; i < m_Animations. size (); i++)
338
+ m_pVecAnimations-> resize ( Info.Entries );
339
+ for (size_t i = 0 ; i < m_pVecAnimations-> size (); i++)
354
340
{
355
- IFP_Animation & ifpAnimation = m_Animations[i] ;
341
+ IFP_Animation & ifpAnimation = m_pVecAnimations-> at ( i ) ;
356
342
357
343
_CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy ;
358
344
@@ -1177,7 +1163,7 @@ CAnimBlendHierarchySAInterface * CClientIFP::GetAnimationHierarchy ( const SStri
1177
1163
{
1178
1164
if ( m_bisIFPLoaded )
1179
1165
{
1180
- for (auto it = m_Animations. begin (); it != m_Animations. end (); ++it)
1166
+ for (auto it = m_pVecAnimations-> begin (); it != m_pVecAnimations-> end (); ++it)
1181
1167
{
1182
1168
if (strAnimationName.ToLower () == it->Name .ToLower ())
1183
1169
{
0 commit comments