From eef56b66b48651c9c2951032a5f16d56c95490fa Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Tue, 25 Jul 2006 01:39:24 +0000 Subject: [PATCH] added ability for particle system to perform a 'soft stop' where the birthing is effectively stopped while the rest of the system runs down --- panda/src/particlesystem/particleSystem.I | 52 ++++++++++++++++++++- panda/src/particlesystem/particleSystem.cxx | 11 +++-- panda/src/particlesystem/particleSystem.h | 6 +++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/panda/src/particlesystem/particleSystem.I b/panda/src/particlesystem/particleSystem.I index fb30f0b6db..7a42672f5e 100644 --- a/panda/src/particlesystem/particleSystem.I +++ b/panda/src/particlesystem/particleSystem.I @@ -38,7 +38,7 @@ render() { INLINE void ParticleSystem:: induce_labor() { - _tics_since_birth = _birth_rate; + _tics_since_birth = _cur_birth_rate; } //////////////////////////////////////////////////////////////////// @@ -62,6 +62,35 @@ clear_to_initial() { _tics_since_birth = 0.0f; } +//////////////////////////////////////////////////////////////////// +// Function : soft_start +// Access : Public +// Description : Causes system to use birth rate set by set_birth_rate() +//////////////////////////////////////////////////////////////////// + +INLINE void ParticleSystem:: +soft_start(float br) { + if (br > 0.0) + set_birth_rate(br); + _cur_birth_rate = _birth_rate; + _tics_since_birth = 0.0f; +} + +//////////////////////////////////////////////////////////////////// +// Function : soft_stop +// Access : Public +// Description : Causes system to use birth rate set by +// set_soft_birth_rate() +//////////////////////////////////////////////////////////////////// + +INLINE void ParticleSystem:: +soft_stop(float br) { + if (br > 0.0) + set_soft_birth_rate(br); + _cur_birth_rate = _soft_birth_rate; + _tics_since_birth = 0.0f; +} + //// /////////////////////////////////////////////////////// //// SET METHODS /////////////////////////////////////////////////////// //// /////////////////////////////////////////////////////// @@ -84,9 +113,21 @@ set_pool_size(int size) { INLINE void ParticleSystem:: set_birth_rate(float new_br) { _birth_rate = new_br; + _cur_birth_rate = _birth_rate; if(IS_NEARLY_ZERO(_birth_rate)) _birth_rate = NEARLY_ZERO(float); } +//////////////////////////////////////////////////////////////////// +// Function : set_soft_birth_rate +// Access : Public +//////////////////////////////////////////////////////////////////// + +INLINE void ParticleSystem:: +set_soft_birth_rate(float new_br) { + _soft_birth_rate = new_br; + if(IS_NEARLY_ZERO(_soft_birth_rate)) _soft_birth_rate = NEARLY_ZERO(float); +} + //////////////////////////////////////////////////////////////////// // Function : set_litter_size // Access : Public @@ -294,6 +335,15 @@ get_birth_rate() const { return _birth_rate; } +//////////////////////////////////////////////////////////////////// +// Function : get_soft_birth_rate +// Access : Public +//////////////////////////////////////////////////////////////////// +INLINE float ParticleSystem:: +get_soft_birth_rate() const { + return _soft_birth_rate; +} + //////////////////////////////////////////////////////////////////// // Function : get_litter_size // Access : Public diff --git a/panda/src/particlesystem/particleSystem.cxx b/panda/src/particlesystem/particleSystem.cxx index 26acff1e77..9788136cce 100644 --- a/panda/src/particlesystem/particleSystem.cxx +++ b/panda/src/particlesystem/particleSystem.cxx @@ -46,7 +46,9 @@ ParticleSystem(int pool_size) : Physical(pool_size, false) { _birth_rate = 0.5f; - _tics_since_birth = _birth_rate; + _cur_birth_rate = _birth_rate; + _soft_birth_rate = HUGE_VAL; + _tics_since_birth = 0.0; _litter_size = 1; _litter_spread = 0; _living_particles = 0; @@ -91,6 +93,7 @@ ParticleSystem(const ParticleSystem& copy) : _template_system_flag(false) { _birth_rate = copy._birth_rate; + _cur_birth_rate = copy._cur_birth_rate; _litter_size = copy._litter_size; _litter_spread = copy._litter_spread; _active_system_flag = copy._active_system_flag; @@ -106,7 +109,7 @@ ParticleSystem(const ParticleSystem& copy) : _render_node = _renderer->get_render_node(); _render_parent->add_child(_render_node); - _tics_since_birth = _birth_rate; + _tics_since_birth = 0.0; _system_lifespan = copy._system_lifespan; _living_particles = 0; @@ -534,9 +537,9 @@ update(float dt) { // generate new particles if necessary. _tics_since_birth += dt; - while (_tics_since_birth >= _birth_rate) { + while (_tics_since_birth >= _cur_birth_rate) { birth_litter(); - _tics_since_birth -= _birth_rate; + _tics_since_birth -= _cur_birth_rate; } #ifdef PARTICLE_SYSTEM_UPDATE_SENTRIES diff --git a/panda/src/particlesystem/particleSystem.h b/panda/src/particlesystem/particleSystem.h index 97232dbdf2..c4fd48a180 100644 --- a/panda/src/particlesystem/particleSystem.h +++ b/panda/src/particlesystem/particleSystem.h @@ -55,6 +55,7 @@ PUBLISHED: // access/queries INLINE void set_pool_size(int size); INLINE void set_birth_rate(float new_br); + INLINE void set_soft_birth_rate(float new_br); INLINE void set_litter_size(int new_ls); INLINE void set_litter_spread(int new_ls); INLINE void set_local_velocity_flag(bool lv); @@ -75,6 +76,7 @@ PUBLISHED: INLINE int get_pool_size() const; INLINE float get_birth_rate() const; + INLINE float get_soft_birth_rate() const; INLINE int get_litter_size() const; INLINE int get_litter_spread() const; INLINE bool get_local_velocity_flag() const; @@ -102,6 +104,8 @@ PUBLISHED: INLINE void render(); INLINE void induce_labor(); INLINE void clear_to_initial(); + INLINE void soft_stop(float br = 0.0); + INLINE void soft_start(float br = 0.0); void update(float dt); virtual void output(ostream &out) const; @@ -123,7 +127,9 @@ private: int _particle_pool_size; int _living_particles; + float _cur_birth_rate; float _birth_rate; + float _soft_birth_rate; float _tics_since_birth; int _litter_size; int _litter_spread;