Skip to content

Commit 76e266a

Browse files
committed
Use std::unique_ptr for CAnimBlendAssocGroup and CAnimBlock
1 parent 0bba0fc commit 76e266a

File tree

9 files changed

+79
-66
lines changed

9 files changed

+79
-66
lines changed

Client/game_sa/CAnimManagerSA.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(int ID)
8080
return nullptr;
8181
}
8282

83-
std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(const char* szName, CAnimBlock* pBlock)
83+
std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(const char* szName, std::unique_ptr<CAnimBlock>& pBlock)
8484
{
8585
CAnimBlendHierarchySAInterface* pInterface = nullptr;
8686
DWORD dwFunc = FUNC_CAnimManager_GetAnimation_str_block;
@@ -100,7 +100,7 @@ std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(const char* sz
100100
return nullptr;
101101
}
102102

103-
std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(unsigned int uiIndex, CAnimBlock* pBlock)
103+
std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(unsigned int uiIndex, std::unique_ptr<CAnimBlock>& pBlock)
104104
{
105105
CAnimBlendHierarchySAInterface* pInterface = nullptr;
106106
;
@@ -121,7 +121,7 @@ std::unique_ptr<CAnimBlendHierarchy> CAnimManagerSA::GetAnimation(unsigned int u
121121
return nullptr;
122122
}
123123

124-
CAnimBlock* CAnimManagerSA::GetAnimationBlock(int ID)
124+
std::unique_ptr<CAnimBlock> CAnimManagerSA::GetAnimationBlock(int ID)
125125
{
126126
CAnimBlockSAInterface* pInterface = nullptr;
127127
DWORD dwFunc = FUNC_CAnimManager_GetAnimationBlock_int;
@@ -132,10 +132,14 @@ CAnimBlock* CAnimManagerSA::GetAnimationBlock(int ID)
132132
mov pInterface, eax
133133
add esp, 0x4
134134
}
135-
return GetAnimBlock(pInterface);
135+
if (pInterface)
136+
{
137+
return std::make_unique<CAnimBlockSA>(pInterface);
138+
}
139+
return nullptr;
136140
}
137141

138-
CAnimBlock* CAnimManagerSA::GetAnimationBlock(const char* szName)
142+
std::unique_ptr<CAnimBlock> CAnimManagerSA::GetAnimationBlock(const char* szName)
139143
{
140144
CAnimBlockSAInterface* pInterface = nullptr;
141145
DWORD dwFunc = FUNC_CAnimManager_GetAnimationBlock_str;
@@ -146,7 +150,11 @@ CAnimBlock* CAnimManagerSA::GetAnimationBlock(const char* szName)
146150
mov pInterface, eax
147151
add esp, 0x4
148152
}
149-
return GetAnimBlock(pInterface);
153+
if (pInterface)
154+
{
155+
return std::make_unique<CAnimBlockSA>(pInterface);
156+
}
157+
return nullptr;
150158
}
151159

152160
int CAnimManagerSA::GetAnimationBlockIndex(const char* szName)
@@ -177,7 +185,7 @@ int CAnimManagerSA::RegisterAnimBlock(const char* szName)
177185
return iReturn;
178186
}
179187

180-
CAnimBlendAssocGroup* CAnimManagerSA::GetAnimBlendAssoc(AssocGroupId groupID)
188+
std::unique_ptr<CAnimBlendAssocGroup> CAnimManagerSA::GetAnimBlendAssoc(AssocGroupId groupID)
181189
{
182190
CAnimBlendAssocGroupSAInterface* pInterface = nullptr;
183191
DWORD dwFunc = FUNC_CAnimManager_GetAnimBlendAssoc;
@@ -188,7 +196,11 @@ CAnimBlendAssocGroup* CAnimManagerSA::GetAnimBlendAssoc(AssocGroupId groupID)
188196
mov pInterface, eax
189197
add esp, 0x4
190198
}
191-
return GetAnimBlendAssocGroup(pInterface);
199+
if (pInterface)
200+
{
201+
return std::make_unique<CAnimBlendAssocGroupSA>(pInterface);
202+
}
203+
return nullptr;
192204
}
193205

194206
AssocGroupId CAnimManagerSA::GetFirstAssocGroup(const char* szName)
@@ -773,36 +785,20 @@ std::unique_ptr<CAnimBlendAssociation> CAnimManagerSA::GetAnimBlendAssociation(C
773785
return nullptr;
774786
}
775787

