@@ -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 (const Emission* emission: reference.m_EmissionList ) {
68+ m_EmissionList.push_back (dynamic_cast <Emission*>(emission-> Clone ()) );
6969 }
7070 if (reference.m_EmissionSound ) {
7171 m_EmissionSound = dynamic_cast <SoundContainer*>(reference.m_EmissionSound ->Clone ());
@@ -105,9 +105,12 @@ 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;
110- m_EmissionList.push_back (emission);
108+ Entity* readerEntity = g_PresetMan.ReadReflectedPreset (reader);
109+ if (Emission* readerEmission = dynamic_cast <Emission*>(readerEntity)) {
110+ m_EmissionList.push_back (readerEmission);
111+ } else {
112+ reader.ReportError (" Tried to AddEmission a non-Emission type!" );
113+ }
111114 });
112115 MatchProperty (" EmissionSound" , {
113116 m_EmissionSound = new SoundContainer;
@@ -128,8 +131,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
128131 float ppm;
129132 reader >> ppm;
130133 // 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 ());
134+ for (Emission* emission: m_EmissionList) {
135+ emission-> SetRate ( ppm / static_cast <float >(m_EmissionList.size () ));
133136 }
134137 });
135138 MatchProperty (" NegativeThrottleMultiplier" , { reader >> m_NegativeThrottleMultiplier; });
@@ -140,8 +143,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
140143 int burstSize;
141144 reader >> burstSize;
142145 // 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 ()));
146+ for (Emission* emission: m_EmissionList) {
147+ emission-> SetBurstSize ( std::ceil (static_cast <float >(burstSize) / static_cast <float >(m_EmissionList.size () )));
145148 }
146149 });
147150 MatchProperty (" BurstScale" , { reader >> m_BurstScale; });
@@ -233,6 +236,10 @@ void AEmitter::Destroy(bool notInherited) {
233236 m_EmissionSound->Stop ();
234237 }
235238
239+ for (auto eItr = m_EmissionList.begin (); eItr != m_EmissionList.end (); ++eItr) {
240+ delete (*eItr);
241+ }
242+
236243 delete m_EmissionSound;
237244 delete m_BurstSound;
238245 delete m_EndSound;
@@ -246,8 +253,8 @@ void AEmitter::Destroy(bool notInherited) {
246253
247254void AEmitter::ResetEmissionTimers () {
248255 m_LastEmitTmr.Reset ();
249- for (auto eItr = m_EmissionList. begin (); eItr != m_EmissionList. end (); ++eItr )
250- (*eItr). ResetEmissionTimers ();
256+ for (Emission* emission: m_EmissionList)
257+ emission-> ResetEmissionTimers ();
251258}
252259
253260void AEmitter::EnableEmission (bool enable) {
@@ -268,22 +275,22 @@ float AEmitter::EstimateImpulse(bool burst) {
268275 float velMin, velMax, velRange, spread;
269276
270277 // Go through all emissions and emit them according to their respective rates
271- for (auto eItr = m_EmissionList. begin (); eItr != m_EmissionList. end (); ++eItr ) {
278+ for (const Emission* emission: m_EmissionList) {
272279 // Only check emissions that push the emitter
273- if ((*eItr). PushesEmitter ()) {
274- float emissions = ((*eItr). GetRate () / 60 .0f ) * g_TimerMan.GetDeltaTimeSecs ();
280+ if (emission-> PushesEmitter ()) {
281+ float emissions = (emission-> GetRate () / 60 .0f ) * g_TimerMan.GetDeltaTimeSecs ();
275282 float scale = 1 .0F ;
276283 if (burst) {
277- emissions *= (*eItr). GetBurstSize ();
284+ emissions *= emission-> GetBurstSize ();
278285 scale = m_BurstScale;
279286 }
280287
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
288+ velMin = emission-> GetMinVelocity () * scale;
289+ velRange = (emission-> GetMaxVelocity () - emission-> GetMinVelocity ()) * 0 .5F * scale;
290+ 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
284291
285292 // Add to accumulative recoil impulse generated, F = m * a.
286- impulse += (velMin + velRange) * spread * (*eItr). m_pEmission ->GetMass () * emissions;
293+ impulse += (velMin + velRange) * spread * emission-> m_pEmission ->GetMass () * emissions;
287294 }
288295 }
289296
@@ -305,16 +312,16 @@ float AEmitter::EstimateImpulse(bool burst) {
305312
306313float AEmitter::GetTotalParticlesPerMinute () const {
307314 float totalPPM = 0 ;
308- for (const Emission& emission: m_EmissionList) {
309- totalPPM += emission. m_PPM ;
315+ for (const Emission* emission: m_EmissionList) {
316+ totalPPM += emission-> GetRate () ;
310317 }
311318 return totalPPM;
312319}
313320
314321int AEmitter::GetTotalBurstSize () const {
315322 int totalBurstSize = 0 ;
316- for (const Emission& emission: m_EmissionList) {
317- totalBurstSize += emission. m_BurstSize ;
323+ for (const Emission* emission: m_EmissionList) {
324+ totalBurstSize += emission-> GetBurstSize () ;
318325 }
319326 return totalBurstSize;
320327}
@@ -382,8 +389,8 @@ void AEmitter::Update() {
382389 }
383390
384391 // 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 ();
392+ for (Emission* emission: m_EmissionList)
393+ emission-> ResetEmissionTimers ();
387394 }
388395 // Update the distance attenuation
389396 else if (m_EmissionSound) {
@@ -415,11 +422,11 @@ void AEmitter::Update() {
415422 MovableObject* pParticle = 0 ;
416423 Vector parentVel, emitVel, pushImpulses;
417424 // Go through all emissions and emit them according to their respective rates
418- for (Emission& emission: m_EmissionList) {
425+ for (Emission* emission: m_EmissionList) {
419426 // Make sure the emissions only happen between the start time and end time
420- if (emission. IsEmissionTime ()) {
427+ if (emission-> IsEmissionTime ()) {
421428 // Apply the throttle factor to the emission rate
422- currentPPM = emission. GetRate () * throttleFactor;
429+ currentPPM = emission-> GetRate () * throttleFactor;
423430 int emissionCount = 0 ;
424431
425432 // Only do all this if the PPM is actually above zero
@@ -428,72 +435,72 @@ void AEmitter::Update() {
428435 SPE = 60.0 / currentPPM;
429436
430437 // Add the last elapsed time to the accumulator
431- emission. m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS ();
438+ emission-> SetAccumulator (emission-> GetAccumulator () + m_LastEmitTmr.GetElapsedSimTimeS () );
432439
433440 // Now figure how many full emissions can fit in the current accumulator
434- emissionCount = std::floor (emission. m_Accumulator / SPE);
441+ emissionCount = std::floor (emission-> GetAccumulator () / SPE);
435442 // Deduct the about to be emitted emissions from the accumulator
436- emission. m_Accumulator -= emissionCount * SPE;
443+ emission-> SetAccumulator (emission-> GetAccumulator () - emissionCount * SPE) ;
437444
438- RTEAssert (emission. m_Accumulator >= 0 , " Emission accumulator negative!" );
445+ RTEAssert (emission-> GetAccumulator () >= 0 , " Emission accumulator negative!" );
439446 } else {
440- emission. m_Accumulator = 0 ;
447+ emission-> SetAccumulator ( 0 ) ;
441448 }
442449 float scale = 1 .0F ;
443450 // Add extra emissions if bursting.
444451 if (m_BurstTriggered) {
445- emissionCount += emission. GetBurstSize () * std::floor (throttleFactor);
452+ emissionCount += emission-> GetBurstSize () * std::floor (throttleFactor);
446453 scale = m_BurstScale;
447454 }
448455 emissionCountTotal += emissionCount;
449456 if (emissionCount > 0 ) {
450- int extraEmissions = emission. GetParticleCount () - 1 ;
457+ int extraEmissions = emission-> GetParticleCount () - 1 ;
451458 emissionCount += extraEmissions;
452459 }
453460 pParticle = 0 ;
454461 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 ();
462+ Vector rotationalVel = ((( RotateOffset (emission-> GetOffset ()) + (m_Pos - pRootParent->GetPos ())) * pRootParent-> GetAngularVel ()). GetPerpendicular () / c_PPM) * emission-> InheritsVelocity ();
463+ parentVel = pRootParent->GetVel () * emission-> InheritsVelocity ();
457464
458465 for (int i = 0 ; i < emissionCount; ++i) {
459- velMin = emission. GetMinVelocity () * scale;
460- velRange = (emission. GetMaxVelocity () - emission. GetMinVelocity ()) * scale;
461- spread = emission. GetSpread () * scale;
466+ velMin = emission-> GetMinVelocity () * scale;
467+ velRange = (emission-> GetMaxVelocity () - emission-> GetMinVelocity ()) * scale;
468+ spread = emission-> GetSpread () * scale;
462469 // Make a copy after the reference particle
463- pParticle = dynamic_cast <MovableObject*>(emission. GetEmissionParticlePreset ()->Clone ());
470+ pParticle = dynamic_cast <MovableObject*>(emission-> GetEmissionParticlePreset ()->Clone ());
464471 // Set up its position and velocity according to the parameters of this.
465472 // Emission point offset not set
466473
467- if (emission. GetOffset ().IsZero ()) {
474+ if (emission-> GetOffset ().IsZero ()) {
468475 if (m_EmissionOffset.IsZero ()) {
469476 pParticle->SetPos (m_Pos);
470477 } else {
471478 pParticle->SetPos (m_Pos + RotateOffset (m_EmissionOffset));
472479 }
473480 } else {
474- pParticle->SetPos (m_Pos + RotateOffset (emission. GetOffset ()));
481+ pParticle->SetPos (m_Pos + RotateOffset (emission-> GetOffset ()));
475482 }
476483 // TODO: Optimize making the random angles!")
477484 emitVel.SetXY (velMin + RandomNum (0 .0F , velRange), 0 .0F );
478485 emitVel.RadRotate (m_EmitAngle.GetRadAngle () + spread * RandomNormalNum ());
479486 emitVel = RotateOffset (emitVel);
480487 pParticle->SetVel (parentVel + rotationalVel + emitVel);
481488 pParticle->SetRotAngle (emitVel.GetAbsRadAngle () + (m_HFlipped ? -c_PI : 0 ));
482- pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission. InheritsAngularVelocity ());
489+ pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission-> InheritsAngularVelocity ());
483490 pParticle->SetHFlipped (m_HFlipped);
484491
485492 // Scale the particle's lifetime based on life variation and throttle, as long as it's not 0
486493 if (pParticle->GetLifetime () != 0 ) {
487- pParticle->SetLifetime (std::max (static_cast <int >(static_cast <float >(pParticle->GetLifetime ()) * (1 .0F + (emission. GetLifeVariation () * RandomNormalNum ()))), 1 ));
494+ pParticle->SetLifetime (std::max (static_cast <int >(static_cast <float >(pParticle->GetLifetime ()) * (1 .0F + (emission-> GetLifeVariation () * RandomNormalNum ()))), 1 ));
488495 pParticle->SetLifetime (std::max (static_cast <int >(pParticle->GetLifetime () * throttleFactor), 1 ));
489496 }
490497 pParticle->SetTeam (m_Team);
491498 pParticle->SetIgnoresTeamHits (true );
492499
493500 // Add to accumulative recoil impulse generated, F = m * a
494501 // If enabled, that is
495- if (emission. PushesEmitter () && (GetParent () || GetMass () > 0 )) {
496- pushImpulses -= emitVel * pParticle->GetMass ();
502+ if (emission-> PushesEmitter () && (GetParent () || GetMass () > 0 )) {
503+ pushImpulses += - emitVel * pParticle->GetMass ();
497504 }
498505
499506 // Set the emitted particle to not hit this emitter's parent, if applicable
0 commit comments