diff --git a/direct/src/particles/ParticleEffect.py b/direct/src/particles/ParticleEffect.py index 41930dd46b..2705ae39fd 100644 --- a/direct/src/particles/ParticleEffect.py +++ b/direct/src/particles/ParticleEffect.py @@ -36,6 +36,10 @@ class ParticleEffect(NodePath): self.addParticles(particles) self.renderParent = None + def birthLitter(self): + for p in self.particlesDict.values(): + p.birthLitter() + def cleanup(self): self.removeNode() self.disable() @@ -269,3 +273,4 @@ class ParticleEffect(NodePath): clear_to_initial = clearToInitial soft_stop = softStop soft_start = softStart + birth_litter = birthLitter diff --git a/panda/src/particlesystem/particleSystem.h b/panda/src/particlesystem/particleSystem.h index 7518bbfd9a..6d77d520dc 100644 --- a/panda/src/particlesystem/particleSystem.h +++ b/panda/src/particlesystem/particleSystem.h @@ -104,6 +104,8 @@ PUBLISHED: virtual void write_spawn_templates(std::ostream &out, int indent=0) const; virtual void write(std::ostream &out, int indent=0) const; + void birth_litter(); + private: #ifdef PSSANITYCHECK int sanity_check(); @@ -111,7 +113,6 @@ private: bool birth_particle(); void kill_particle(int pool_index); - void birth_litter(); void resize_pool(int size); pdeque< int > _free_particle_fifo; diff --git a/tests/particles/test_particlesystem.py b/tests/particles/test_particlesystem.py index 9e2ff85c20..41dce1ccaf 100644 --- a/tests/particles/test_particlesystem.py +++ b/tests/particles/test_particlesystem.py @@ -101,3 +101,38 @@ def test_particle_soft_start(): system.update(1) assert system.get_living_particles() == 1 + + +def test_particle_burst_emission(): + effect = ParticleEffect() + system = Particles("testSystem", 10) + effect.add_particles(system) + + # Setup some dummy nodes, since it seems to want them + # We might normally call "start", but that calls "enable", which + # seems to assume that "base" exists and has physics and particle managers... + system.setRenderParent(NodePath(PandaNode("test"))) + system.setSpawnRenderNodePath(NodePath(PandaNode("test"))) + # However, we don't want normal emission, so we now soft-stop it immediately, + # before the system has a chance to update and emit. + effect.softStop() + + # Now, a sanity-check: assert that we have no particles, + # Then update the system, and assert again that we + # have no particles. If so, then we're (hopefully) + # not emitting normally! + + assert system.getLivingParticles() == 0 + system.update(1) + assert system.getLivingParticles() == 0 + + # Now, the real test: emit a particle-burst! + effect.birthLitter() + + # And assert that a particle has, in fact, been emitted. + assert system.getLivingParticles() == 1 + + # Check the snake-case version, too. + effect.birth_litter() + + assert system.getLivingParticles() == 2