776-
CAnimBlendAssocGroup* CAnimManagerSA::GetAnimBlendAssocGroup(CAnimBlendAssocGroupSAInterface* pInterface)
788+
std::unique_ptr<CAnimBlendAssocGroup> CAnimManagerSA::GetAnimBlendAssocGroup(CAnimBlendAssocGroupSAInterface* pInterface)
777789
{
778790
if (pInterface)
779791
{
780-
AssocGroupId groupID = pInterface->groupID;
781-
if (groupID < TOTAL_ANIM_GROUPS)
782-
{
783-
if (!m_pAnimAssocGroups[groupID])
784-
{
785-
m_pAnimAssocGroups[groupID] = new CAnimBlendAssocGroupSA(pInterface);
786-
}
787-
return m_pAnimAssocGroups[groupID];
788-
}
792+
return std::make_unique<CAnimBlendAssocGroupSA>(pInterface);
789793
}
790794
return nullptr;
791795
}
792796

793-
CAnimBlock* CAnimManagerSA::GetAnimBlock(CAnimBlockSAInterface* pInterface)
797+
std::unique_ptr<CAnimBlock> CAnimManagerSA::GetAnimBlock(CAnimBlockSAInterface* pInterface)
794798
{
795799
if (pInterface)
796800
{
797-
unsigned int ID = pInterface->GetIndex();
798-
if (ID < MAX_ANIM_BLOCKS)
799-
{
800-
if (!m_pAnimBlocks[ID])
801-
{
802-
m_pAnimBlocks[ID] = new CAnimBlockSA(pInterface);
803-
}
804-
return m_pAnimBlocks[ID];
805-
}
801+
return std::make_unique<CAnimBlockSA>(pInterface);
806802
}
807803
return nullptr;
808804
}

Client/game_sa/CAnimManagerSA.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <game/CAnimBlendAssociation.h>
1616
#include <game/CAnimBlendHierarchy.h>
1717
#include <game/CAnimBlock.h>
18+
#include <game/CAnimBlendAssocGroup.h>
1819

1920
#include "Common.h"
2021
#include <list>
@@ -93,16 +94,16 @@ class CAnimManagerSA : public CAnimManager
9394
int GetNumAnimAssocDefinitions();
9495

9596
std::unique_ptr<CAnimBlendHierarchy> GetAnimation(int ID);
96-
std::unique_ptr<CAnimBlendHierarchy> GetAnimation(const char* szName, CAnimBlock* pBlock);
97-
std::unique_ptr<CAnimBlendHierarchy> GetAnimation(unsigned int uiIndex, CAnimBlock* pBlock);
97+
std::unique_ptr<CAnimBlendHierarchy> GetAnimation(const char* szName, std::unique_ptr<CAnimBlock>& pBlock);
98+
std::unique_ptr<CAnimBlendHierarchy> GetAnimation(unsigned int uiIndex, std::unique_ptr<CAnimBlock>& pBlock);
9899

99-
CAnimBlock* GetAnimationBlock(int ID);
100-
CAnimBlock* GetAnimationBlock(const char* szName);
101-
int GetAnimationBlockIndex(const char* szName);
102-
int RegisterAnimBlock(const char* szName);
100+
std::unique_ptr<CAnimBlock> GetAnimationBlock(int ID);
101+
std::unique_ptr<CAnimBlock> GetAnimationBlock(const char* szName);
102+
int GetAnimationBlockIndex(const char* szName);
103+
int RegisterAnimBlock(const char* szName);
103104

104-
CAnimBlendAssocGroup* GetAnimBlendAssoc(AssocGroupId groupID);
105-
AssocGroupId GetFirstAssocGroup(const char* szName);
105+
std::unique_ptr<CAnimBlendAssocGroup> GetAnimBlendAssoc(AssocGroupId groupID);
106+
AssocGroupId GetFirstAssocGroup(const char* szName);
106107

107108
const char* GetAnimGroupName(AssocGroupId groupID);
108109
const char* GetAnimBlockName(AssocGroupId groupID);
@@ -150,8 +151,8 @@ class CAnimManagerSA : public CAnimManager
150151

151152
// MTA members
152153
std::unique_ptr<CAnimBlendAssociation> GetAnimBlendAssociation(CAnimBlendAssociationSAInterface* pInterface);
153-
CAnimBlendAssocGroup* GetAnimBlendAssocGroup(CAnimBlendAssocGroupSAInterface* pInterface);
154-
CAnimBlock* GetAnimBlock(CAnimBlockSAInterface* pInterface);
154+
std::unique_ptr<CAnimBlendAssocGroup> GetAnimBlendAssocGroup(CAnimBlendAssocGroupSAInterface* pInterface);
155+
std::unique_ptr<CAnimBlock> GetAnimBlock(CAnimBlockSAInterface* pInterface);
155156
std::unique_ptr<CAnimBlendHierarchy> GetAnimBlendHierarchy(CAnimBlendHierarchySAInterface* pInterface);
156157

