00001 // Filename: particleSystem.h 00002 // Created by: charles (14Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef NDEBUG 00020 //#define PSDEBUG 00021 #endif 00022 00023 //#define PSSANITYCHECK 00024 00025 #ifndef PARTICLESYSTEM_H 00026 #define PARTICLESYSTEM_H 00027 00028 #include "pandabase.h" 00029 #include "pointerTo.h" 00030 #include "physical.h" 00031 #include "pandaNode.h" 00032 #include "referenceCount.h" 00033 00034 #include "pdeque.h" 00035 00036 #include "baseParticle.h" 00037 #include "baseParticleRenderer.h" 00038 #include "baseParticleEmitter.h" 00039 #include "baseParticleFactory.h" 00040 00041 class ParticleSystemManager; 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Class : ParticleSystem 00045 // Description : Contains and manages a particle system. 00046 //////////////////////////////////////////////////////////////////// 00047 class EXPCL_PANDAPHYSICS ParticleSystem : public Physical { 00048 private: 00049 00050 #ifdef PSSANITYCHECK 00051 int sanity_check(); 00052 #endif 00053 00054 bool birth_particle(void); 00055 void kill_particle(int pool_index); 00056 void birth_litter(void); 00057 void resize_pool(int size); 00058 00059 pdeque< int > _free_particle_fifo; 00060 00061 int _particle_pool_size; 00062 int _living_particles; 00063 float _birth_rate; 00064 float _tics_since_birth; 00065 int _litter_size; 00066 int _litter_spread; 00067 float _system_age; 00068 float _system_lifespan; 00069 00070 PT(BaseParticleFactory) _factory; 00071 PT(BaseParticleEmitter) _emitter; 00072 PT(BaseParticleRenderer) _renderer; 00073 ParticleSystemManager *_manager; 00074 00075 bool _template_system_flag; 00076 00077 // _render_parent is the ALREADY ALLOC'D node under which this 00078 // system will render its particles. 00079 00080 PT(PandaNode) _render_parent; 00081 PT(PandaNode) _render_node; 00082 00083 bool _active_system_flag; 00084 bool _local_velocity_flag; 00085 bool _system_grows_older_flag; 00086 00087 // information for systems that will spawn 00088 00089 bool _spawn_on_death_flag; 00090 PT(PandaNode) _spawn_render_node; 00091 pvector< PT(ParticleSystem) > _spawn_templates; 00092 00093 void spawn_child_system(BaseParticle *bp); 00094 00095 // information for spawned systems 00096 bool _i_was_spawned_flag; 00097 00098 PUBLISHED: 00099 // constructor/destructor 00100 00101 ParticleSystem(int pool_size = 0); 00102 ParticleSystem(const ParticleSystem& copy); 00103 ~ParticleSystem(void); 00104 00105 // access/queries 00106 INLINE void set_pool_size(int size); 00107 INLINE void set_birth_rate(float new_br); 00108 INLINE void set_litter_size(int new_ls); 00109 INLINE void set_litter_spread(int new_ls); 00110 INLINE void set_local_velocity_flag(bool lv); 00111 INLINE void set_system_grows_older_flag(bool sgo); 00112 INLINE void set_system_lifespan(float sl); 00113 INLINE void set_system_age(float age); 00114 INLINE void set_active_system_flag(bool a); 00115 INLINE void set_spawn_on_death_flag(bool sod); 00116 INLINE void set_spawn_render_node(PandaNode *node); 00117 INLINE void set_template_system_flag(bool tsf); 00118 INLINE void set_render_parent(PandaNode *node); 00119 INLINE void set_renderer(BaseParticleRenderer *r); 00120 INLINE void set_emitter(BaseParticleEmitter *e); 00121 INLINE void set_factory(BaseParticleFactory *f); 00122 00123 INLINE int get_pool_size(void) const; 00124 INLINE float get_birth_rate(void) const; 00125 INLINE int get_litter_size(void) const; 00126 INLINE int get_litter_spread(void) const; 00127 INLINE bool get_local_velocity_flag(void) const; 00128 INLINE bool get_system_grows_older_flag(void) const; 00129 INLINE float get_system_lifespan(void) const; 00130 INLINE float get_system_age(void) const; 00131 INLINE bool get_active_system_flag(void) const; 00132 INLINE bool get_spawn_on_death_flag(void) const; 00133 INLINE PandaNode *get_spawn_render_node(void) const; 00134 INLINE bool get_i_was_spawned_flag(void) const; 00135 INLINE int get_living_particles(void) const; 00136 INLINE PandaNode *get_render_parent(void) const; 00137 INLINE BaseParticleRenderer *get_renderer(void) const; 00138 INLINE BaseParticleEmitter *get_emitter(void) const; 00139 INLINE BaseParticleFactory *get_factory(void) const; 00140 00141 // particle template vector 00142 00143 INLINE void add_spawn_template(ParticleSystem *ps); 00144 INLINE void clear_spawn_templates(void); 00145 00146 // methods 00147 00148 INLINE void render(void); 00149 INLINE void induce_labor(void); 00150 void update(float dt); 00151 00152 public: 00153 friend class ParticleSystemManager; 00154 }; 00155 00156 #include "particleSystem.I" 00157 00158 #endif // PARTICLESYSTEM_H 00159