Skip to content

Commit 3e6f48d

Browse files
committed
Fix everything after a quick look at how to actually use pointers.
1 parent 0dcedca commit 3e6f48d

File tree

13 files changed

+111
-109
lines changed

13 files changed

+111
-109
lines changed

Source/Entities/AEmitter.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ int AEmitter::Create(const AEmitter& reference) {
6464
SetFlash(dynamic_cast<Attachable*>(reference.m_pFlash->Clone()));
6565
}
6666

67-
for (const Emission* emission: reference.m_EmissionList) {
68-
m_EmissionList.push_back(dynamic_cast<Emission*>(emission->Clone()));
67+
for (Emission* emission: reference.m_EmissionList) {
68+
m_EmissionList.push_back(static_cast<Emission*>(emission->Clone()));
6969
}
7070
if (reference.m_EmissionSound) {
7171
m_EmissionSound = dynamic_cast<SoundContainer*>(reference.m_EmissionSound->Clone());
@@ -106,10 +106,10 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
106106

107107
MatchProperty("AddEmission", {
108108
Entity* readerEntity = g_PresetMan.ReadReflectedPreset(reader);
109-
if (Emission* readerEmission = dynamic_cast<Emission*>(readerEntity)) {
110-
m_EmissionList.push_back(readerEmission);
109+
if (Emission* readerAttachable = dynamic_cast<Emission*>(readerEntity)) {
110+
m_EmissionList.push_back(readerAttachable);
111111
} else {
112-
reader.ReportError("Tried to AddEmission a non-Emission type!");
112+
reader.ReportError("Tried to AddAttachable a non-Attachable type!");
113113
}
114114
});
115115
MatchProperty("EmissionSound", {
@@ -132,7 +132,7 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
132132
reader >> ppm;
133133
// Go through all emissions and set the rate so that it emulates the way it used to work, for mod backwards compatibility.
134134
for (Emission* emission: m_EmissionList) {
135-
emission->SetRate(ppm / static_cast<float>(m_EmissionList.size()));
135+
emission->m_PPM = ppm / static_cast<float>(m_EmissionList.size());
136136
}
137137
});
138138
MatchProperty("NegativeThrottleMultiplier", { reader >> m_NegativeThrottleMultiplier; });
@@ -144,7 +144,7 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
144144
reader >> burstSize;
145145
// Go through all emissions and set the rate so that it emulates the way it used to work, for mod backwards compatibility.
146146
for (Emission* emission: m_EmissionList) {
147-
emission->SetBurstSize(std::ceil(static_cast<float>(burstSize) / static_cast<float>(m_EmissionList.size())));
147+
emission->m_BurstSize = std::ceil(static_cast<float>(burstSize) / static_cast<float>(m_EmissionList.size()));
148148
}
149149
});
150150
MatchProperty("BurstScale", { reader >> m_BurstScale; });
@@ -169,9 +169,9 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
169169
int AEmitter::Save(Writer& writer) const {
170170
Attachable::Save(writer);
171171

172-
for (auto itr = m_EmissionList.begin(); itr != m_EmissionList.end(); ++itr) {
172+
for (Emission* emission: m_EmissionList) {
173173
writer.NewProperty("AddEmission");
174-
writer << *itr;
174+
writer << *emission;
175175
}
176176
writer.NewProperty("EmissionSound");
177177
writer << m_EmissionSound;
@@ -236,8 +236,8 @@ void AEmitter::Destroy(bool notInherited) {
236236
m_EmissionSound->Stop();
237237
}
238238

239-
for (auto eItr = m_EmissionList.begin(); eItr != m_EmissionList.end(); ++eItr) {
240-
delete (*eItr);
239+
for (Emission* emission: m_EmissionList) {
240+
delete emission;
241241
}
242242

243243
delete m_EmissionSound;
@@ -246,15 +246,17 @@ void AEmitter::Destroy(bool notInherited) {
246246

247247
// m_BurstSound.Stop();
248248

249-
if (!notInherited)
249+
if (!notInherited) {
250250
Attachable::Destroy();
251+
}
251252
Clear();
252253
}
253254

254255
void AEmitter::ResetEmissionTimers() {
255256
m_LastEmitTmr.Reset();
256-
for (Emission* emission: m_EmissionList)
257+
for (Emission* emission: m_EmissionList) {
257258
emission->ResetEmissionTimers();
259+
}
258260
}
259261

260262
void AEmitter::EnableEmission(bool enable) {
@@ -275,7 +277,7 @@ float AEmitter::EstimateImpulse(bool burst) {
275277
float velMin, velMax, velRange, spread;
276278

277279
// Go through all emissions and emit them according to their respective rates
278-
for (const Emission* emission: m_EmissionList) {
280+
for (Emission* emission: m_EmissionList) {
279281
// Only check emissions that push the emitter
280282
if (emission->PushesEmitter()) {
281283
float emissions = (emission->GetRate() / 60.0f) * g_TimerMan.GetDeltaTimeSecs();
@@ -313,15 +315,15 @@ float AEmitter::EstimateImpulse(bool burst) {
313315
float AEmitter::GetTotalParticlesPerMinute() const {
314316
float totalPPM = 0;
315317
for (const Emission* emission: m_EmissionList) {
316-
totalPPM += emission->GetRate();
318+
totalPPM += emission->m_PPM;
317319
}
318320
return totalPPM;
319321
}
320322

321323
int AEmitter::GetTotalBurstSize() const {
322324
int totalBurstSize = 0;
323325
for (const Emission* emission: m_EmissionList) {
324-
totalBurstSize += emission->GetBurstSize();
326+
totalBurstSize += emission->m_BurstSize;
325327
}
326328
return totalBurstSize;
327329
}
@@ -435,16 +437,16 @@ void AEmitter::Update() {
435437
SPE = 60.0 / currentPPM;
436438

437439
// Add the last elapsed time to the accumulator
438-
emission->SetAccumulator(emission->GetAccumulator() + m_LastEmitTmr.GetElapsedSimTimeS());
440+
emission->m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS();
439441

440442
// Now figure how many full emissions can fit in the current accumulator
441-
emissionCount = std::floor(emission->GetAccumulator() / SPE);
443+
emissionCount = std::floor(emission->m_Accumulator / SPE);
442444
// Deduct the about to be emitted emissions from the accumulator
443-
emission->SetAccumulator(emission->GetAccumulator() - emissionCount * SPE);
445+
emission->m_Accumulator -= emissionCount * SPE;
444446

445-
RTEAssert(emission->GetAccumulator() >= 0, "Emission accumulator negative!");
447+
RTEAssert(emission->m_Accumulator >= 0, "Emission accumulator negative!");
446448
} else {
447-
emission->SetAccumulator(0);
449+
emission->m_Accumulator = 0;
448450
}
449451
float scale = 1.0F;
450452
// Add extra emissions if bursting.
@@ -459,8 +461,8 @@ void AEmitter::Update() {
459461
}
460462
pParticle = 0;
461463
emitVel.Reset();
462-
Vector rotationalVel = (((RotateOffset(emission->GetOffset()) + (m_Pos - pRootParent->GetPos())) * pRootParent->GetAngularVel()).GetPerpendicular() / c_PPM) * emission->InheritsVelocity();
463464
parentVel = pRootParent->GetVel() * emission->InheritsVelocity();
465+
Vector rotationalVel = (((RotateOffset(emission->GetOffset()) + (m_Pos - pRootParent->GetPos())) * pRootParent->GetAngularVel()).GetPerpendicular() / c_PPM) * emission->InheritsVelocity();
464466

465467
for (int i = 0; i < emissionCount; ++i) {
466468
velMin = emission->GetMinVelocity() * scale;
@@ -500,7 +502,7 @@ void AEmitter::Update() {
500502
// Add to accumulative recoil impulse generated, F = m * a
501503
// If enabled, that is
502504
if (emission->PushesEmitter() && (GetParent() || GetMass() > 0)) {
503-
pushImpulses += -emitVel * pParticle->GetMass();
505+
pushImpulses -= emitVel * pParticle->GetMass();
504506
}
505507

506508
// Set the emitted particle to not hit this emitter's parent, if applicable

Source/Entities/AEmitter.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ namespace RTE {
7777
/// @return The combined burst size of all Emissions in this AEmitter.
7878
int GetTotalBurstSize() const;
7979

80-
/// Gets the list of Emissions of this AEmitter.
81-
/// @return The list of Emissions of this AEmitter.
82-
const std::vector<Emission*>& GetEmissionList() const { return m_EmissionList; }
83-
8480
/// Gets the scale factor that will be applied to the regular spread and
8581
/// emission velocity to get the burst particle parameters.
8682
/// @return The scale factor.
@@ -370,8 +366,8 @@ namespace RTE {
370366
// Member variables
371367
static Entity::ClassInfo m_sClass;
372368

373-
// The list of pointers to MO emission objects
374-
std::vector<Emission*> m_EmissionList;
369+
// The list of MO instances that get emitted
370+
std::list<Emission*> m_EmissionList;
375371
// Sounds
376372
SoundContainer* m_EmissionSound;
377373
SoundContainer* m_BurstSound;

Source/Entities/Emission.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,6 @@ namespace RTE {
146146
/// @param newParticleCount The new number of particles emitted per emission.
147147
void SetParticleCount(int newParticleCount) { m_ParticleCount = newParticleCount; }
148148

149-
/// Returns the current time accumulation of this emitter.
150-
/// @return the current time accumulation of this emitter.
151-
double GetAccumulator() const { return m_Accumulator; }
152-
153-
/// Changes time accumulation of this emitter.
154-
/// @param increment The time to be added to the accumulation.
155-
void SetAccumulator(double increment) { m_Accumulator += increment; }
156-
157149
/// Protected member variable and method declarations
158150
protected:
159151
// Member variables

Source/Entities/MOSRotating.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace RTE {
163163

164164
/// Returns whether this MOSprite is currently under the effects of
165165
/// recoil.
166-
bool IsRecoiled() const { return m_Recoiled; }
166+
bool IsRecoiled() { return m_Recoiled; }
167167

168168
/// Sets whether or not this MOSRotating should check for deep penetrations
169169
/// the terrain or not.

Source/Entities/PEmitter.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ int PEmitter::Create() {
5858
int PEmitter::Create(const PEmitter& reference) {
5959
MOSParticle::Create(reference);
6060

61-
for (const Emission* emission: reference.m_EmissionList) {
62-
m_EmissionList.push_back(dynamic_cast<Emission*>(emission->Clone()));
61+
for (Emission* emission: reference.m_EmissionList) {
62+
m_EmissionList.push_back(static_cast<Emission*>(emission->Clone()));
6363
}
6464
m_EmissionSound = reference.m_EmissionSound;
6565
m_BurstSound = reference.m_BurstSound;
@@ -91,12 +91,12 @@ int PEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
9191

9292
MatchProperty("AddEmission", {
9393
Entity* readerEntity = g_PresetMan.ReadReflectedPreset(reader);
94-
if (Emission* readerEmission = dynamic_cast<Emission*>(readerEntity)) {
95-
m_EmissionList.push_back(readerEmission);
94+
if (Emission* readerAttachable = dynamic_cast<Emission*>(readerEntity)) {
95+
m_EmissionList.push_back(readerAttachable);
9696
} else {
97-
reader.ReportError("Tried to AddEmission a non-Emission type!");
97+
reader.ReportError("Tried to AddAttachable a non-Attachable type!");
9898
}
99-
});
99+
});
100100
MatchProperty("EmissionSound", { reader >> m_EmissionSound; });
101101
MatchProperty("BurstSound", { reader >> m_BurstSound; });
102102
MatchProperty("EndSound", { reader >> m_EndSound; });
@@ -139,9 +139,9 @@ int PEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
139139
int PEmitter::Save(Writer& writer) const {
140140
MOSParticle::Save(writer);
141141

142-
for (auto itr = m_EmissionList.begin(); itr != m_EmissionList.end(); ++itr) {
142+
for (Emission* emission: m_EmissionList) {
143143
writer.NewProperty("AddEmission");
144-
writer << *itr;
144+
writer << *emission;
145145
}
146146
writer.NewProperty("EmissionSound");
147147
writer << m_EmissionSound;
@@ -191,10 +191,11 @@ int PEmitter::Save(Writer& writer) const {
191191

192192
void PEmitter::Destroy(bool notInherited) {
193193
// Stop playback of sounds gracefully
194-
if (m_EmissionSound.IsBeingPlayed())
194+
if (m_EmissionSound.IsBeingPlayed()) {
195195
m_EndSound.Play(m_Pos);
196-
else
196+
} else {
197197
m_EndSound.Stop();
198+
}
198199

199200
for (Emission* emission: m_EmissionList) {
200201
delete emission;

Source/Entities/PEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ namespace RTE {
280280
static Entity::ClassInfo m_sClass;
281281

282282
// The list of MO instances that get emitted
283-
std::vector<Emission*> m_EmissionList;
283+
std::list<Emission*> m_EmissionList;
284284
// Sounds
285285
SoundContainer m_EmissionSound;
286286
SoundContainer m_BurstSound;

0 commit comments

Comments
 (0)