Skip to content

Commit 43f90fe

Browse files
committed
Code quality improvements
Replaced uint32_t, int32_t, and int16_t with std::* from <cstdint> - Suggested by Necktrox Used std::find_if in CClientIFP::GetAnimationHierarchy & improved iterator loops by using for (auto& Animation : m_pIFPAnimations->vecAnimations) in CClientIFP::ReadIFPVersion2 and CClientIFP::ReadIFPVersion1 - earlier suggested by sbx320 Replaced std::string with SString. Changed CIFPAnimations::SIFPAnimation::pSequencesMemory type to BYTE*. Removed casting where this member of struct was accessed. Used const where applicable in CClientIFP.cpp. Renamed ConvertStringToMapKey to ConvertStringToKey. Applied source formatting again
1 parent 6ec9bcc commit 43f90fe

File tree

9 files changed

+282
-290
lines changed

9 files changed

+282
-290
lines changed

Client/mods/deathmatch/StdInc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
#include <CMapEventManager.h>
9696
#include <CModelNames.h>
9797
#include <CIFPEngine.h>
98+
#include <CFileReader.h>
99+
#include <CIFPAnimations.h>
98100
#include <CScriptFile.h>
99101
#include <CWeaponNames.h>
100102
#include <CVehicleNames.h>

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,7 +6820,7 @@ void CClientGame::RemovePedPointerFromSet(CClientPed* pPed)
68206820
CClientPed* CClientGame::GetClientPedByClump(const RpClump& Clump)
68216821
{
68226822
std::lock_guard<std::mutex> mutexGuardedLock(m_MutexOfPedPointersSet);
6823-
for (auto &pPed : m_setOfPedPointers)
6823+
for (auto& pPed : m_setOfPedPointers)
68246824
{
68256825
CEntity* pEntity = pPed->GetGameEntity();
68266826
if (pEntity != nullptr)
@@ -6842,7 +6842,7 @@ void CClientGame::OnClientIFPUnload(const std::shared_ptr<CClientIFP>& IFP)
68426842
{
68436843
std::lock_guard<std::mutex> mutexGuardedLock(m_MutexOfPedPointersSet);
68446844
IFP->MarkAsUnloading();
6845-
for (auto &pPed : m_setOfPedPointers)
6845+
for (auto& pPed : m_setOfPedPointers)
68466846
{
68476847
// Remove IFP animations from replaced animations of peds/players
68486848
pPed->RestoreAnimations(IFP);

Client/mods/deathmatch/logic/CClientIFP.cpp

Lines changed: 214 additions & 219 deletions
Large diffs are not rendered by default.

Client/mods/deathmatch/logic/CClientIFP.h

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class CClientIFP : public CClientEntity, CFileReader
1212

1313
struct SBase
1414
{
15-
char FourCC[4];
16-
uint32_t Size;
15+
char FourCC[4];
16+
std::uint32_t Size;
1717
};
1818

1919
struct SInfo
2020
{
21-
SBase Base;
22-
int32_t Entries;
23-
char Name[24];
21+
SBase Base;
22+
std::int32_t Entries;
23+
char Name[24];
2424
};
2525

2626
struct SAnpk
@@ -47,16 +47,16 @@ class CClientIFP : public CClientEntity, CFileReader
4747

4848
struct SAnim
4949
{
50-
SBase Base;
51-
char Name[28];
52-
int32_t Frames;
53-
int32_t Unk;
54-
int32_t Next;
55-
int32_t Previous;
50+
SBase Base;
51+
char Name[28];
52+
std::int32_t Frames;
53+
std::int32_t Unk;
54+
std::int32_t Next;
55+
std::int32_t Previous;
5656

5757
// According to https://www.gtamodding.com/wiki/IFP, Unk2 should not exist, but for some reason, it's there
5858
// I don't know why. Let's just go with the flow and ignore it. The value seems to be always zero.
59-
int32_t Unk2;
59+
std::int32_t Unk2;
6060
};
6161

6262
struct SKfrm
@@ -97,18 +97,18 @@ class CClientIFP : public CClientEntity, CFileReader
9797

9898
struct SCompressedQuaternion
9999
{
100-
int16_t X, Y, Z, W;
100+
std::int16_t X, Y, Z, W;
101101
};
102102

103103
struct SCompressedCVector
104104
{
105-
int16_t X, Y, Z;
105+
std::int16_t X, Y, Z;
106106
};
107107

108108
struct SCompressed_KR00
109109
{
110110
SCompressedQuaternion Rotation;
111-
int16_t Time;
111+
std::int16_t Time;
112112
};
113113

114114
struct SCompressed_KRT0 : SCompressed_KR00
@@ -128,27 +128,25 @@ class CClientIFP : public CClientEntity, CFileReader
128128

129129
struct SIFPHeaderV2
130130
{
131-
int32_t OffsetEOF;
132-
char InternalFileName[24];
133-
int32_t TotalAnimations;
131+
std::int32_t OffsetEOF;
132+
char InternalFileName[24];
133+
std::int32_t TotalAnimations;
134134
};
135135

136136
struct SAnimationHeaderV2
137137
{
138-
char Name[24];
139-
int32_t TotalObjects;
140-
int32_t FrameSize;
141-
int32_t isCompressed; // The value is always 1
138+
char Name[24];
139+
std::int32_t TotalObjects;
140+
std::int32_t FrameSize;
141+
std::int32_t isCompressed; // The value is always 1
142142
};
143143

144144
struct SSequenceHeaderV2
145145
{
146-
// 24 + 4 + 4 + 4 = 36 bytes
147-
148-
char Name[24];
149-
int32_t FrameType;
150-
int32_t TotalFrames;
151-
int32_t BoneID;
146+
char Name[24];
147+
std::int32_t FrameType;
148+
std::int32_t TotalFrames;
149+
std::int32_t BoneID;
152150
};
153151

154152
enum eBoneType
@@ -213,51 +211,52 @@ class CClientIFP : public CClientEntity, CFileReader
213211
void ReadIFPVersion1(void);
214212
void ReadIFPVersion2(bool bAnp3);
215213

216-
WORD ReadSequencesWithDummies(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy);
217-
WORD ReadSequences(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& MapOfSequences);
218-
WORD ReadSequencesVersion1(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& MapOfSequences);
219-
WORD ReadSequencesVersion2(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& MapOfSequences);
220-
int32_t ReadSequenceVersion1(SAnim& Anim);
221-
void ReadSequenceVersion2(SSequenceHeaderV2& ObjectNode);
214+
WORD ReadSequencesWithDummies(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy);
215+
WORD ReadSequences(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& MapOfSequences);
216+
WORD ReadSequencesVersion1(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& MapOfSequences);
217+
WORD ReadSequencesVersion2(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& MapOfSequences);
218+
std::int32_t ReadSequenceVersion1(SAnim& Anim);
219+
void ReadSequenceVersion2(SSequenceHeaderV2& ObjectNode);
222220

223221
void ReadHeaderVersion1(SInfo& Info);
224222
void ReadAnimationNameVersion1(SAnimation& IfpAnimation);
225223
void ReadDgan(SDgan& Dgan);
226224
CClientIFP::eFrameType ReadKfrm(void);
227225
void ReadAnimationHeaderVersion2(SAnimationHeaderV2& AnimationNode, bool bAnp3);
228226

229-
bool ReadSequenceKeyFrames(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, eFrameType iFrameType, int32_t iFrames);
230-
void ReadKeyFramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, eFrameType iFrameType, int32_t iFrames);
231-
void ReadKrtsFramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, int32_t TotalFrames);
232-
void ReadKrt0FramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, int32_t TotalFrames);
233-
void ReadKr00FramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, int32_t TotalFrames);
227+
bool ReadSequenceKeyFrames(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, eFrameType iFrameType, const std::int32_t& cFrames);
228+
void ReadKeyFramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, eFrameType iFrameType, const std::int32_t& cFrames);
229+
void ReadKrtsFramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, const std::int32_t& cFrames);
230+
void ReadKrt0FramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, const std::int32_t& cFrames);
231+
void ReadKr00FramesAsCompressed(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, const std::int32_t& cFrames);
234232

