Skip to content

Commit 26da3f5

Browse files
authored
Merge branch 'master' into client_c20
2 parents 8ec4253 + 839f328 commit 26da3f5

File tree

93 files changed

+2735
-2085
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2735
-2085
lines changed

Client/core/CVersionUpdater.Util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
class CVersionUpdater;
1313

1414
// Update master info
15-
#define UPDATER_MASTER_URL1 "http://updatesa.mtasa.com/sa/master/?v=%VERSION%&id=%ID%"
16-
#define UPDATER_MASTER_URL2 "http://updatesa.multitheftauto.com/sa/master/?v=%VERSION%&id=%ID%"
15+
#define UPDATER_MASTER_URL1 "https://updatesa.mtasa.com/sa/master/?v=%VERSION%&id=%ID%"
16+
#define UPDATER_MASTER_URL2 "https://updatesa.multitheftauto.com/sa/master/?v=%VERSION%&id=%ID%"
1717

1818
/*
1919

Client/game_sa/CAnimManagerSA.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,10 @@ static const char* const kGateWayAnimationName = "run_wuzi";
3232

3333
CAnimManagerSA::CAnimManagerSA()
3434
{
35-
MemSetFast(m_pAnimAssocGroups, 0, sizeof(m_pAnimAssocGroups));
36-
MemSetFast(m_pAnimBlocks, 0, sizeof(m_pAnimBlocks));
3735
}
3836

3937
CAnimManagerSA::~CAnimManagerSA()
4038
{
41-
for (unsigned int i = 0; i < MAX_ANIM_GROUPS; i++)
42-
if (m_pAnimAssocGroups[i])
43-
delete m_pAnimAssocGroups[i];
44-
for (unsigned int i = 0; i < MAX_ANIM_BLOCKS; i++)
45-
if (m_pAnimBlocks[i])
46-
delete m_pAnimBlocks[i];
4739
}
4840

4941
void CAnimManagerSA::Initialize()

Client/game_sa/CAnimManagerSA.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,4 @@ class CAnimManagerSA : public CAnimManager
165165

166166
bool IsValidGroup(std::uint32_t uiAnimGroup) const;
167167
bool IsValidAnim(std::uint32_t uiAnimGroup, std::uint32_t uiAnimID) const;
168-
private:
169-
CAnimBlendAssocGroup* m_pAnimAssocGroups[MAX_ANIM_GROUPS];
170-
CAnimBlock* m_pAnimBlocks[MAX_ANIM_BLOCKS];
171168
};

Client/game_sa/CBuildingSA.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
#include "CBuildingSA.h"
1414
#include <game/CWorld.h>
1515
#include "CGameSA.h"
16+
#include "CMatrixLinkSA.h"
17+
#include "CDynamicPool.h"
1618

1719
extern CGameSA* pGame;
1820

21+
static CDynamicPool<CMatrixLinkSAInterface, PoolGrowAddStrategy<0, 500>> g_matrixPool{};
22+
1923
CBuildingSA::CBuildingSA(CBuildingSAInterface* pInterface)
2024
{
2125
SetInterface(pInterface);
@@ -65,3 +69,42 @@ void CBuildingSA::SetLod(CBuilding* pLod)
6569
}
6670
}
6771
}
72+
73+
void CBuildingSA::AllocateMatrix()
74+
{
75+
auto* newMatrix = g_matrixPool.AllocateItem();
76+
std::memset(newMatrix, 0, sizeof(CMatrixLinkSAInterface));
77+
newMatrix->SetTranslateOnly(m_pInterface->Placeable.m_transform.m_translate);
78+
79+
m_pInterface->Placeable.matrix = reinterpret_cast<CMatrix_Padded*>(newMatrix);
80+
}
81+
82+
void CBuildingSA::ReallocateMatrix()
83+
{
84+
if (!m_pInterface->HasMatrix())
85+
return;
86+
87+
auto* newMatrix = g_matrixPool.AllocateItem();
88+
std::memcpy(newMatrix, m_pInterface->Placeable.matrix, sizeof(CMatrixLinkSAInterface));
89+
newMatrix->m_pOwner = nullptr;
90+
newMatrix->m_pPrev = nullptr;
91+
newMatrix->m_pNext = nullptr;
92+
93+
m_pInterface->RemoveMatrix();
94+
m_pInterface->Placeable.matrix = reinterpret_cast<CMatrix_Padded*>(newMatrix);
95+
}
96+
97+
void CBuildingSA::RemoveAllocatedMatrix()
98+
{
99+
if (!m_pInterface->HasMatrix())
100+
return;
101+
102+
CMatrixLinkSAInterface* pMatrix = reinterpret_cast<CMatrixLinkSAInterface*>(m_pInterface->Placeable.matrix);
103+
104+
if (pMatrix->m_pOwner || (pMatrix->m_pNext && pMatrix->m_pPrev))
105+
return;
106+
107+
g_matrixPool.RemoveItem(reinterpret_cast<CMatrixLinkSAInterface*>(m_pInterface->Placeable.matrix));
108+
g_matrixPool.SetCapacity(0);
109+
m_pInterface->Placeable.matrix = nullptr;
110+
}

Client/game_sa/CBuildingSA.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ class CBuildingSA final : public virtual CBuilding, public virtual CEntitySA
2727
CBuildingSAInterface* GetBuildingInterface() { return static_cast<CBuildingSAInterface*>(GetInterface()); };
2828

2929
void SetLod(CBuilding* pLod) override;
30+
31+
void AllocateMatrix();
32+
void ReallocateMatrix();
33+
void RemoveAllocatedMatrix();
3034
};

Client/game_sa/CBuildingsPoolSA.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "CPtrNodeSingleListSA.h"
1919
#include "MemSA.h"
2020
#include "CVehicleSA.h"
21+
#include "CBuildingRemovalSA.h"
2122

2223
extern CGameSA* pGame;
2324

@@ -48,7 +49,17 @@ inline bool CBuildingsPoolSA::AddBuildingToPool(CClientBuilding* pClientBuilding
4849
return true;
4950
}
5051

51-
CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint16_t modelId, CVector* vPos, CVector4D* vRot, uint8_t interior)
52+
CClientEntity* CBuildingsPoolSA::GetClientBuilding(CBuildingSAInterface* pGameInterface) const noexcept
53+
{
54+
std::uint32_t poolIndex = (*m_ppBuildingPoolInterface)->GetObjectIndexSafe(pGameInterface);
55+
56+
if (poolIndex == static_cast<std::uint32_t>(-1))
57+
return nullptr;
58+
59+
return m_buildingPool.entities[poolIndex].pClientEntity;
60+
}
61+
62+
CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint16_t modelId, CVector* vPos, CVector* vRot, uint8_t interior)
5263
{
5364
if (!HasFreeBuildingSlot())
5465
return nullptr;
@@ -61,15 +72,12 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
6172
modelInfo->SetObjectPropertiesGroup(MODEL_PROPERTIES_GROUP_STATIC);
6273

6374
// Load building
64-
SFileObjectInstance instance;
75+
SFileObjectInstance instance{};
6576
instance.modelID = modelId;
6677
instance.lod = -1;
6778
instance.interiorID = interior;
6879
instance.position = *vPos;
69-
instance.rotation = *vRot;
70-
71-
// Fix strange SA rotation
72-
instance.rotation.fW = -instance.rotation.fW;
80+
instance.rotation = {};
7381

7482
auto pBuilding = static_cast<CBuildingSAInterface*>(CFileLoaderSA::LoadObjectInstance(&instance));
7583

@@ -87,6 +95,22 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
8795

8896
// Add building in world
8997
auto pBuildingSA = new CBuildingSA(pBuilding);
98+
99+
if (pBuilding->HasMatrix())
100+
{
101+
// Edge case for the traincross2 (1374) model
102+
// LoadObjectInstance allocates a matrix for the model
103+
// We need allocate our own matrix and put the old matrix in the original pool
104+
pBuildingSA->ReallocateMatrix();
105+
}
106+
else if (vRot->fX != 0 || vRot->fY != 0)
107+
{
108+
// Allocate matrix in our unlimited storage instead of using the shared pool.
109+
pBuildingSA->AllocateMatrix();
110+
}
111+
112+
pBuilding->SetOrientation(vRot->fX, vRot->fY, vRot->fZ);
113+
90114
pGame->GetWorld()->Add(pBuildingSA, CBuildingPool_Constructor);
91115

92116
// Add CBuildingSA object in pool
@@ -105,6 +129,10 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
105129
if (dwElementIndexInPool == UINT_MAX)
106130
return;
107131

132+
// Remove references to allocated matrix
133+
auto* pBuildingSA = m_buildingPool.entities[dwElementIndexInPool].pEntity;
134+
pBuildingSA->RemoveAllocatedMatrix();
135+
108136
// Remove building from cover list
109137
pGame->GetCoverManager()->RemoveCover(pInterface);
110138

@@ -117,23 +145,24 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
117145
// Remove building from world
118146
pGame->GetWorld()->Remove(pInterface, CBuildingPool_Destructor);
119147

148+
std::uint16_t modelId = pInterface->m_nModelIndex;
149+
120150
// Call virtual destructor
121151
((void*(__thiscall*)(void*, char))pInterface->vtbl->SCALAR_DELETING_DESTRUCTOR)(pInterface, 0);
122152

123153
// Remove col reference
124-
auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex());
154+
auto modelInfo = pGame->GetModelInfo(modelId);
125155
modelInfo->RemoveColRef();
126156

157+
// Remove building from SA pool
158+
(*m_ppBuildingPoolInterface)->Release(dwElementIndexInPool);
159+
127160
// Remove from BuildingSA pool
128-
auto* pBuildingSA = m_buildingPool.entities[dwElementIndexInPool].pEntity;
129161
m_buildingPool.entities[dwElementIndexInPool] = {nullptr, nullptr};
130162

131163
// Delete it from memory
132164
delete pBuildingSA;
133165

134-
// Remove building from SA pool
135-
(*m_ppBuildingPoolInterface)->Release(dwElementIndexInPool);
136-
137166
// Decrease the count of elements in the pool
138167
--m_buildingPool.count;
139168
}
@@ -174,6 +203,9 @@ void CBuildingsPoolSA::RestoreBackup()
174203
if (!m_pOriginalBuildingsBackup)
175204
return;
176205

206+
auto* worldSA = pGame->GetWorld();
207+
auto* buildingRemovealSA = static_cast<CBuildingRemovalSA*>(pGame->GetBuildingRemoval());
208+
177209
auto& originalData = *m_pOriginalBuildingsBackup;
178210
auto pBuildsingsPool = (*m_ppBuildingPoolInterface);
179211
for (size_t i = 0; i < MAX_BUILDINGS; i++)
@@ -184,7 +216,8 @@ void CBuildingsPoolSA::RestoreBackup()
184216
auto pBuilding = pBuildsingsPool->GetObject(i);
185217
*pBuilding = originalData[i].second;
186218

187-
pGame->GetWorld()->Add(pBuilding, CBuildingPool_Constructor);
219+
worldSA->Add(pBuilding, CBuildingPool_Constructor);
220+
buildingRemovealSA->AddDataBuilding(pBuilding);
188221
}
189222
}
190223

Client/game_sa/CBuildingsPoolSA.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ class CBuildingsPoolSA : public CBuildingsPool
2222
CBuildingsPoolSA();
2323
~CBuildingsPoolSA() = default;
2424

25-
CBuilding* AddBuilding(CClientBuilding*, uint16_t modelId, CVector* vPos, CVector4D* vRot, uint8_t interior);
25+
CBuilding* AddBuilding(CClientBuilding*, uint16_t modelId, CVector* vPos, CVector* vRot, uint8_t interior);
2626
void RemoveBuilding(CBuilding* pBuilding);
2727
bool HasFreeBuildingSlot();
2828

2929
void RemoveAllWithBackup() override;
3030
void RestoreBackup() override;
3131
bool Resize(int size) override;
3232
int GetSize() const override { return (*m_ppBuildingPoolInterface)->m_nSize; };
33+
CClientEntity* GetClientBuilding(CBuildingSAInterface* pGameInterface) const noexcept;
3334

3435
private:
3536
void RemoveBuildingFromWorld(CBuildingSAInterface* pBuilding);

0 commit comments

Comments
 (0)