@@ -22,6 +22,7 @@ CClientIFP::CClientIFP ( class CClientManager* pManager, ElementID ID ) : CClien
2222 m_pManager = pManager;
2323 SetTypeName ( " IFP" );
2424 m_bisIFPLoaded = false ;
25+ m_pIFPAnimations = nullptr ;
2526}
2627
2728CClientIFP::~CClientIFP ( void )
@@ -34,60 +35,45 @@ bool CClientIFP::LoadIFP ( const char* szFilePath, SString strBlockName )
3435 printf (" \n CClientIFP::LoadIFP: szFilePath %s\n szBlockName: %s\n\n " , szFilePath, strBlockName.c_str ());
3536
3637 m_strBlockName = strBlockName;
38+ m_pIFPAnimations = new SIFPAnimations;
39+ m_pVecAnimations = &m_pIFPAnimations->vecAnimations ;
3740
38- if (LoadIFPFile ( szFilePath) )
41+ if ( LoadIFPFile ( szFilePath ) )
3942 {
4043 m_bisIFPLoaded = true ;
41- return true ;
4244 }
43- return false ;
45+ else
46+ {
47+ delete m_pIFPAnimations;
48+ }
49+ return m_bisIFPLoaded;
4450}
4551
46-
4752void CClientIFP::UnloadIFP ( void )
4853{
4954 if ( m_bisIFPLoaded )
5055 {
5156 printf (" CClientIFP::UnloadIFP ( ) called!\n " );
5257
5358 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
5661 g_pClientGame->RemoveIFPPointerFromMap ( m_strBlockName );
5762
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 );
6065
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 ;
6469
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 );
7074
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;
8876 }
89-
90- printf (" IFP unloaded sucessfully with block name '%s'\n " , m_strBlockName.c_str ());
9177 }
9278}
9379
@@ -138,10 +124,10 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
138124{
139125 readBuffer < IFPHeaderV2 > ( &HeaderV2 );
140126
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++)
143129 {
144- IFP_Animation & ifpAnimation = m_Animations[i] ;
130+ IFP_Animation & ifpAnimation = m_pVecAnimations-> at ( i ) ;
145131
146132 _CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy ;
147133
@@ -349,10 +335,10 @@ void CClientIFP::ReadIFPVersion1 ( )
349335
350336 // ofs << "Total Animations: " << Info.Entries << std::endl;
351337
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++)
354340 {
355- IFP_Animation & ifpAnimation = m_Animations[i] ;
341+ IFP_Animation & ifpAnimation = m_pVecAnimations-> at ( i ) ;
356342
357343 _CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy ;
358344
@@ -1177,7 +1163,7 @@ CAnimBlendHierarchySAInterface * CClientIFP::GetAnimationHierarchy ( const SStri
11771163{
11781164 if ( m_bisIFPLoaded )
11791165 {
1180- for (auto it = m_Animations. begin (); it != m_Animations. end (); ++it)
1166+ for (auto it = m_pVecAnimations-> begin (); it != m_pVecAnimations-> end (); ++it)
11811167 {
11821168 if (strAnimationName.ToLower () == it->Name .ToLower ())
11831169 {
0 commit comments