@@ -64,8 +64,8 @@ int AEmitter::Create(const AEmitter& reference) {
64
64
SetFlash (dynamic_cast <Attachable*>(reference.m_pFlash ->Clone ()));
65
65
}
66
66
67
- for (auto itr = reference.m_EmissionList . begin (); itr != reference. m_EmissionList . end (); ++itr ) {
68
- m_EmissionList.push_back (*itr );
67
+ for (Emission* emission: reference.m_EmissionList ) {
68
+ m_EmissionList.push_back (static_cast <Emission*>(emission-> Clone ()) );
69
69
}
70
70
if (reference.m_EmissionSound ) {
71
71
m_EmissionSound = dynamic_cast <SoundContainer*>(reference.m_EmissionSound ->Clone ());
@@ -105,8 +105,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
105
105
StartPropertyList (return Attachable::ReadProperty (propName, reader));
106
106
107
107
MatchProperty (" AddEmission" , {
108
- Emission emission;
109
- reader >> emission;
108
+ Emission* emission = new Emission () ;
109
+ reader >> * emission;
110
110
m_EmissionList.push_back (emission);
111
111
});
112
112
MatchProperty (" EmissionSound" , {
@@ -128,8 +128,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
128
128
float ppm;
129
129
reader >> ppm;
130
130
// Go through all emissions and set the rate so that it emulates the way it used to work, for mod backwards compatibility.
131
- for (Emission& emission: m_EmissionList) {
132
- emission. m_PPM = ppm / static_cast <float >(m_EmissionList.size ());
131
+ for (Emission* emission: m_EmissionList) {
132
+ emission-> m_PPM = ppm / static_cast <float >(m_EmissionList.size ());
133
133
}
134
134
});
135
135
MatchProperty (" NegativeThrottleMultiplier" , { reader >> m_NegativeThrottleMultiplier; });
@@ -140,8 +140,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
140
140
int burstSize;
141
141
reader >> burstSize;
142
142
// Go through all emissions and set the rate so that it emulates the way it used to work, for mod backwards compatibility.
143
- for (Emission& emission: m_EmissionList) {
144
- emission. m_BurstSize = std::ceil (static_cast <float >(burstSize) / static_cast <float >(m_EmissionList.size ()));
143
+ for (Emission* emission: m_EmissionList) {
144
+ emission-> m_BurstSize = std::ceil (static_cast <float >(burstSize) / static_cast <float >(m_EmissionList.size ()));
145
145
}
146
146
});
147
147
MatchProperty (" BurstScale" , { reader >> m_BurstScale; });
@@ -166,9 +166,9 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
166
166
int AEmitter::Save (Writer& writer) const {
167
167
Attachable::Save (writer);
168
168
169
- for (auto itr = m_EmissionList. begin (); itr != m_EmissionList. end (); ++itr ) {
169
+ for (Emission* emission: m_EmissionList) {
170
170
writer.NewProperty (" AddEmission" );
171
- writer << *itr ;
171
+ writer << *emission ;
172
172
}
173
173
writer.NewProperty (" EmissionSound" );
174
174
writer << m_EmissionSound;
@@ -233,21 +233,27 @@ void AEmitter::Destroy(bool notInherited) {
233
233
m_EmissionSound->Stop ();
234
234
}
235
235
236
+ for (Emission* emission: m_EmissionList) {
237
+ delete emission;
238
+ }
239
+
236
240
delete m_EmissionSound;
237
241
delete m_BurstSound;
238
242
delete m_EndSound;
239
243
240
244
// m_BurstSound.Stop();
241
245
242
- if (!notInherited)
246
+ if (!notInherited) {
243
247
Attachable::Destroy ();
248
+ }
244
249
Clear ();
245
250
}
246
251
247
252
void AEmitter::ResetEmissionTimers () {
248
253
m_LastEmitTmr.Reset ();
249
- for (auto eItr = m_EmissionList.begin (); eItr != m_EmissionList.end (); ++eItr)
250
- (*eItr).ResetEmissionTimers ();
254
+ for (Emission* emission: m_EmissionList) {
255
+ emission->ResetEmissionTimers ();
256
+ }
251
257
}
252
258
253
259
void AEmitter::EnableEmission (bool enable) {
@@ -268,22 +274,22 @@ float AEmitter::EstimateImpulse(bool burst) {
268
274
float velMin, velMax, velRange, spread;
269
275
270
276
// Go through all emissions and emit them according to their respective rates
271
- for (auto eItr = m_EmissionList. begin (); eItr != m_EmissionList. end (); ++eItr ) {
277
+ for (Emission* emission: m_EmissionList) {
272
278
// Only check emissions that push the emitter
273
- if ((*eItr). PushesEmitter ()) {
274
- float emissions = ((*eItr). GetRate () / 60 .0f ) * g_TimerMan.GetDeltaTimeSecs ();
279
+ if (emission-> PushesEmitter ()) {
280
+ float emissions = (emission-> GetRate () / 60 .0f ) * g_TimerMan.GetDeltaTimeSecs ();
275
281
float scale = 1 .0F ;
276
282
if (burst) {
277
- emissions *= (*eItr). GetBurstSize ();
283
+ emissions *= emission-> GetBurstSize ();
278
284
scale = m_BurstScale;
279
285
}
280
286
281
- velMin = (*eItr). GetMinVelocity () * scale;
282
- velRange = ((*eItr). GetMaxVelocity () - (*eItr). GetMinVelocity ()) * 0 .5F * scale;
283
- spread = (std::max (static_cast <float >(c_PI) - (*eItr). GetSpread (), 0 .0F ) / c_PI) * scale; // A large spread will cause the forces to cancel eachother out
287
+ velMin = emission-> GetMinVelocity () * scale;
288
+ velRange = (emission-> GetMaxVelocity () - emission-> GetMinVelocity ()) * 0 .5F * scale;
289
+ spread = (std::max (static_cast <float >(c_PI) - emission-> GetSpread (), 0 .0F ) / c_PI) * scale; // A large spread will cause the forces to cancel eachother out
284
290
285
291
// Add to accumulative recoil impulse generated, F = m * a.
286
- impulse += (velMin + velRange) * spread * (*eItr). m_pEmission ->GetMass () * emissions;
292
+ impulse += (velMin + velRange) * spread * emission-> m_pEmission ->GetMass () * emissions;
287
293
}
288
294
}
289
295
@@ -305,16 +311,16 @@ float AEmitter::EstimateImpulse(bool burst) {
305
311
306
312
float AEmitter::GetTotalParticlesPerMinute () const {
307
313
float totalPPM = 0 ;
308
- for (const Emission& emission: m_EmissionList) {
309
- totalPPM += emission. m_PPM ;
314
+ for (const Emission* emission: m_EmissionList) {
315
+ totalPPM += emission-> m_PPM ;
310
316
}
311
317
return totalPPM;
312
318
}
313
319
314
320
int AEmitter::GetTotalBurstSize () const {
315
321
int totalBurstSize = 0 ;
316
- for (const Emission& emission: m_EmissionList) {
317
- totalBurstSize += emission. m_BurstSize ;
322
+ for (const Emission* emission: m_EmissionList) {
323
+ totalBurstSize += emission-> m_BurstSize ;
318
324
}
319
325
return totalBurstSize;
320
326
}
@@ -382,8 +388,8 @@ void AEmitter::Update() {
382
388
}
383
389
384
390
// Reset the timers of all emissions so they will start/stop at the correct relative offsets from now
385
- for (Emission& emission: m_EmissionList)
386
- emission. ResetEmissionTimers ();
391
+ for (Emission* emission: m_EmissionList)
392
+ emission-> ResetEmissionTimers ();
387
393
}
388
394
// Update the distance attenuation
389
395
else if (m_EmissionSound) {
@@ -415,11 +421,11 @@ void AEmitter::Update() {
415
421
MovableObject* pParticle = 0 ;
416
422
Vector parentVel, emitVel, pushImpulses;
417
423
// Go through all emissions and emit them according to their respective rates
418
- for (Emission& emission: m_EmissionList) {
424
+ for (Emission* emission: m_EmissionList) {
419
425
// Make sure the emissions only happen between the start time and end time
420
- if (emission. IsEmissionTime ()) {
426
+ if (emission-> IsEmissionTime ()) {
421
427
// Apply the throttle factor to the emission rate
422
- currentPPM = emission. GetRate () * throttleFactor;
428
+ currentPPM = emission-> GetRate () * throttleFactor;
423
429
int emissionCount = 0 ;
424
430
425
431
// Only do all this if the PPM is actually above zero
@@ -428,71 +434,71 @@ void AEmitter::Update() {
428
434
SPE = 60.0 / currentPPM;
429
435
430
436
// Add the last elapsed time to the accumulator
431
- emission. m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS ();
437
+ emission-> m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS ();
432
438
433
439
// Now figure how many full emissions can fit in the current accumulator
434
- emissionCount = std::floor (emission. m_Accumulator / SPE);
440
+ emissionCount = std::floor (emission-> m_Accumulator / SPE);
435
441
// Deduct the about to be emitted emissions from the accumulator
436
- emission. m_Accumulator -= emissionCount * SPE;
442
+ emission-> m_Accumulator -= emissionCount * SPE;
437
443
438
- RTEAssert (emission. m_Accumulator >= 0 , " Emission accumulator negative!" );
444
+ RTEAssert (emission-> m_Accumulator >= 0 , " Emission accumulator negative!" );
439
445
} else {
440
- emission. m_Accumulator = 0 ;
446
+ emission-> m_Accumulator = 0 ;
441
447
}
442
448
float scale = 1 .0F ;
443
449
// Add extra emissions if bursting.
444
450
if (m_BurstTriggered) {
445
- emissionCount += emission. GetBurstSize () * std::floor (throttleFactor);
451
+ emissionCount += emission-> GetBurstSize () * std::floor (throttleFactor);
446
452
scale = m_BurstScale;
447
453
}
448
454
emissionCountTotal += emissionCount;
449
455
if (emissionCount > 0 ) {
450
- int extraEmissions = emission. GetParticleCount () - 1 ;
456
+ int extraEmissions = emission-> GetParticleCount () - 1 ;
451
457
emissionCount += extraEmissions;
452
458
}
453
459
pParticle = 0 ;
454
460
emitVel.Reset ();
455
- parentVel = pRootParent->GetVel () * emission. InheritsVelocity ();
456
- Vector rotationalVel = (((RotateOffset (emission. GetOffset ()) + (m_Pos - pRootParent->GetPos ())) * pRootParent->GetAngularVel ()).GetPerpendicular () / c_PPM) * emission. InheritsVelocity ();
461
+ parentVel = pRootParent->GetVel () * emission-> InheritsVelocity ();
462
+ Vector rotationalVel = (((RotateOffset (emission-> GetOffset ()) + (m_Pos - pRootParent->GetPos ())) * pRootParent->GetAngularVel ()).GetPerpendicular () / c_PPM) * emission-> InheritsVelocity ();
457
463
458
464
for (int i = 0 ; i < emissionCount; ++i) {
459
- velMin = emission. GetMinVelocity () * scale;
460
- velRange = (emission. GetMaxVelocity () - emission. GetMinVelocity ()) * scale;
461
- spread = emission. GetSpread () * scale;
465
+ velMin = emission-> GetMinVelocity () * scale;
466
+ velRange = (emission-> GetMaxVelocity () - emission-> GetMinVelocity ()) * scale;
467
+ spread = emission-> GetSpread () * scale;
462
468
// Make a copy after the reference particle
463
- pParticle = dynamic_cast <MovableObject*>(emission. GetEmissionParticlePreset ()->Clone ());
469
+ pParticle = dynamic_cast <MovableObject*>(emission-> GetEmissionParticlePreset ()->Clone ());
464
470
// Set up its position and velocity according to the parameters of this.
465
471
// Emission point offset not set
466
472
467
- if (emission. GetOffset ().IsZero ()) {
473
+ if (emission-> GetOffset ().IsZero ()) {
468
474
if (m_EmissionOffset.IsZero ()) {
469
475
pParticle->SetPos (m_Pos);
470
476
} else {
471
477
pParticle->SetPos (m_Pos + RotateOffset (m_EmissionOffset));
472
478
}
473
479
} else {
474
- pParticle->SetPos (m_Pos + RotateOffset (emission. GetOffset ()));
480
+ pParticle->SetPos (m_Pos + RotateOffset (emission-> GetOffset ()));
475
481
}
476
482
// TODO: Optimize making the random angles!")
477
483
emitVel.SetXY (velMin + RandomNum (0 .0F , velRange), 0 .0F );
478
484
emitVel.RadRotate (m_EmitAngle.GetRadAngle () + spread * RandomNormalNum ());
479
485
emitVel = RotateOffset (emitVel);
480
486
pParticle->SetVel (parentVel + rotationalVel + emitVel);
481
487
pParticle->SetRotAngle (emitVel.GetAbsRadAngle () + (m_HFlipped ? -c_PI : 0 ));
482
- pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission. InheritsAngularVelocity ());
488
+ pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission-> InheritsAngularVelocity ());
483
489
pParticle->SetHFlipped (m_HFlipped);
484
490
485
491
// Scale the particle's lifetime based on life variation and throttle, as long as it's not 0
486
492
if (pParticle->GetLifetime () != 0 ) {
487
- pParticle->SetLifetime (std::max (static_cast <int >(static_cast <float >(pParticle->GetLifetime ()) * (1 .0F + (emission. GetLifeVariation () * RandomNormalNum ()))), 1 ));
493
+ pParticle->SetLifetime (std::max (static_cast <int >(static_cast <float >(pParticle->GetLifetime ()) * (1 .0F + (emission-> GetLifeVariation () * RandomNormalNum ()))), 1 ));
488
494
pParticle->SetLifetime (std::max (static_cast <int >(pParticle->GetLifetime () * throttleFactor), 1 ));
489
495
}
490
496
pParticle->SetTeam (m_Team);
491
497
pParticle->SetIgnoresTeamHits (true );
492
498
493
499
// Add to accumulative recoil impulse generated, F = m * a
494
500
// If enabled, that is
495
- if (emission. PushesEmitter () && (GetParent () || GetMass () > 0 )) {
501
+ if (emission-> PushesEmitter () && (GetParent () || GetMass () > 0 )) {
496
502
pushImpulses -= emitVel * pParticle->GetMass ();
497
503
}
498
504
0 commit comments