235233
template <class T>
236-
void ReadCompressedFrames(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, int32_t iFrames)
234+
void ReadCompressedFrames(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, std::int32_t iFrames)
237235
{
238236
BYTE* pKeyFrames = pAnimationSequence->GetKeyFrames();
239237
size_t iSizeInBytes = sizeof(T) * iFrames;
240238
ReadBytes(pKeyFrames, iSizeInBytes);
241239
}
242240

243-
void InitializeAnimationHierarchy(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, const char* szAnimationName, const int32_t iSequences);
244-
void InitializeAnimationSequence(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, const char* szName, const int32_t iBoneID);
241+
void InitializeAnimationHierarchy(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, const SString& strAnimationName,
242+
const std::int32_t& iSequences);
243+
void InitializeAnimationSequence(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, const SString& strName, const std::int32_t& iBoneID);
245244
void PreProcessAnimationHierarchy(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy);
246245
void CopySequencesWithDummies(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy, std::map<DWORD, CAnimBlendSequenceSAInterface>& mapOfSequences);
247246
BYTE* AllocateSequencesMemory(std::unique_ptr<CAnimBlendHierarchy>& pAnimationHierarchy);
248247

249-
void InsertAnimationDummySequence(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, std::string& BoneName, DWORD& dwBoneID);
250-
void CopyDummyKeyFrameByBoneID(BYTE* pKeyFrames, DWORD dwBoneID);
251-
std::string ConvertStringToMapKey(const char* szString);
248+
void InsertAnimationDummySequence(std::unique_ptr<CAnimBlendSequence>& pAnimationSequence, const SString& BoneName, const DWORD& dwBoneID);
249+
void CopyDummyKeyFrameByBoneID(BYTE* pKeyFrames, DWORD dwBoneID);
250+
SString ConvertStringToKey(const SString& strBoneName);
252251

