Skip to content

Commit d64f8b3

Browse files
committed
[BAD DESIGN] Implemented temporary UnloadIFP function for unloading IFPs while testing. Also, using malloc instead of OLD_CMemoryMgr_Malloc.
1 parent 1983a2a commit d64f8b3

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

Client/mods/deathmatch/logic/CClientIFP.cpp

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@ bool CClientIFP::LoadIFP ( const char* szFilePath, SString strBlockName )
3737
//return false;
3838
}
3939

40-
40+
// Temporary method to avoid memory leaks, we'll need to rewrite the entire thing ;)
4141
void CClientIFP::UnloadIFP ( void )
4242
{
43-
//printf ("CClientIFP::UnloadIFP ( ) called!\n");
43+
printf ("CClientIFP::UnloadIFP ( ) called!\n");
44+
45+
for ( size_t i = 0; i < m_Animations.size(); i++ )
46+
{
47+
IFP_Animation * ifpAnimation = &m_Animations[i];
48+
for (unsigned short SequenceIndex = 0; i < ifpAnimation->Hierarchy.m_nSeqCount; i++)
49+
{
50+
_CAnimBlendSequence * pSequence = (_CAnimBlendSequence*)((BYTE*)(ifpAnimation->Hierarchy.m_pSequences) + (sizeof(_CAnimBlendSequence) * SequenceIndex));
51+
free ( pSequence->m_pFrames );
52+
}
53+
delete ifpAnimation->pSequencesMemory;
54+
}
55+
56+
printf ("IFP unloaded sucessfully\n");
4457
}
4558

4659
bool CClientIFP::LoadIFPFile(const char * FilePath)
@@ -67,7 +80,7 @@ bool CClientIFP::LoadIFPFile(const char * FilePath)
6780
{
6881
isVersion1 = true;
6982

70-
//ReadIFPVersion1 ( );
83+
ReadIFPVersion1 ( );
7184
}
7285

7386
// We are unloading the data because we don't need to read it anymore.
@@ -95,12 +108,12 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
95108
{
96109
readBuffer < IFPHeaderV2 > ( &HeaderV2 );
97110

98-
AnimationHierarchies.resize(HeaderV2.TotalAnimations);
99-
100-
101-
for (size_t i = 0; i < AnimationHierarchies.size(); i++)
111+
m_Animations.resize ( HeaderV2.TotalAnimations );
112+
for (size_t i = 0; i < m_Animations.size(); i++)
102113
{
103-
_CAnimBlendHierarchy * pAnimHierarchy = &AnimationHierarchies[i];
114+
IFP_Animation & ifpAnimation = m_Animations[i];
115+
116+
_CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy;
104117

105118
_CAnimBlendHierarchy_Constructor(pAnimHierarchy);
106119

@@ -121,7 +134,7 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
121134

122135
pAnimHierarchy->m_bRunningCompressed = AnimationNode.isCompressed & 1;
123136

124-
pKeyFrames = (unsigned char*)OLD_CMemoryMgr_Malloc(AnimationNode.FrameSize);
137+
pKeyFrames = (unsigned char*)malloc(AnimationNode.FrameSize);
125138
}
126139

127140
OLD__CAnimBlendHierarchy_SetName(pAnimHierarchy, AnimationNode.Name);
@@ -133,6 +146,9 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
133146
const unsigned short TotalSequences = IFP_TOTAL_SEQUENCES + pAnimHierarchy->m_nSeqCount;
134147
char * pNewSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
135148

149+
// Okay, we have assigned the memory. We can free it when we want to
150+
ifpAnimation.pSequencesMemory = pNewSequencesMemory;
151+
136152
pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( pNewSequencesMemory + 4 );
137153

138154
std::map < std::string, _CAnimBlendSequence > MapOfSequences;
@@ -292,13 +308,13 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
292308
Call__CAnimBlendHierarchy_RemoveQuaternionFlips(pAnimHierarchy);
293309

294310
Call__CAnimBlendHierarchy_CalcTotalTime(pAnimHierarchy);
295-
}
311+
}
296312

297313
}
298314
}
299315

