@@ -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 (const Emission* emission: reference.m_EmissionList ) {
68
+ m_EmissionList.push_back (dynamic_cast <Emission*>(emission-> Clone ()) );
69
69
}
70
70
if (reference.m_EmissionSound ) {
71
71
m_EmissionSound = dynamic_cast <SoundContainer*>(reference.m_EmissionSound ->Clone ());
@@ -105,9 +105,12 @@ 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;
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
+ }
111
114
});
112
115
MatchProperty (" EmissionSound" , {
113
116
m_EmissionSound = new SoundContainer;
@@ -128,8 +131,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
128
131
float ppm;
129
132
reader >> ppm;
130
133
// 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 () ));
133
136
}
134
137
});
135
138
MatchProperty (" NegativeThrottleMultiplier" , { reader >> m_NegativeThrottleMultiplier; });
@@ -140,8 +143,8 @@ int AEmitter::ReadProperty(const std::string_view& propName, Reader& reader) {
140
143
int burstSize;
141
144
reader >> burstSize;
142
145
// 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 () )));
145
148
}
146
149
});
147
150
MatchProperty (" BurstScale" , { reader >> m_BurstScale; });
@@ -233,6 +236,10 @@ void AEmitter::Destroy(bool notInherited) {
233
236
m_EmissionSound->Stop ();
234
237
}
235
238
239
+ for (auto eItr = m_EmissionList.begin (); eItr != m_EmissionList.end (); ++eItr) {
240
+ delete (*eItr);
241
+ }
242
+
236
243
delete m_EmissionSound;
237
244
delete m_BurstSound;
238
245
delete m_EndSound;
@@ -246,8 +253,8 @@ void AEmitter::Destroy(bool notInherited) {
246
253
247
254
void AEmitter::ResetEmissionTimers () {
248
255
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 ();
251
258
}
252
259
253
260
void AEmitter::EnableEmission (bool enable) {
@@ -268,22 +275,22 @@ float AEmitter::EstimateImpulse(bool burst) {
268
275
float velMin, velMax, velRange, spread;
269
276
270
277
// 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) {
272
279
// 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 ();
275
282
float scale = 1 .0F ;
276
283
if (burst) {
277
- emissions *= (*eItr). GetBurstSize ();
284
+ emissions *= emission-> GetBurstSize ();
278
285
scale = m_BurstScale;
279
286
}
280
287
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
284
291
285
292
// 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;
287
294
}
288
295
}
289
296
@@ -305,16 +312,16 @@ float AEmitter::EstimateImpulse(bool burst) {
305
312
306
313
float AEmitter::GetTotalParticlesPerMinute () const {
307
314
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 () ;
310
317
}
311
318
return totalPPM;
312
319
}
313
320
314
321
int AEmitter::GetTotalBurstSize () const {
315
322
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 () ;
318
325
}
319
326
return totalBurstSize;
320
327
}
@@ -382,8 +389,8 @@ void AEmitter::Update() {
382
389
}
383
390
384
391
// 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 ();
387
394
}
388
395
// Update the distance attenuation
389
396
else if (m_EmissionSound) {
@@ -415,11 +422,11 @@ void AEmitter::Update() {
415
422
MovableObject* pParticle = 0 ;
416
423
Vector parentVel, emitVel, pushImpulses;
417
424
// Go through all emissions and emit them according to their respective rates
418
- for (Emission& emission: m_EmissionList) {
425
+ for (Emission* emission: m_EmissionList) {
419
426
// Make sure the emissions only happen between the start time and end time
420
- if (emission. IsEmissionTime ()) {
427
+ if (emission-> IsEmissionTime ()) {
421
428
// Apply the throttle factor to the emission rate
422
- currentPPM = emission. GetRate () * throttleFactor;
429
+ currentPPM = emission-> GetRate () * throttleFactor;
423
430
int emissionCount = 0 ;
424
431
425
432
// Only do all this if the PPM is actually above zero
@@ -428,72 +435,72 @@ void AEmitter::Update() {
428
435
SPE = 60.0 / currentPPM;
429
436
430
437
// Add the last elapsed time to the accumulator
431
- emission. m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS ();
438
+ emission-> SetAccumulator (emission-> GetAccumulator () + m_LastEmitTmr.GetElapsedSimTimeS () );
432
439
433
440
// 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);
435
442
// Deduct the about to be emitted emissions from the accumulator
436
- emission. m_Accumulator -= emissionCount * SPE;
443
+ emission-> SetAccumulator (emission-> GetAccumulator () - emissionCount * SPE) ;
437
444
438
- RTEAssert (emission. m_Accumulator >= 0 , " Emission accumulator negative!" );
445
+ RTEAssert (emission-> GetAccumulator () >= 0 , " Emission accumulator negative!" );
439
446
} else {
440
- emission. m_Accumulator = 0 ;
447
+ emission-> SetAccumulator ( 0 ) ;
441
448
}
442
449
float scale = 1 .0F ;
443
450
// Add extra emissions if bursting.
444
451
if (m_BurstTriggered) {
445
- emissionCount += emission. GetBurstSize () * std::floor (throttleFactor);
452
+ emissionCount += emission-> GetBurstSize () * std::floor (throttleFactor);
446
453
scale = m_BurstScale;
447
454
}
448
455
emissionCountTotal += emissionCount;
449
456
if (emissionCount > 0 ) {
450
- int extraEmissions = emission. GetParticleCount () - 1 ;
457
+ int extraEmissions = emission-> GetParticleCount () - 1 ;
451
458
emissionCount += extraEmissions;
452
459
}
453
460
pParticle = 0 ;
454
461
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 ();
457
464
458
465
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;
462
469
// Make a copy after the reference particle
463
- pParticle = dynamic_cast <MovableObject*>(emission. GetEmissionParticlePreset ()->Clone ());
470
+ pParticle = dynamic_cast <MovableObject*>(emission-> GetEmissionParticlePreset ()->Clone ());
464
471
// Set up its position and velocity according to the parameters of this.
465
472
// Emission point offset not set
466
473
467
- if (emission. GetOffset ().IsZero ()) {
474
+ if (emission-> GetOffset ().IsZero ()) {
468
475
if (m_EmissionOffset.IsZero ()) {
469
476
pParticle->SetPos (m_Pos);
470
477
} else {
471
478
pParticle->SetPos (m_Pos + RotateOffset (m_EmissionOffset));
472
479
}
473
480
} else {
474
- pParticle->SetPos (m_Pos + RotateOffset (emission. GetOffset ()));
481
+ pParticle->SetPos (m_Pos + RotateOffset (emission-> GetOffset ()));
475
482
}
476
483
// TODO: Optimize making the random angles!")
477
484
emitVel.SetXY (velMin + RandomNum (0 .0F , velRange), 0 .0F );
478
485
emitVel.RadRotate (m_EmitAngle.GetRadAngle () + spread * RandomNormalNum ());
479
486
emitVel = RotateOffset (emitVel);
480
487
pParticle->SetVel (parentVel + rotationalVel + emitVel);
481
488
pParticle->SetRotAngle (emitVel.GetAbsRadAngle () + (m_HFlipped ? -c_PI : 0 ));
482
- pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission. InheritsAngularVelocity ());
489
+ pParticle->SetAngularVel (pRootParent->GetAngularVel () * emission-> InheritsAngularVelocity ());
483
490
pParticle->SetHFlipped (m_HFlipped);
484
491
485
492
// Scale the particle's lifetime based on life variation and throttle, as long as it's not 0
486
493
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 ));
488
495
pParticle->SetLifetime (std::max (static_cast <int >(pParticle->GetLifetime () * throttleFactor), 1 ));
489
496
}
490
497
pParticle->SetTeam (m_Team);
491
498
pParticle->SetIgnoresTeamHits (true );
492
499
493
500
// Add to accumulative recoil impulse generated, F = m * a
494
501
// 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 ();
497
504
}
498
505
499
506
// Set the emitted particle to not hit this emitter's parent, if applicable
0 commit comments