253-
constexpr void RoundSize(uint32_t& u32Size);
252+
constexpr void RoundSize(std::uint32_t& u32Size);
254253
constexpr bool IsKeyFramesTypeRoot(eFrameType iFrameType);
255254

256-
eFrameType GetFrameTypeFromFourCC(const char* szFourCC);
257-
size_t GetSizeOfCompressedFrame(eFrameType FrameType);
258-
int32_t GetBoneIDFromName(std::string const& BoneName);
259-
std::string GetCorrectBoneNameFromName(std::string const& BoneName);
260-
std::string GetCorrectBoneNameFromID(int32_t& BoneID);
255+
eFrameType GetFrameTypeFromFourCC(const char* szFourCC);
256+
size_t GetSizeOfCompressedFrame(eFrameType FrameType);
257+
std::int32_t GetBoneIDFromName(const SString& strBoneName);
258+
SString GetCorrectBoneNameFromName(const SString& strBoneName);
259+
SString GetCorrectBoneNameFromID(const std::int32_t& iBoneID);
261260

262261
std::shared_ptr<CIFPAnimations> m_pIFPAnimations;
263262
SString m_strBlockName;

Client/mods/deathmatch/logic/CElementDeleter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ void CElementDeleter::DeleteIFP(CClientEntity* pElement)
9494
const unsigned int u32BlockNameHash = IFP.GetBlockNameHash();
9595

9696
auto it = std::find_if(m_vecIFPElements.begin(), m_vecIFPElements.end(),
97-
[&u32BlockNameHash](std::shared_ptr<CClientIFP> const& pIFP)
98-
{
99-
return pIFP->GetBlockNameHash() == u32BlockNameHash;
100-
});
101-
if(it != m_vecIFPElements.end())
97+
[&u32BlockNameHash](std::shared_ptr<CClientIFP> const& pIFP) { return pIFP->GetBlockNameHash() == u32BlockNameHash; });
98+
if (it != m_vecIFPElements.end())
10299
{
103100
m_vecIFPElements.erase(it);
104101
}

Client/mods/deathmatch/logic/CFileReader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CFileReader::CFileReader(void)
88

