|
1 | 1 | /***************************************************************************** |
2 | 2 | * |
3 | | - * PROJECT: Multi Theft Auto v1.0 |
| 3 | + * PROJECT: Multi Theft Auto |
4 | 4 | * LICENSE: See LICENSE in the top level directory |
5 | 5 | * FILE: game_sa/CDummyPoolSA.cpp |
6 | 6 | * PURPOSE: Dummy pool class |
|
13 | 13 |
|
14 | 14 | #include "StdInc.h" |
15 | 15 | #include "CDummyPoolSA.h" |
| 16 | +#include "CGameSA.h" |
| 17 | +#include <game/CWorld.h> |
| 18 | + |
| 19 | +extern CGameSA* pGame; |
16 | 20 |
|
17 | 21 | CDummyPoolSA::CDummyPoolSA() |
18 | 22 | { |
19 | 23 | m_ppDummyPoolInterface = (CPoolSAInterface<CEntitySAInterface>**)0xB744A0; |
20 | 24 | } |
21 | 25 |
|
22 | | -void CDummyPoolSA::RemoveAllBuildingLods() |
| 26 | +void CDummyPoolSA::RemoveAllWithBackup() |
23 | 27 | { |
24 | | - if (m_pLodBackup) |
| 28 | + if (m_pOriginalElementsBackup) |
25 | 29 | return; |
26 | 30 |
|
27 | | - m_pLodBackup = std::make_unique<std::array<CEntitySAInterface*, MAX_DUMMIES>>(); |
| 31 | + m_pOriginalElementsBackup = std::make_unique<pool_backup_t>(); |
28 | 32 |
|
29 | | - for (int i = 0; i < MAX_DUMMIES; i++) |
| 33 | + auto pDummyPool = (*m_ppDummyPoolInterface); |
| 34 | + for (auto i = 0; i < MAX_DUMMIES_DEFAULT; i++) |
30 | 35 | { |
31 | | - CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i); |
32 | | - (*m_pLodBackup)[i] = object->m_pLod; |
33 | | - object->m_pLod = nullptr; |
| 36 | + if (pDummyPool->IsContains(i)) |
| 37 | + { |
| 38 | + CEntitySAInterface* building = pDummyPool->GetObject(i); |
| 39 | + |
| 40 | + pGame->GetWorld()->Remove(building, CDummyPool_Destructor); |
| 41 | + building->RemoveRWObjectWithReferencesCleanup(); |
| 42 | + |
| 43 | + pDummyPool->Release(i); |
| 44 | + |
| 45 | + (*m_pOriginalElementsBackup)[i].first = true; |
| 46 | + (*m_pOriginalElementsBackup)[i].second = *building; |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + (*m_pOriginalElementsBackup)[i].first = false; |
| 51 | + } |
34 | 52 | } |
35 | 53 | } |
36 | 54 |
|
37 | | -void CDummyPoolSA::RestoreAllBuildingsLods() |
| 55 | +void CDummyPoolSA::RestoreBackup() |
38 | 56 | { |
39 | | - if (!m_pLodBackup) |
| 57 | + if (!m_pOriginalElementsBackup) |
40 | 58 | return; |
41 | 59 |
|
42 | | - for (int i = 0; i < MAX_DUMMIES; i++) |
| 60 | + auto& originalData = *m_pOriginalElementsBackup; |
| 61 | + auto pDummyPool = (*m_ppDummyPoolInterface); |
| 62 | + for (auto i = 0; i < MAX_DUMMIES_DEFAULT; i++) |
43 | 63 | { |
44 | | - CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i); |
45 | | - object->m_pLod = (*m_pLodBackup)[i]; |
| 64 | + if (originalData[i].first) |
| 65 | + { |
| 66 | + pDummyPool->AllocateAt(i); |
| 67 | + auto pDummy = pDummyPool->GetObject(i); |
| 68 | + *pDummy = originalData[i].second; |
| 69 | + |
| 70 | + pGame->GetWorld()->Add(pDummy, CDummyPool_Constructor); |
| 71 | + } |
46 | 72 | } |
47 | 73 |
|
48 | | - m_pLodBackup.release(); |
| 74 | + m_pOriginalElementsBackup = nullptr; |
49 | 75 | } |
50 | 76 |
|
51 | | -void CDummyPoolSA::UpdateBuildingLods(void* oldPool, void* newPool) |
| 77 | +void CDummyPoolSA::UpdateBuildingLods(const std::uint32_t offset) |
52 | 78 | { |
53 | | - const uint32_t offset = (uint32_t)newPool - (uint32_t)oldPool; |
| 79 | + if (m_pOriginalElementsBackup) |
| 80 | + UpdateBackupLodOffset(offset); |
| 81 | + else |
| 82 | + UpdateLodsOffestInPool(offset); |
| 83 | +} |
54 | 84 |
|
55 | | - if (m_pLodBackup) |
| 85 | +void CDummyPoolSA::UpdateBackupLodOffset(const std::uint32_t offset) |
| 86 | +{ |
| 87 | + for (auto& it : *m_pOriginalElementsBackup) |
56 | 88 | { |
57 | | - for (int i = 0; i < MAX_DUMMIES; i++) |
| 89 | + if (it.first) |
58 | 90 | { |
59 | | - if ((*m_pLodBackup)[i] != nullptr) |
60 | | - { |
61 | | - (*m_pLodBackup)[i] = (CEntitySAInterface*)((uint32_t)(*m_pLodBackup)[i] + offset); |
62 | | - } |
| 91 | + CEntitySAInterface* object = &it.second; |
| 92 | + CEntitySAInterface* lod = object->GetLod(); |
| 93 | + if (lod) |
| 94 | + object->SetLod((CEntitySAInterface*)((std::uint32_t)lod + offset)); |
63 | 95 | } |
64 | 96 | } |
65 | | - else |
| 97 | +} |
| 98 | + |
| 99 | +void CDummyPoolSA::UpdateLodsOffestInPool(const std::uint32_t offset) |
| 100 | +{ |
| 101 | + for (auto i = 0; i < (*m_ppDummyPoolInterface)->Size(); i++) |
66 | 102 | { |
67 | | - for (int i = 0; i < MAX_DUMMIES; i++) |
68 | | - { |
69 | | - CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i); |
70 | | - if (object->m_pLod) |
71 | | - { |
72 | | - object->m_pLod = (CEntitySAInterface*)((uint32_t)object->m_pLod + offset); |
73 | | - } |
74 | | - } |
| 103 | + CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i); |
| 104 | + CEntitySAInterface* lod = object->GetLod(); |
| 105 | + if (lod) |
| 106 | + object->SetLod((CEntitySAInterface*)((std::uint32_t)lod + offset)); |
75 | 107 | } |
76 | 108 | } |
0 commit comments