Skip to content

Commit 6c856f0

Browse files
committed
Make Enumerable array contiguous again
the madness must end now
1 parent e17c8b0 commit 6c856f0

7 files changed

Lines changed: 20 additions & 68 deletions

File tree

src/Ext/Bullet/Body.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ void BulletExt::ExtData::InitializeLaserTrails()
150150

151151
for (auto const& idxTrail : pTypeExt->LaserTrail_Types)
152152
{
153-
if (auto const pLaserType = LaserTrailTypeClass::Array[idxTrail].get())
154-
{
155-
this->LaserTrails.push_back(LaserTrailClass { pLaserType, pOwner });
156-
}
153+
this->LaserTrails.push_back(LaserTrailClass { &LaserTrailTypeClass::Array[idxTrail], pOwner });
157154
}
158155
}
159156
}

src/Ext/Techno/Body.Internal.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ void TechnoExt::ExtData::InitializeLaserTrails()
1515
{
1616
for (auto const& entry : pTypeExt->LaserTrailData)
1717
{
18-
if (auto const pLaserType = LaserTrailTypeClass::Array[entry.idxType].get())
19-
{
20-
this->LaserTrails.push_back(
21-
LaserTrailClass { pLaserType, this->OwnerObject()->Owner, entry.FLH, entry.IsOnTurret });
22-
}
18+
this->LaserTrails.emplace_back(entry.GetType(), this->OwnerObject()->Owner, entry.FLH, entry.IsOnTurret);
2319
}
2420
}
2521
}

src/Ext/Techno/Body.Update.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,7 @@ void TechnoExt::ExtData::UpdateTypeData(TechnoTypeClass* pCurrentType)
422422
// Recreate Laser Trails
423423
for (auto const& entry : this->TypeExtData->LaserTrailData)
424424
{
425-
if (auto const pLaserType = LaserTrailTypeClass::Array[entry.idxType].get())
426-
{
427-
this->LaserTrails.push_back(LaserTrailClass {
428-
pLaserType, pThis->Owner, entry.FLH, entry.IsOnTurret });
429-
}
425+
this->LaserTrails.emplace_back(entry.GetType(), pThis->Owner, entry.FLH, entry.IsOnTurret);
430426
}
431427

432428
// Reset AutoDeath Timer

src/Ext/TechnoType/Body.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -845,26 +845,6 @@ void TechnoTypeExt::ExtData::SaveToStream(PhobosStreamWriter& Stm)
845845
this->Serialize(Stm);
846846
}
847847

848-
bool TechnoTypeExt::ExtData::LaserTrailDataEntry::Load(PhobosStreamReader& stm, bool registerForChange)
849-
{
850-
return this->Serialize(stm);
851-
}
852-
853-
bool TechnoTypeExt::ExtData::LaserTrailDataEntry::Save(PhobosStreamWriter& stm) const
854-
{
855-
return const_cast<LaserTrailDataEntry*>(this)->Serialize(stm);
856-
}
857-
858-
template <typename T>
859-
bool TechnoTypeExt::ExtData::LaserTrailDataEntry::Serialize(T& stm)
860-
{
861-
return stm
862-
.Process(this->idxType)
863-
.Process(this->FLH)
864-
.Process(this->IsOnTurret)
865-
.Success();
866-
}
867-
868848
// =============================
869849
// container
870850

src/Ext/TechnoType/Body.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,7 @@ class TechnoTypeExt
234234
ValueableIdx<LaserTrailTypeClass> idxType;
235235
Valueable<CoordStruct> FLH;
236236
Valueable<bool> IsOnTurret;
237-
238-
bool Load(PhobosStreamReader& stm, bool registerForChange);
239-
bool Save(PhobosStreamWriter& stm) const;
240-
241-
private:
242-
template <typename T>
243-
bool Serialize(T& stm);
237+
LaserTrailTypeClass* GetType() const { return &LaserTrailTypeClass::Array[idxType]; }
244238
};
245239

