From c0daa753536caf474dd7f420d36ba74c5aaf1c26 Mon Sep 17 00:00:00 2001 From: Thaumaturge Date: Sun, 10 Nov 2019 20:33:45 +0100 Subject: [PATCH] particles: add parameter to delay particle birth in soft_start() Also adds a get_tics_since_birth() getter. This feature can be used to synchronize different particle effects. Closes #769 --- direct/src/particles/ParticleEffect.py | 7 +++++-- panda/src/particlesystem/particleSystem.I | 20 ++++++++++++++++++++ panda/src/particlesystem/particleSystem.h | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/direct/src/particles/ParticleEffect.py b/direct/src/particles/ParticleEffect.py index 4ba19dcd61..f2c2141614 100644 --- a/direct/src/particles/ParticleEffect.py +++ b/direct/src/particles/ParticleEffect.py @@ -221,10 +221,13 @@ class ParticleEffect(NodePath): for particles in self.getParticlesList(): particles.softStop() - def softStart(self): + def softStart(self, firstBirthDelay=None): if self.__isValid(): for particles in self.getParticlesList(): - particles.softStart() + if firstBirthDelay is not None: + particles.softStart(br=-1, first_birth_delay=firstBirthDelay) + else: + particles.softStart() else: # Not asserting here since we want to crash live clients for more expedient bugfix # (Sorry, live clients) diff --git a/panda/src/particlesystem/particleSystem.I b/panda/src/particlesystem/particleSystem.I index a96083f7e2..731ae9d7dc 100644 --- a/panda/src/particlesystem/particleSystem.I +++ b/panda/src/particlesystem/particleSystem.I @@ -58,6 +58,18 @@ soft_start(PN_stdfloat br) { _tics_since_birth = 0.0f; } +/** + * Causes system to use birth rate set by set_birth_rate(), with the system's + * first birth being delayed by the value of first_birth_delay. Note that a + * negative delay is perfectly valid, causing the first birth to happen + * sooner rather than later. + */ +INLINE void ParticleSystem:: +soft_start(PN_stdfloat br, PN_stdfloat first_birth_delay) { + soft_start(br); + _tics_since_birth = -first_birth_delay; +} + /** * Causes system to use birth rate set by set_soft_birth_rate() */ @@ -342,6 +354,14 @@ get_floor_z() const { return _floor_z; } +/** + +*/ +INLINE PN_stdfloat ParticleSystem:: +get_tics_since_birth() const { + return _tics_since_birth; +} + /** */ diff --git a/panda/src/particlesystem/particleSystem.h b/panda/src/particlesystem/particleSystem.h index 1e5bfdaac8..23e6f5ce82 100644 --- a/panda/src/particlesystem/particleSystem.h +++ b/panda/src/particlesystem/particleSystem.h @@ -83,6 +83,7 @@ PUBLISHED: INLINE BaseParticleEmitter *get_emitter() const; INLINE BaseParticleFactory *get_factory() const; INLINE PN_stdfloat get_floor_z() const; + INLINE PN_stdfloat get_tics_since_birth() const; // particle template vector @@ -96,6 +97,7 @@ PUBLISHED: INLINE void clear_to_initial(); INLINE void soft_stop(PN_stdfloat br = 0.0); INLINE void soft_start(PN_stdfloat br = 0.0); + INLINE void soft_start(PN_stdfloat br, PN_stdfloat first_birth_delay); void update(PN_stdfloat dt); virtual void output(std::ostream &out) const;