99
void CFileReader::FreeFileReaderMemory(void)
1010
{
11-
std::vector<char>().swap( vecFileDataBuffer );
11+
std::vector<char>().swap(vecFileDataBuffer);
1212
u32BytesReadFromBuffer = 0;
1313
}
1414

@@ -34,15 +34,15 @@ void CFileReader::SkipBytes(const std::uint32_t u32BytesToSkip)
3434

3535
bool CFileReader::LoadFileToMemory(const SString& strFilePath)
3636
{
37-
std::ifstream fileStream(strFilePath, std::ios::binary | std::ios::ate);
37+
std::ifstream fileStream(strFilePath, std::ios::binary | std::ios::ate);
3838
std::streamsize iFileSize = fileStream.tellg();
3939
if (iFileSize == eIFSTREAM::SIZE_ERROR)
4040
{
4141
return false;
4242
}
4343

4444
fileStream.seekg(0, std::ios::beg);
45-
vecFileDataBuffer.reserve (static_cast < size_t > ( iFileSize ));
45+
vecFileDataBuffer.reserve(static_cast<size_t>(iFileSize));
4646
if (fileStream.read(vecFileDataBuffer.data(), iFileSize))
4747
{
4848
return true;

Client/mods/deathmatch/logic/CFileReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class CFileReader
77
{
88
public:
99
enum eIFSTREAM
10-
{
10+
{
1111
SIZE_ERROR = -1
1212
};
1313

@@ -24,9 +24,9 @@ class CFileReader
2424
*pDestination = *reinterpret_cast<T*>(&vecFileDataBuffer[u32ReadOffset]);
2525
}
2626

27-
void ReadBytes(void* pDestination, const std::uint32_t u32BytesToRead);
28-
void ReadStringNullTerminated(char* pDestination, const std::uint32_t u32BytesToRead);
29-
void SkipBytes(const std::uint32_t u32BytesToSkip);
27+
void ReadBytes(void* pDestination, const std::uint32_t u32BytesToRead);
28+
void ReadStringNullTerminated(char* pDestination, const std::uint32_t u32BytesToRead);
29+
void SkipBytes(const std::uint32_t u32BytesToSkip);
3030

3131
private:
3232
std::vector<char> vecFileDataBuffer;

Client/mods/deathmatch/logic/CIFPAnimations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ CIFPAnimations::~CIFPAnimations(void)
99
void CIFPAnimations::DeleteAnimations(void)
1010
{
1111
CAnimManager* pAnimManager = g_pGame->GetAnimManager();
12-
for (auto it = vecAnimations.begin(); it != vecAnimations.end(); ++it)
12+
for (auto& Animation : vecAnimations)
1313
{
14-
auto pAnimationHierarchy = pAnimManager->GetCustomAnimBlendHierarchy(&it->Hierarchy);
14+
auto pAnimationHierarchy = pAnimManager->GetCustomAnimBlendHierarchy(&Animation.Hierarchy);
1515
for (unsigned short SequenceIndex = 0; SequenceIndex < pAnimationHierarchy->GetNumSequences(); SequenceIndex++)
1616
{
1717
pAnimManager->RemoveFromUncompressedCache(pAnimationHierarchy->GetInterface());
@@ -32,6 +32,6 @@ void CIFPAnimations::DeleteAnimations(void)
3232
}
3333
}
3434
}
35-
delete it->pSequencesMemory;
35+
delete Animation.pSequencesMemory;
3636
}
3737
}

Client/mods/deathmatch/logic/CIFPAnimations.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma
21
#ifndef __CIFPANIMATIONS_H
32
#define __CIFPANIMATIONS_H
43
#include "../Client/mods/deathmatch/logic/CClientIFP.h"
@@ -9,9 +8,9 @@ class CIFPAnimations
98
struct SAnimation
109
{
1110
SString Name;
12-
unsigned int u32NameHash;
11+
unsigned int uiNameHash;
1312
CAnimBlendHierarchySAInterface Hierarchy;
14-
char* pSequencesMemory;
13+
BYTE* pSequencesMemory;
1514
};
1615

1716
std::vector<SAnimation> vecAnimations;

0 commit comments

Comments
 (0)