246240
std::vector<LaserTrailDataEntry> LaserTrailData;

src/Ext/VoxelAnim/Body.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ void VoxelAnimExt::InitializeLaserTrails(VoxelAnimClass* pThis)
1515

1616
for (auto const& idxTrail : pTypeExt->LaserTrail_Types)
1717
{
18-
if (auto const pLaserType = LaserTrailTypeClass::Array[idxTrail].get())
19-
{
20-
pThisExt->LaserTrails.push_back(LaserTrailClass { pLaserType, pThis->OwnerHouse });
21-
}
18+
pThisExt->LaserTrails.push_back(LaserTrailClass { &LaserTrailTypeClass::Array[idxTrail], pThis->OwnerHouse });
2219
}
2320
}
2421

src/Utilities/Enumerable.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
#pragma once
22

3-
#include <Phobos.CRT.h>
43
#include "Savegame.h"
54
#include "Constructs.h"
65

76
#include <algorithm>
8-
#include <memory>
97
#include <vector>
108

11-
#include <ArrayClasses.h>
129
#include <CCINIClass.h>
1310
#include "Swizzle.h"
1411

1512
template <typename T> class Enumerable
1613
{
17-
typedef std::vector<std::unique_ptr<T>> container_t;
18-
1914
public:
20-
static container_t Array;
15+
inline static std::vector<T> Array;
2116

2217
static int FindIndex(const char* Title)
2318
{
24-
auto result = std::find_if(Array.begin(), Array.end(), [Title](std::unique_ptr<T>& Item)
19+
auto result = std::find_if(Array.begin(), Array.end(), [Title](const T& Item)
2520
{
26-
return !_strcmpi(Item->Name, Title);
21+
return !_strcmpi(Item.Name, Title);
2722
});
2823

2924
if (result == Array.end())
@@ -35,17 +30,17 @@ template <typename T> class Enumerable
3530
static T* Find(const char* Title)
3631
{
3732
auto result = FindIndex(Title);
38-
return (result < 0) ? nullptr : Array[static_cast<size_t>(result)].get();
33+
return (result < 0) ? nullptr : &Array[static_cast<size_t>(result)];
3934
}
4035

4136
static T* FindOrAllocate(const char* Title)
4237
{
43-
if (T* find = Find(Title))
44-
return find;
45-
46-
Array.push_back(std::make_unique<T>(Title));
38+
if (T* found = Find(Title))
39+
return found;
40+
static_assert(std::constructible_from<T, const char*>);
41+
Array.emplace_back(Title);
4742

48-
return Array.back().get();
43+
return &Array.back();
4944
}
5045

5146
static void Clear()
@@ -64,8 +59,8 @@ template <typename T> class Enumerable
6459
FindOrAllocate(Phobos::readBuffer);
6560
}
6661

67-
for (const auto& item : Array)
68-
item->LoadFromINI(pINI);
62+
for (auto& item : Array)
63+
item.LoadFromINI(pINI);
6964
}
7065

7166
static bool LoadGlobals(PhobosStreamReader& Stm)
@@ -98,12 +93,12 @@ template <typename T> class Enumerable
9893
{
9994
Stm.Save(Array.size());
10095

101-
for (const auto& item : Array)
96+
for (auto& item : Array)
10297
{
10398
// write old pointer and name, then delegate
104-
Stm.Save(item.get());
105-
Stm.Save(item->Name);
106-
item->SaveToStream(Stm);
99+
Stm.Save(&item);
100+
Stm.Save(item.Name);
101+
item.SaveToStream(Stm);
107102
}
108103

109104
return true;
@@ -124,6 +119,3 @@ template <typename T> class Enumerable
124119

125120
PhobosFixedString<32> Name;
126121
};
127-
128-
template <typename T>
129-
Enumerable<T>::container_t Enumerable<T>::Array;

0 commit comments

Comments
 (0)