Work around missing cake explosions at low framerates, the burst time would be shorter than one frame and the emitter was shut down before it could even begin to emit

This commit is contained in:
Marianne Gagnon 2014-09-29 20:54:47 -04:00
parent 768d843cfe
commit f2ffcb680d
2 changed files with 15 additions and 8 deletions

View File

@ -39,6 +39,7 @@ Explosion::Explosion(const Vec3& coord, const char* explosion_sound, const char
{
// short emision time, explosion, not constant flame
m_remaining_time = burst_time;
m_emission_frames = 0;
ParticleKindManager* pkm = ParticleKindManager::get();
ParticleKind* particles = pkm->getParticles(particle_file);
@ -67,6 +68,7 @@ bool Explosion::updateAndDelete(float dt)
// so no need to save the result of the update call.
HitSFX::updateAndDelete(dt);
m_emission_frames++;
m_remaining_time -= dt;
if (m_remaining_time < 0.0f && m_remaining_time >= -explosion_time)
@ -85,7 +87,6 @@ bool Explosion::updateAndDelete(float dt)
node->getMaterial(0).AmbientColor.setRed(intensity);
node->getMaterial(0).DiffuseColor.setRed(intensity);
node->getMaterial(0).EmissiveColor.setRed(intensity);
}
@ -96,11 +97,16 @@ bool Explosion::updateAndDelete(float dt)
// sfx will get aborted 'in the middle' when this explosion
// object is removed.
if (m_remaining_time > -explosion_time)
{
// if framerate is very low, emit for at least a few frames, in case
// burst time is lower than the time of 1 frame
if (m_emission_frames > 2)
{
// Stop the emitter and wait a little while for all particles to have time to fade out
m_emitter->getNode()->getEmitter()->setMinParticlesPerSecond(0);
m_emitter->getNode()->getEmitter()->setMaxParticlesPerSecond(0);
}
}
else
{
// Sound and animation finished, node can be removed now.

View File

@ -32,7 +32,7 @@ class Vec3;
class SFXBase;
class ParticleEmitter;
const float explosion_time = 1.5f;
const float explosion_time = 2.0f;
/**
* \ingroup graphics
@ -41,6 +41,7 @@ class Explosion : public HitSFX
{
private:
float m_remaining_time;
int m_emission_frames;
ParticleEmitter* m_emitter;
public: