Skip to content

Commit 29efd60

Browse files
committed
minor refactor new trajectory boilerplate
1 parent 76a8f44 commit 29efd60

File tree

6 files changed

+60
-50
lines changed

6 files changed

+60
-50
lines changed

src/Ext/Bullet/Body.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ DEFINE_HOOK(0x4665E9, BulletClass_DTOR, 0xA)
214214
GET(BulletClass*, pItem, ESI);
215215

216216
if (auto pTraj = BulletExt::ExtMap.Find(pItem)->Trajectory)
217-
DLLDelete(pTraj);
217+
delete pTraj;
218218

219219
BulletExt::ExtMap.Remove(pItem);
220220
return 0;

src/Ext/Bullet/Trajectories/BombardTrajectory.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ PhobosTrajectory* BombardTrajectoryType::CreateInstance() const
77
return new BombardTrajectory(this);
88
}
99

10+
template<typename T>
11+
void BombardTrajectoryType::Serialize(T& Stm)
12+
{
13+
Stm.Process(this->Height);
14+
}
15+
1016
bool BombardTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChange)
1117
{
1218
this->PhobosTrajectoryType::Load(Stm, false);
13-
Stm.Process(this->Height, false);
19+
this->Serialize(Stm);
1420
return true;
1521
}
1622

1723
bool BombardTrajectoryType::Save(PhobosStreamWriter& Stm) const
1824
{
1925
this->PhobosTrajectoryType::Save(Stm);
20-
Stm.Process(this->Height);
26+
const_cast<BombardTrajectoryType*>(this)->Serialize(Stm);
2127
return true;
2228
}
2329

@@ -26,14 +32,20 @@ void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
2632
this->Height = pINI->ReadDouble(pSection, "Trajectory.Bombard.Height", 0.0);
2733
}
2834

29-
bool BombardTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
35+
template<typename T>
36+
void BombardTrajectory::Serialize(T& Stm)
3037
{
31-
this->PhobosTrajectory::Load(Stm, false);
32-
3338
Stm
3439
.Process(this->IsFalling)
3540
.Process(this->Height)
3641
;
42+
}
43+
44+
bool BombardTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
45+
{
46+
this->PhobosTrajectory::Load(Stm, false);
47+
48+
this->Serialize(Stm);
3749

3850
return true;
3951
}
@@ -42,10 +54,7 @@ bool BombardTrajectory::Save(PhobosStreamWriter& Stm) const
4254
{
4355
this->PhobosTrajectory::Save(Stm);
4456

45-
Stm
46-
.Process(this->IsFalling)
47-
.Process(this->Height)
48-
;
57+
const_cast<BombardTrajectory*>(this)->Serialize(Stm);
4958

5059
return true;
5160
}

src/Ext/Bullet/Trajectories/BombardTrajectory.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ class BombardTrajectoryType final : public PhobosTrajectoryType
1616
virtual void Read(CCINIClass* const pINI, const char* pSection) override;
1717

1818
double Height;
19+
20+
private:
21+
template <typename T>
22+
void Serialize(T& Stm);
1923
};
2024

2125
class BombardTrajectory final : public PhobosTrajectory
2226
{
2327
public:
24-
BombardTrajectory() : PhobosTrajectory(TrajectoryFlag::Bombard)
25-
, IsFalling { false }
26-
, Height { 0.0 }
27-
{}
28+
BombardTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { }
2829

2930
BombardTrajectory(PhobosTrajectoryType const* pType) : PhobosTrajectory(TrajectoryFlag::Bombard)
3031
, IsFalling { false }
@@ -43,4 +44,8 @@ class BombardTrajectory final : public PhobosTrajectory
4344

4445
bool IsFalling;
4546
double Height;
47+
48+
private:
49+
template <typename T>
50+
void Serialize(T& Stm);
4651
};

src/Ext/Bullet/Trajectories/PhobosTrajectory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ PhobosTrajectory* PhobosTrajectory::LoadFromStream(PhobosStreamReader& Stm)
132132
switch (flag)
133133
{
134134
case TrajectoryFlag::Straight:
135-
pTraj = DLLCreate<StraightTrajectory>();
135+
pTraj = new StraightTrajectory(noinit_t {});
136136
break;
137137
case TrajectoryFlag::Bombard:
138-
pTraj = DLLCreate<BombardTrajectory>();
138+
pTraj = new BombardTrajectory(noinit_t {});
139139
break;
140140
default:
141141
return nullptr;

src/Ext/Bullet/Trajectories/StraightTrajectory.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,35 @@
22
#include <Ext/Bullet/Body.h>
33
#include <Ext/WeaponType/Body.h>
44

5-
bool StraightTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChange)
6-
{
7-
this->PhobosTrajectoryType::Load(Stm, false);
8-
9-
Stm
10-
.Process(this->DetonationDistance, false)
11-
.Process(this->ApplyRangeModifiers, false)
12-
.Process(this->TargetSnapDistance, false)
13-
.Process(this->PassThrough, false)
14-
;
15-
16-
return true;
17-
}
18-
195
PhobosTrajectory* StraightTrajectoryType::CreateInstance() const
206
{
217
return new StraightTrajectory(this);
228
}
239

