particles: expose birth_litter() to support burst emission

Closes #524
Closes #340
This commit is contained in:
Thaumaturge 2020-02-23 15:11:44 +01:00 committed by rdb
parent f21ab509ec
commit 50d27166d8
3 changed files with 42 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -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