157158
StaticAssocIntface_type GetAnimStaticAssociation(CAnimBlendStaticAssociationSAInterface* pInterface);

Client/game_sa/CPlayerPedSA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void CPlayerPedSA::SetMoveAnim(eMoveAnim iAnimGroup)
285285
// Need to load ?
286286
if (!IsBlendAssocGroupLoaded(iAnimGroup))
287287
{
288-
CAnimBlock* pAnimBlock = pGame->GetAnimManager()->GetAnimationBlock(strBlockName);
288+
std::unique_ptr<CAnimBlock> pAnimBlock = pGame->GetAnimManager()->GetAnimationBlock(strBlockName);
289289

290290
// Try load
291291
if (pAnimBlock && !pAnimBlock->IsLoaded())
@@ -304,7 +304,7 @@ void CPlayerPedSA::SetMoveAnim(eMoveAnim iAnimGroup)
304304
return;
305305

306306
// Ensure we add a ref to this block, even if it wasn't loaded by us
307-
CAnimBlock* pAnimBlock = pGame->GetAnimManager()->GetAnimationBlock(strBlockName);
307+
std::unique_ptr<CAnimBlock> pAnimBlock = pGame->GetAnimManager()->GetAnimationBlock(strBlockName);
308308
if (!pAnimBlock)
309309
return;
310310
if (!MapContains(ms_DoneAnimBlockRefMap, strBlockName))

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ void CClientPed::ApplyControllerStateFixes(CControllerState& Current)
29162916
animId == ANIM_ID_STEALTH_AIM)
29172917
{
29182918
// Are our knife anims loaded?
2919-
CAnimBlock* pBlock = g_pGame->GetAnimManager()->GetAnimationBlock("KNIFE");
2919+
std::unique_ptr<CAnimBlock> pBlock = g_pGame->GetAnimManager()->GetAnimationBlock("KNIFE");
29202920
if (pBlock->IsLoaded())
29212921
{
29222922
// Force the animation
@@ -4360,7 +4360,7 @@ void CClientPed::SetWearingGoggles(bool bWearing, bool animationEnabled)
43604360
// Are our goggle anims loaded?
43614361
if (animationEnabled)
43624362
{
4363-
CAnimBlock* pBlock = g_pGame->GetAnimManager()->GetAnimationBlock("GOGGLES");
4363+
std::unique_ptr<CAnimBlock> pBlock = g_pGame->GetAnimManager()->GetAnimationBlock("GOGGLES");
43644364
if (pBlock->IsLoaded())
43654365
{
43664366
BlendAnimation(ANIM_GROUP_GOGGLES, ANIM_ID_GOGGLES_ON, 4.0f);
@@ -5651,7 +5651,7 @@ void CClientPed::RunAnimation(AssocGroupId animGroup, AnimationId animID)
56515651
}
56525652
}
56535653

5654-
void CClientPed::RunNamedAnimation(CAnimBlock* pBlock, const char* szAnimName, int iTime, int iBlend, bool bLoop, bool bUpdatePosition, bool bInterruptable,
5654+
void CClientPed::RunNamedAnimation(std::unique_ptr<CAnimBlock>& pBlock, const char* szAnimName, int iTime, int iBlend, bool bLoop, bool bUpdatePosition, bool bInterruptable,
56555655
bool bFreezeLastFrame, bool bRunInSequence, bool bOffsetPed, bool bHoldLastFrame)
56565656
{
56575657
/* lil_Toady: this seems to break things
@@ -5721,7 +5721,10 @@ void CClientPed::RunNamedAnimation(CAnimBlock* pBlock, const char* szAnimName, i
57215721
*/
57225722
}
57235723
}
5724-
m_pAnimationBlock = pBlock;
5724+
if (pBlock)
5725+
{
5726+
m_pAnimationBlock = g_pGame->GetAnimManager()->GetAnimBlock(pBlock->GetInterface());
5727+
}
57255728
m_strAnimationName = szAnimName;
57265729
m_iTimeAnimation = iTime;
57275730
m_iBlendAnimation = iBlend;
@@ -5753,6 +5756,19 @@ void CClientPed::KillAnimation()
57535756
SetNextAnimationNormal();
57545757
}
57555758

5759+
std::unique_ptr<CAnimBlock> CClientPed::GetAnimationBlock()
5760+
{
5761+
if (m_pAnimationBlock)
5762+
{
5763+
return g_pGame->GetAnimManager()->GetAnimBlock(m_pAnimationBlock->GetInterface());
5764+
}
5765+
return nullptr;
5766+
}
5767+
const char* CClientPed::GetAnimationName()
5768+
{
5769+
return m_strAnimationName;
5770+
}
5771+
57565772
void CClientPed::PostWeaponFire()
57575773
{
57585774
m_ulLastTimeFired = CClientTime::GetTime();

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
420420

421421
bool IsRunningAnimation();
422422
void RunAnimation(AssocGroupId animGroup, AnimationId animID);
423-
void RunNamedAnimation(CAnimBlock* pBlock, const char* szAnimName, int iTime = -1, int iBlend = 250, bool bLoop = true, bool bUpdatePosition = true,
423+
void RunNamedAnimation(std::unique_ptr<CAnimBlock>& pBlock, const char* szAnimName, int iTime = -1, int iBlend = 250, bool bLoop = true, bool bUpdatePosition = true,
424424
bool bInterruptable = false, bool bFreezeLastFrame = true, bool bRunInSequence = false, bool bOffsetPed = false,
425425
bool bHoldLastFrame = false);
426-
void KillAnimation();
427-
CAnimBlock* GetAnimationBlock() { return m_pAnimationBlock; }
428-
const char* GetAnimationName() { return m_strAnimationName; }
426+
void KillAnimation();
427+
std::unique_ptr<CAnimBlock> GetAnimationBlock();
428+
const char* GetAnimationName();
429429

430430
bool IsUsingGun();
431431

@@ -637,7 +637,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
637637
CClientPad m_Pad;
638638
bool m_bDestroyingSatchels;
639639
bool m_bDoingGangDriveby;
640-
CAnimBlock* m_pAnimationBlock;
640+
std::unique_ptr<CAnimBlock> m_pAnimationBlock;
641641
SString m_strAnimationName;
642642
bool m_bRequestedAnimation;
643643
int m_iTimeAnimation;

Client/mods/deathmatch/logic/CIFPEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool CIFPEngine::EngineReplaceAnimation(CClientEntity* pEntity, const SString& s
4545
CClientPed& Ped = static_cast<CClientPed&>(*pEntity);
4646

4747
const unsigned int u32BlockNameHash = HashString(strCustomBlockName.ToLower());
48-
CAnimBlock* pInternalBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strInternalBlockName);
48+
std::unique_ptr<CAnimBlock> pInternalBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strInternalBlockName);
4949
std::shared_ptr<CClientIFP> pCustomIFP = g_pClientGame->GetIFPPointerFromMap(u32BlockNameHash);
5050
if (pInternalBlock && pCustomIFP)
5151
{
@@ -78,7 +78,7 @@ bool CIFPEngine::EngineRestoreAnimation(CClientEntity* pEntity, const SString& s
7878
}
7979
else
8080
{
81-
CAnimBlock* pInternalBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strInternalBlockName);
81+
std::unique_ptr<CAnimBlock> pInternalBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strInternalBlockName);
8282
if (pInternalBlock)
8383
{
8484
if (eRestoreType == eRestoreAnimation::BLOCK)

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,7 @@ bool CStaticFunctionDefinitions::SetPedAnimation(CClientEntity& Entity, const SS
21602160
CClientPed& Ped = static_cast<CClientPed&>(Entity);
21612161
if (strBlockName && szAnimName)
21622162
{
2163-
CAnimBlock* pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strBlockName);
2163+
std::unique_ptr<CAnimBlock> pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strBlockName);
21642164
if (pBlock)
21652165
{
21662166
Ped.SetCurrentAnimationCustom(false);
@@ -2176,8 +2176,8 @@ bool CStaticFunctionDefinitions::SetPedAnimation(CClientEntity& Entity, const SS
21762176
if (pIFP)
21772177
{
21782178
// Play the gateway animation
2179-
const SString& strGateWayBlockName = g_pGame->GetAnimManager()->GetGateWayBlockName();
2180-
CAnimBlock* pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strGateWayBlockName);
2179+
const SString& strGateWayBlockName = g_pGame->GetAnimManager()->GetGateWayBlockName();
2180+
std::unique_ptr<CAnimBlock> pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(strGateWayBlockName);
21812181
auto pCustomAnimBlendHierarchy = pIFP->GetAnimationHierarchy(szAnimName);
21822182
if ((pBlock) && (pCustomAnimBlendHierarchy != nullptr))
21832183
{

Client/mods/deathmatch/logic/rpc/CPedRPCs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void CPedRPCs::SetPedAnimation(CClientEntity* pSource, NetBitStreamInterface& bi
266266
if (bitStream.Version() >= 0x065)
267267
bitStream.Read(iBlend);
268268

269-
CAnimBlock* pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(blockName.c_str());
269+
std::unique_ptr<CAnimBlock> pBlock = g_pGame->GetAnimManager()->GetAnimationBlock(blockName.c_str());
270270
if (pBlock)
271271
pPed->RunNamedAnimation(pBlock, animName.c_str(), iTime, iBlend, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame);
272272
}

Client/sdk/game/CAnimManager.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CAnimManager
4848
public:
4949
typedef std::unique_ptr<CAnimBlendAssociation> AnimBlendAssoc_type;
5050
typedef std::unique_ptr<CAnimBlendStaticAssociation> StaticAssocIntface_type;
51-
51+
typedef std::unique_ptr<CAnimBlendAssocGroup> AnimAssocGroup_type;
5252
virtual void Initialize() = 0;
5353
virtual void Shutdown() = 0;
5454

@@ -57,16 +57,16 @@ class CAnimManager
5757
virtual int GetNumAnimAssocDefinitions() = 0;
5858

5959
virtual std::unique_ptr<CAnimBlendHierarchy> GetAnimation(int ID) = 0;
60-
virtual std::unique_ptr<CAnimBlendHierarchy> GetAnimation(const char* szName, CAnimBlock* pBlock) = 0;
61-
virtual std::unique_ptr<CAnimBlendHierarchy> GetAnimation(unsigned int uiIndex, CAnimBlock* pBlock) = 0;
60+
virtual std::unique_ptr<CAnimBlendHierarchy> GetAnimation(const char* szName, std::unique_ptr<CAnimBlock>& pBlock) = 0;
61+
virtual std::unique_ptr<CAnimBlendHierarchy> GetAnimation(unsigned int uiIndex, std::unique_ptr<CAnimBlock>& pBlock) = 0;
6262

63-
virtual CAnimBlock* GetAnimationBlock(int ID) = 0;
64-
virtual CAnimBlock* GetAnimationBlock(const char* szName) = 0;
65-
virtual int GetAnimationBlockIndex(const char* szName) = 0;
66-
virtual int RegisterAnimBlock(const char* szName) = 0;
63+
virtual std::unique_ptr<CAnimBlock> GetAnimationBlock(int ID) = 0;
64+
virtual std::unique_ptr<CAnimBlock> GetAnimationBlock(const char* szName) = 0;
65+
virtual int GetAnimationBlockIndex(const char* szName) = 0;
66+
virtual int RegisterAnimBlock(const char* szName) = 0;
6767

68-
virtual CAnimBlendAssocGroup* GetAnimBlendAssoc(AssocGroupId groupID) = 0;
69-
virtual AssocGroupId GetFirstAssocGroup(const char* szName) = 0;
68+
virtual AnimAssocGroup_type GetAnimBlendAssoc(AssocGroupId groupID) = 0;
69+
virtual AssocGroupId GetFirstAssocGroup(const char* szName) = 0;
7070

7171
virtual const char* GetAnimGroupName(AssocGroupId groupID) = 0;
7272
virtual const char* GetAnimBlockName(AssocGroupId groupID) = 0;
@@ -114,8 +114,8 @@ class CAnimManager
114114

115115
// MTA members
116116
virtual AnimBlendAssoc_type GetAnimBlendAssociation(CAnimBlendAssociationSAInterface* pInterface) = 0;
117-
virtual CAnimBlendAssocGroup* GetAnimBlendAssocGroup(CAnimBlendAssocGroupSAInterface* pInterface) = 0;
118-
virtual CAnimBlock* GetAnimBlock(CAnimBlockSAInterface* pInterface) = 0;
117+
virtual AnimAssocGroup_type GetAnimBlendAssocGroup(CAnimBlendAssocGroupSAInterface* pInterface) = 0;
118+
virtual std::unique_ptr<CAnimBlock> GetAnimBlock(CAnimBlockSAInterface* pInterface) = 0;
119119
virtual std::unique_ptr<CAnimBlendHierarchy> GetAnimBlendHierarchy(CAnimBlendHierarchySAInterface* pInterface) = 0;
120120

121121
virtual StaticAssocIntface_type GetAnimStaticAssociation(CAnimBlendStaticAssociationSAInterface* pInterface) = 0;

0 commit comments

Comments
 (0)