24-
bool StraightTrajectoryType::Save(PhobosStreamWriter& Stm) const
10+
template<typename T>
11+
void StraightTrajectoryType::Serialize(T& Stm)
2512
{
26-
this->PhobosTrajectoryType::Save(Stm);
27-
2813
Stm
2914
.Process(this->DetonationDistance)
3015
.Process(this->ApplyRangeModifiers)
3116
.Process(this->TargetSnapDistance)
3217
.Process(this->PassThrough)
3318
;
19+
}
3420

21+
bool StraightTrajectoryType::Load(PhobosStreamReader& Stm, bool RegisterForChange)
22+
{
23+
this->PhobosTrajectoryType::Load(Stm, false);
24+
this->Serialize(Stm);
3525
return true;
3626
}
3727

28+
bool StraightTrajectoryType::Save(PhobosStreamWriter& Stm) const
29+
{
30+
this->PhobosTrajectoryType::Save(Stm);
31+
const_cast<StraightTrajectoryType*>(this)->Serialize(Stm);
32+
return true;
33+
}
3834

3935
void StraightTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
4036
{
@@ -46,17 +42,22 @@ void StraightTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
4642
this->PassThrough.Read(exINI, pSection, "Trajectory.Straight.PassThrough");
4743
}
4844

49-
bool StraightTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
45+
template<typename T>
46+
void StraightTrajectory::Serialize(T& Stm)
5047
{
51-
this->PhobosTrajectory::Load(Stm, false);
52-
5348
Stm
5449
.Process(this->DetonationDistance)
5550
.Process(this->TargetSnapDistance)
5651
.Process(this->PassThrough)
5752
.Process(this->FirerZPosition)
5853
.Process(this->TargetZPosition)
5954
;
55+
}
56+
57+
bool StraightTrajectory::Load(PhobosStreamReader& Stm, bool RegisterForChange)
58+
{
59+
this->PhobosTrajectory::Load(Stm, false);
60+
this->Serialize(Stm);
6061

6162
return true;
6263
}
@@ -65,13 +66,7 @@ bool StraightTrajectory::Save(PhobosStreamWriter& Stm) const
6566
{
6667
this->PhobosTrajectory::Save(Stm);
6768

68-
Stm
69-
.Process(this->DetonationDistance)
70-
.Process(this->TargetSnapDistance)
71-
.Process(this->PassThrough)
72-
.Process(this->FirerZPosition)
73-
.Process(this->TargetZPosition)
74-
;
69+
const_cast<StraightTrajectory*>(this)->Serialize(Stm);
7570

7671
return true;
7772
}

src/Ext/Bullet/Trajectories/StraightTrajectory.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ class StraightTrajectoryType final : public PhobosTrajectoryType
2121
Valueable<bool> ApplyRangeModifiers;
2222
Valueable<Leptons> TargetSnapDistance;
2323
Valueable<bool> PassThrough;
24+
25+
private:
26+
template <typename T>
27+
void Serialize(T& Stm);
2428
};
2529

2630
class StraightTrajectory final : public PhobosTrajectory
2731
{
2832
public:
29-
StraightTrajectory() : PhobosTrajectory(TrajectoryFlag::Straight)
30-
, DetonationDistance { Leptons(102) }
31-
, TargetSnapDistance { Leptons(128) }
32-
, PassThrough { false }
33-
, FirerZPosition { 0 }
34-
, TargetZPosition { 0 }
35-
{}
33+
StraightTrajectory(noinit_t) :PhobosTrajectory { noinit_t{} } { }
3634

3735
StraightTrajectory(PhobosTrajectoryType const* pType) : PhobosTrajectory(TrajectoryFlag::Straight)
3836
, DetonationDistance { Leptons(102) }
@@ -63,4 +61,7 @@ class StraightTrajectory final : public PhobosTrajectory
6361
int GetFirerZPosition(BulletClass* pBullet);
6462
int GetTargetZPosition(BulletClass* pBullet);
6563
bool ElevationDetonationCheck(BulletClass* pBullet);
64+
65+
template <typename T>
66+
void Serialize(T& Stm);
6667
};

0 commit comments

Comments
 (0)