Skip to content

Commit a0ac74b

Browse files
committed
Bunch of hopeful fixes to emitters
1 parent f5fdc24 commit a0ac74b

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

Source/Entities/AEmitter.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -276,28 +276,25 @@ float AEmitter::EstimateImpulse(bool burst) {
276276
for (Emission* emission: m_EmissionList) {
277277
// Only check emissions that push the emitter
278278
if (emission->PushesEmitter()) {
279-
// TODO: we're not checking emission start/stop times here, so this will always calculate the impulse as if the emission was active.
279+
// Todo... we're not checking emission start/stop times here, so this will always calculate the impulse as if the emission was active.
280280
// There's not really an easy way to do this, since the emission rate is not necessarily constant over time.
281+
float emissionsPerFrame = (emission->GetRate() / 60.0f) * g_TimerMan.GetDeltaTimeSecs();
282+
float scale = 1.0F;
281283

282-
// TODO: burst emissions shouldn't be affected by delta time, but they were.
283-
// However our values were tuned for 60hz, so hack in constant 60Hz deltatime in milliseconds.
284-
float deltaTimeSecs = burst ? 1.0f / 60.0f : g_TimerMan.GetDeltaTimeSecs();
284+
// Get all the particles emitted this frame
285+
emissionsPerFrame *= emission->GetParticleCount();
285286

286-
float emissions = (emission->GetRate() / 60.0f) * deltaTimeSecs;
287-
float scale = 1.0F;
287+
// When bursting, add on all the bursted emissions
288+
// We also use m_BurstScale on ALL emissions, not just the extra bursted ones
289+
// This is a bit funky but consistent with the code that applies the impulse
288290
if (burst) {
289-
emissions *= emission->GetBurstSize();
291+
emissionsPerFrame += emission->GetBurstSize();
290292
scale = m_BurstScale;
291293
}
292294

293-
if (emissions > 0) {
294-
int extraEmissions = emission->GetParticleCount() - 1;
295-
emissions += extraEmissions;
296-
}
297-
298295
float velMin = emission->GetMinVelocity() * scale;
299-
float velRange = (emission->GetMaxVelocity() - emission->GetMinVelocity()) * scale * 0.5f;
300-
float spread = (std::max(static_cast<float>(c_PI) - (emission->GetSpread() * scale), 0.0F) / c_PI); // A large spread will cause the forces to cancel eachother out
296+
float velRange = (emission->GetMaxVelocity() - emission->GetMinVelocity()) * scale * 0.5f;
297+
float spread = (std::max(static_cast<float>(c_PI) - (emission->GetSpread() * scale), 0.0F) / c_PI); // A large spread will cause the forces to cancel eachother out
301298

302299
// Add to accumulative recoil impulse generated, F = m * a.
303300
impulse += (velMin + velRange) * spread * emission->m_pEmission->GetMass() * emissions;
@@ -458,17 +455,18 @@ void AEmitter::Update() {
458455
} else {
459456
emission->m_Accumulator = 0;
460457
}
458+
461459
float scale = 1.0F;
462460
// Add extra emissions if bursting.
463461
if (m_BurstTriggered) {
464462
emissionCount += emission->GetBurstSize();
465463
scale = m_BurstScale;
466464
}
465+
466+
// We don't consider extra particles for our emission count, so add prior to multiply
467467
emissionCountTotal += emissionCount;
468-
if (emissionCount > 0) {
469-
int extraEmissions = emission->GetParticleCount() - 1;
470-
emissionCount += extraEmissions;
471-
}
468+
emissionCount *= emission->GetParticleCount();
469+
472470
pParticle = 0;
473471
emitVel.Reset();
474472
parentVel = pRootParent->GetVel() * emission->InheritsVelocity();

Source/Entities/PEmitter.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,20 @@ float PEmitter::EstimateImpulse(bool burst) {
234234
if (emission->PushesEmitter()) {
235235
// Todo... we're not checking emission start/stop times here, so this will always calculate the impulse as if the emission was active.
236236
// There's not really an easy way to do this, since the emission rate is not necessarily constant over time.
237-
float emissions = (emission->GetRate() / 60.0f) * g_TimerMan.GetDeltaTimeSecs();
237+
float emissionsPerFrame = (emission->GetRate() / 60.0f) * g_TimerMan.GetDeltaTimeSecs();
238238
float scale = 1.0F;
239+
240+
// Get all the particles emitted this frame
241+
emissionsPerFrame *= emission->GetParticleCount();
242+
243+
// When bursting, add on all the bursted emissions
244+
// We also use m_BurstScale on ALL emissions, not just the extra bursted ones
245+
// This is a bit funky but consistent with the code that applies the impulse
239246
if (burst) {
240-
emissions *= emission->GetBurstSize();
247+
emissionsPerFrame += emission->GetBurstSize();
241248
scale = m_BurstScale;
242249
}
243250

244-
if (emissions > 0) {
245-
int extraEmissions = emission->GetParticleCount() - 1;
246-
emissions += extraEmissions;
247-
}
248-
249251
float velMin = emission->GetMinVelocity() * scale;
250252
float velRange = (emission->GetMaxVelocity() - emission->GetMinVelocity()) * scale * 0.5f;
251253
float spread = (std::max(static_cast<float>(c_PI) - (emission->GetSpread() * scale), 0.0F) / c_PI); // A large spread will cause the forces to cancel eachother out
@@ -320,7 +322,7 @@ void PEmitter::Update() {
320322
else
321323
m_BurstTriggered = false;
322324

323-
int emissions = 0;
325+
int emissionCountTotal = 0;
324326
float velMin, velRange, spread;
325327
double currentPPM, SPE;
326328
MovableObject* pParticle = 0;
@@ -331,7 +333,7 @@ void PEmitter::Update() {
331333
if (emission->IsEmissionTime()) {
332334
// Apply the throttle factor to the emission rate
333335
currentPPM = emission->GetRate() * throttleFactor;
334-
emissions = 0;
336+
int emissionCount = 0;
335337

336338
// Only do all this if the PPM is acutally above zero
337339
if (currentPPM > 0) {
@@ -342,25 +344,32 @@ void PEmitter::Update() {
342344
emission->m_Accumulator += m_LastEmitTmr.GetElapsedSimTimeS();
343345

344346
// Now figure how many full emissions can fit in the current accumulator
345-
emissions = std::floor(emission->m_Accumulator / SPE);
347+
emissionCount = std::floor(emission->m_Accumulator / SPE);
346348
// Deduct the about to be emitted emissions from the accumulator
347349
emission->m_Accumulator -= emissions * SPE;
348350

349351
RTEAssert(emission->m_Accumulator >= 0, "Emission accumulator negative!");
350352
}
351353

354+
float scale = 1.0F;
352355
// Add extra emissions if bursting.
353-
if (m_BurstTriggered)
354-
emissions += emission->GetBurstSize() * std::floor(throttleFactor);
356+
if (m_BurstTriggered) {
357+
emissionCount += emission->GetBurstSize();
358+
scale = m_BurstScale;
359+
}
360+
361+
// We don't consider extra particles for our emission count, so add prior to multiply
362+
emissionCountTotal += emissionCount;
363+
emissionCount *= emission->GetParticleCount();
355364

356365
pParticle = 0;
357366
emitVel.Reset();
358367
parentVel = pRootParent->GetVel() * emission->InheritsVelocity();
359368

360-
for (int i = 0; i < emissions; ++i) {
361-
velMin = emission->GetMinVelocity() * (m_BurstTriggered ? m_BurstScale : 1.0);
362-
velRange = emission->GetMaxVelocity() - emission->GetMinVelocity() * (m_BurstTriggered ? m_BurstScale : 1.0);
363-
spread = emission->GetSpread() * (m_BurstTriggered ? m_BurstScale : 1.0);
369+
for (int i = 0; i < emissionCount; ++i) {
370+
velMin = emission->GetMinVelocity() * scale;
371+
velRange = emission->GetMaxVelocity() - emission->GetMinVelocity() * scale;
372+
spread = emission->GetSpread() * scale;
364373
// Make a copy after the reference particle
365374
pParticle = dynamic_cast<MovableObject*>(emission->GetEmissionParticlePreset()->Clone());
366375
// Set up its position and velocity according to the parameters of this.
@@ -405,7 +414,7 @@ void PEmitter::Update() {
405414
m_LastEmitTmr.Reset();
406415

407416
// Count the total emissions since enabling, and stop emitting if beyong limit (and limit is also enabled)
408-
m_EmitCount += emissions;
417+
m_EmitCount += emissionCountTotal;
409418
if (m_EmitCountLimit > 0 && m_EmitCount > m_EmitCountLimit)
410419
EnableEmission(false);
411420

0 commit comments

Comments
 (0)