300316
void CClientIFP::ReadIFPVersion1 ( )
301-
{
317+
{
302318
uint32_t OffsetEOF;
303319

304320
readBuffer < uint32_t > ( &OffsetEOF );
@@ -312,12 +328,12 @@ void CClientIFP::ReadIFPVersion1 ( )
312328

313329
//ofs << "Total Animations: " << Info.Entries << std::endl;
314330

315-
AnimationHierarchies.resize ( Info.Entries );
316-
317-
318-
for (size_t i = 0; i < AnimationHierarchies.size(); i++)
331+
m_Animations.resize ( Info.Entries );
332+
for (size_t i = 0; i < m_Animations.size(); i++)
319333
{
320-
_CAnimBlendHierarchy * pAnimHierarchy = &AnimationHierarchies[i];
334+
IFP_Animation & ifpAnimation = m_Animations[i];
335+
336+
_CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy;
321337

322338
_CAnimBlendHierarchy_Constructor(pAnimHierarchy);
323339

@@ -356,6 +372,9 @@ void CClientIFP::ReadIFPVersion1 ( )
356372
const unsigned short TotalSequences = IFP_TOTAL_SEQUENCES + pAnimHierarchy->m_nSeqCount;
357373
char * pNewSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
358374

375+
// Okay, we have assigned the memory. We can free it when we want to
376+
ifpAnimation.pSequencesMemory = pNewSequencesMemory;
377+
359378
pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( pNewSequencesMemory + 4 );
360379

361380
std::map < std::string, _CAnimBlendSequence > MapOfSequences;
@@ -438,7 +457,7 @@ void CClientIFP::ReadIFPVersion1 ( )
438457

439458
IFP_FrameType FrameType = getFrameTypeFromFourCC ( Kfrm.Base.FourCC );
440459
size_t CompressedFrameSize = GetSizeOfCompressedFrame ( FrameType );
441-
BYTE * pKeyFrames = ( BYTE * ) OLD_CMemoryMgr_Malloc ( CompressedFrameSize * Anim.Frames );
460+
BYTE * pKeyFrames = ( BYTE * ) malloc ( CompressedFrameSize * Anim.Frames );
442461

443462
bool bIsRoot = FrameType != IFP_FrameType::KR00;
444463
if (bUnknownSequence)
@@ -454,17 +473,17 @@ void CClientIFP::ReadIFPVersion1 ( )
454473
{
455474
//ofs << " | FrameType: KRTS" << std::endl;
456475

457-
ReadKrtsFramesAsCompressed ( pKeyFrames, Anim.Frames );
476+
ReadKrtsFramesAsCompressed ( pKeyFrames, Anim.Frames );
458477
}
459478
else if (FrameType == IFP_FrameType::KRT0)
460479
{
461480
//ofs << " | FrameType: KRT0" << std::endl;
462-
ReadKrt0FramesAsCompressed ( pKeyFrames, Anim.Frames );
481+
ReadKrt0FramesAsCompressed ( pKeyFrames, Anim.Frames );
463482
}
464483
else if (FrameType == IFP_FrameType::KR00)
465484
{
466485
//ofs << " | FrameType: KR00" << std::endl;
467-
ReadKr00FramesAsCompressed ( pKeyFrames, Anim.Frames, BoneID );
486+
ReadKr00FramesAsCompressed ( pKeyFrames, Anim.Frames, BoneID );
468487
}
469488

470489
if (!bUnknownSequence)
@@ -473,7 +492,7 @@ void CClientIFP::ReadIFPVersion1 ( )
473492
}
474493

475494
}
476-
495+
477496
std::map < std::string, _CAnimBlendSequence >::iterator it;
478497
for (size_t SequenceIndex = 0; SequenceIndex < IFP_TOTAL_SEQUENCES; SequenceIndex++)
479498
{
@@ -507,8 +526,8 @@ void CClientIFP::ReadIFPVersion1 ( )
507526
Call__CAnimBlendHierarchy_RemoveQuaternionFlips(pAnimHierarchy);
508527

509528
Call__CAnimBlendHierarchy_CalcTotalTime(pAnimHierarchy);
510-
}
511-
}
529+
}
530+
}
512531
}
513532

514533

@@ -655,7 +674,7 @@ void CClientIFP::insertAnimDummySequence ( bool anp3, _CAnimBlendHierarchy * pAn
655674

656675

657676

658-
pKeyFrames = (unsigned char*)OLD_CMemoryMgr_Malloc(FramesDataSizeInBytes);
677+
pKeyFrames = (unsigned char*)malloc(FramesDataSizeInBytes);
659678

660679
OLD__CAnimBlendSequence_SetNumFrames(pSequence, TotalFrames, bIsRoot, bIsCompressed, pKeyFrames);
661680

0 commit comments

Comments
 (0)