@@ -64,8 +64,8 @@ int AEmitter::Create(const AEmitter& reference) {
6464 SetFlash (dynamic_cast <Attachable*>(reference.m_pFlash ->Clone ()));
6565 }
6666
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 ()) );
6969 }
7070 if (reference.m_EmissionSound ) {
7171 m_EmissionSound = dynamic_cast <SoundContainer*>(reference.m_EmissionSound ->Clone ());
@@ -105,8 +105,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
105105 StartPropertyList (return Attachable::ReadProperty (propName, reader));
106106
107107 MatchProperty (" AddEmission" , {
108- Emission emission;
109- reader >> emission;
108+ Emission* emission = new Emission () ;
109+ reader >> * emission;
110110 m_EmissionList.push_back (emission);
111111 });
112112 MatchProperty (" EmissionSound" , {
@@ -128,8 +128,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
128128 float ppm;
129129 reader >> ppm;
130130 // 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 ());
133133 }
134134 });
135135 MatchProperty (" NegativeThrottleMultiplier" , { reader >> m_NegativeThrottleMultiplier; });
@@ -140,8 +140,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
140140 int burstSize;
141141 reader >> burstSize;
142142 // 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 ()));
145145 }
146146 });
147147 MatchProperty (" BurstScale" , { reader >> m_BurstScale; });
@@ -166,9 +166,9 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
166166int AEmitter::Save (Writer& writer) const {
167167 Attachable::Save (writer);
168168
169- for (auto itr = m_EmissionList. begin (); itr != m_EmissionList. end (); ++itr ) {
169+ for (Emission* emission: m_EmissionList) {
170170 writer.NewProperty (" AddEmission" );
171- writer << *itr ;
171+ writer << *emission ;
172172 }
173173 writer.NewProperty (" EmissionSound" );
174174 writer << m_EmissionSound;
@@ -233,21 +233,27 @@ void AEmitter::Destroy(bool notInherited) {
233233 m_EmissionSound->Stop ();
234234 }
235235
236+ for (Emission* emission: m_EmissionList) {
237+ delete emission;
238+ }
239+
236240 delete m_EmissionSound;
237241 delete m_BurstSound;
238242 delete m_EndSound;
239243
240244 // m_BurstSound.Stop();
241245
242- if (!notInherited)
246+ if (!notInherited) {
243247 Attachable::Destroy ();
248+ }
244249 Clear ();
245250}
246251
247252void AEmitter::ResetEmissionTimers () {
248253 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+ }
251257}
252258
253259void AEmitter::EnableEmission (bool enable) {
@@ -268,22 +274,22 @@ float AEmitter::EstimateImpulse(bool burst) {
268274 float velMin, velMax, velRange, spread;
269275
270276 // 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) {
272278 // 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 ();
275281 float scale = 1 .0F ;
276282 if (burst) {
277- emissions *= (*eItr). GetBurstSize ();
283+ emissions *= emission-> GetBurstSize ();
278284 scale = m_BurstScale;
279285 }
280286
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
284290
285291 // 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;
287293 }
288294 }
289295
@@ -305,16 +311,16 @@ float AEmitter::EstimateImpulse(bool burst) {
305311
306312float AEmitter::GetTotalParticlesPerMinute () const {
307313 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 ;
310316 }
311317 return totalPPM;
312318}
313319
314320int AEmitter::GetTotalBurstSize () const {
315321 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 ;
318324 }
319325 return totalBurstSize;
320326}
@@ -382,8 +388,8 @@ void AEmitter::Update() {
382388 }
383389
384390 // 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 ();
387393 }
388394 // Update the distance attenuation
389395 else if (m_EmissionSound) {
@@ -415,11 +421,11 @@ void AEmitter::Update() {
415421 MovableObject* pParticle = 0 ;
416422 Vector parentVel, emitVel, pushImpulses;
417423 // Go through all emissions and emit them according to their respective rates
418- for (Emission& emission: m_EmissionList) {
424+ for (Emission* emission: m_EmissionList) {
419425 // Make sure the emissions only happen between the start time and end time
420- if (emission. IsEmissionTime ()) {
426+ if (emission-> IsEmissionTime ()) {
421427 // Apply the throttle factor to the emission rate
422- currentPPM = emission. GetRate () * throttleFactor;
428+ currentPPM = emission-> GetRate () * throttleFactor;
423429 int emissionCount = 0 ;
424430
425431 // Only do all this if the PPM is actually above zero
@@ -428,71 +434,71 @@ void AEmitter::Update() {
428434 SPE = 60.0 / currentPPM;
429435
430436 // Add the last elapsed time to the accumulator
431- emission. m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS ();
437+ emission-> m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS ();
432438
433439 // 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);
435441 // Deduct the about to be emitted emissions from the accumulator
436- emission. m_Accumulator -= emissionCount * SPE;
442+ emission-> m_Accumulator -= emissionCount * SPE;
437443
438- RTEAssert (emission. m_Accumulator >= 0 , " Emission accumulator negative!" );
444+ RTEAssert (emission-> m_Accumulator >= 0 , " Emission accumulator negative!" );
439445 } else {
440- emission. m_Accumulator = 0 ;
446+ emission-> m_Accumulator = 0 ;
441447 }
442448 float scale = 1 .0F ;
443449 // Add extra emissions if bursting.
444450 if (m_BurstTriggered) {
445- emissionCount += emission. GetBurstSize () * std::floor (throttleFactor);
451+ emissionCount += emission-> GetBurstSize () * std::floor (throttleFactor);
446452 scale = m_BurstScale;
447453 }
448454 emissionCountTotal += emissionCount;
449455 if (emissionCount > 0 ) {
450- int extraEmissions = emission. GetParticleCount () - 1 ;
456+ int extraEmissions = emission-> GetParticleCount () - 1 ;
451457 emissionCount += extraEmissions;
452458 }
453459 pParticle = 0 ;
454460 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 ();
457463
458464 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;
462468 // Make a copy after the reference particle
463- pParticle = dynamic_cast <MovableObject*>(emission. GetEmissionParticlePreset ()->Clone ());
469+ pParticle = dynamic_cast <MovableObject*>(emission-> GetEmissionParticlePreset ()->Clone ());
464470 // Set up its position and velocity according to the parameters of this.
465471 // Emission point offset not set
466472
467- if (emission. GetOffset ().IsZero ()) {
473+ if (emission-> GetOffset ().IsZero ()) {
468474 if (m_EmissionOffset.IsZero ()) {
469475 pParticle->SetPos (m_Pos);
470476 } else {
471477 pParticle->SetPos (m_Pos + RotateOffset (m_EmissionOffset));
472478 }
473479 } else {
474- pParticle->SetPos (m_Pos + RotateOffset (emission. GetOffset ()));
480+ pParticle->SetPos (m_Pos + RotateOffset (emission-> GetOffset ()));
475481 }
476482 // TODO: Optimize making the random angles!")
477483 emitVel.SetXY (velMin + RandomNum (0 .0F , velRange), 0 .0F );
478484 emitVel.RadRotate (m_EmitAngle.GetRadAngle () + spread * RandomNormalNum ());
479485 emitVel = RotateOffset (emitVel);
480486 pParticle->SetVel (parentVel + rotationalVel + emitVel);
481487 pParticle->SetRotAngle (emitVel.GetAbsRadAngle () + (m_HFlipped ? -c_PI : 0 ));
482- pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission. InheritsAngularVelocity ());
488+ pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission-> InheritsAngularVelocity ());
483489 pParticle->SetHFlipped (m_HFlipped);
484490
485491 // Scale the particle's lifetime based on life variation and throttle, as long as it's not 0
486492 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 ));
488494 pParticle->SetLifetime (std::max (static_cast <int >(pParticle->GetLifetime () * throttleFactor), 1 ));
489495 }
490496 pParticle->SetTeam (m_Team);
491497 pParticle->SetIgnoresTeamHits (true );
492498
493499 // Add to accumulative recoil impulse generated, F = m * a
494500 // If enabled, that is
495- if (emission. PushesEmitter () && (GetParent () || GetMass () > 0 )) {
501+ if (emission-> PushesEmitter () && (GetParent () || GetMass () > 0 )) {
496502 pushImpulses -= emitVel * pParticle->GetMass ();
497503 }
498504
0 commit comments