Panda3D
|
00001 // Filename: particleSystem.h 00002 // Created by: charles (14Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef NDEBUG 00016 //#define PSDEBUG 00017 #endif 00018 00019 //#define PSSANITYCHECK 00020 00021 #ifndef PARTICLESYSTEM_H 00022 #define PARTICLESYSTEM_H 00023 00024 #include "pandabase.h" 00025 #include "pointerTo.h" 00026 #include "physical.h" 00027 #include "pandaNode.h" 00028 #include "referenceCount.h" 00029 #include "pdeque.h" 00030 #include "pStatTimer.h" 00031 #include "baseParticle.h" 00032 #include "baseParticleRenderer.h" 00033 #include "baseParticleEmitter.h" 00034 #include "baseParticleFactory.h" 00035 00036 class ParticleSystemManager; 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Class : ParticleSystem 00040 // Description : Contains and manages a particle system. 00041 //////////////////////////////////////////////////////////////////// 00042 class EXPCL_PANDAPHYSICS ParticleSystem : public Physical { 00043 PUBLISHED: 00044 // constructor/destructor 00045 00046 ParticleSystem(int pool_size = 0); 00047 ParticleSystem(const ParticleSystem& copy); 00048 ~ParticleSystem(); 00049 00050 // access/queries 00051 INLINE void set_pool_size(int size); 00052 INLINE void set_birth_rate(PN_stdfloat new_br); 00053 INLINE void set_soft_birth_rate(PN_stdfloat new_br); 00054 INLINE void set_litter_size(int new_ls); 00055 INLINE void set_litter_spread(int new_ls); 00056 INLINE void set_local_velocity_flag(bool lv); 00057 INLINE void set_system_grows_older_flag(bool sgo); 00058 INLINE void set_system_lifespan(PN_stdfloat sl); 00059 INLINE void set_system_age(PN_stdfloat age); 00060 INLINE void set_active_system_flag(bool a); 00061 INLINE void set_spawn_on_death_flag(bool sod); 00062 INLINE void set_spawn_render_node(PandaNode *node); 00063 INLINE void set_spawn_render_node_path(const NodePath &node); 00064 INLINE void set_template_system_flag(bool tsf); 00065 INLINE void set_render_parent(PandaNode *node); 00066 INLINE void set_render_parent(const NodePath &node); 00067 INLINE void set_renderer(BaseParticleRenderer *r); 00068 INLINE void set_emitter(BaseParticleEmitter *e); 00069 INLINE void set_factory(BaseParticleFactory *f); 00070 INLINE void set_floor_z(PN_stdfloat z); 00071 00072 INLINE void clear_floor_z(); 00073 00074 INLINE int get_pool_size() const; 00075 INLINE PN_stdfloat get_birth_rate() const; 00076 INLINE PN_stdfloat get_soft_birth_rate() const; 00077 INLINE int get_litter_size() const; 00078 INLINE int get_litter_spread() const; 00079 INLINE bool get_local_velocity_flag() const; 00080 INLINE bool get_system_grows_older_flag() const; 00081 INLINE PN_stdfloat get_system_lifespan() const; 00082 INLINE PN_stdfloat get_system_age() const; 00083 INLINE bool get_active_system_flag() const; 00084 INLINE bool get_spawn_on_death_flag() const; 00085 INLINE PandaNode *get_spawn_render_node() const; 00086 INLINE NodePath get_spawn_render_node_path() const; 00087 INLINE bool get_i_was_spawned_flag() const; 00088 INLINE int get_living_particles() const; 00089 INLINE NodePath get_render_parent() const; 00090 INLINE BaseParticleRenderer *get_renderer() const; 00091 INLINE BaseParticleEmitter *get_emitter() const; 00092 INLINE BaseParticleFactory *get_factory() const; 00093 INLINE PN_stdfloat get_floor_z() const; 00094 00095 // particle template vector 00096 00097 INLINE void add_spawn_template(ParticleSystem *ps); 00098 INLINE void clear_spawn_templates(); 00099 00100 // methods 00101 00102 INLINE void render(); 00103 INLINE void induce_labor(); 00104 INLINE void clear_to_initial(); 00105 INLINE void soft_stop(PN_stdfloat br = 0.0); 00106 INLINE void soft_start(PN_stdfloat br = 0.0); 00107 void update(PN_stdfloat dt); 00108 00109 virtual void output(ostream &out) const; 00110 virtual void write_free_particle_fifo(ostream &out, int indent=0) const; 00111 virtual void write_spawn_templates(ostream &out, int indent=0) const; 00112 virtual void write(ostream &out, int indent=0) const; 00113 00114 private: 00115 #ifdef PSSANITYCHECK 00116 int sanity_check(); 00117 #endif 00118 00119 bool birth_particle(); 00120 void kill_particle(int pool_index); 00121 void birth_litter(); 00122 void resize_pool(int size); 00123 00124 pdeque< int > _free_particle_fifo; 00125 00126 int _particle_pool_size; 00127 int _living_particles; 00128 PN_stdfloat _cur_birth_rate; 00129 PN_stdfloat _birth_rate; 00130 PN_stdfloat _soft_birth_rate; 00131 PN_stdfloat _tics_since_birth; 00132 int _litter_size; 00133 int _litter_spread; 00134 PN_stdfloat _system_age; 00135 PN_stdfloat _system_lifespan; 00136 PN_stdfloat _floor_z; 00137 00138 PT(BaseParticleFactory) _factory; 00139 PT(BaseParticleEmitter) _emitter; 00140 PT(BaseParticleRenderer) _renderer; 00141 ParticleSystemManager *_manager; 00142 00143 bool _template_system_flag; 00144 00145 // _render_parent is the ALREADY ALLOC'D node under which this 00146 // system will render its particles. 00147 00148 NodePath _render_parent; 00149 NodePath _render_node_path; 00150 00151 bool _active_system_flag; 00152 bool _local_velocity_flag; 00153 bool _system_grows_older_flag; 00154 00155 // information for systems that will spawn 00156 00157 bool _spawn_on_death_flag; 00158 NodePath _spawn_render_node_path; 00159 pvector< PT(ParticleSystem) > _spawn_templates; 00160 00161 void spawn_child_system(BaseParticle *bp); 00162 00163 // information for spawned systems 00164 bool _i_was_spawned_flag; 00165 00166 public: 00167 static TypeHandle get_class_type() { 00168 return _type_handle; 00169 } 00170 static void init_type() { 00171 Physical::init_type(); 00172 register_type(_type_handle, "ParticleSystem", 00173 Physical::get_class_type()); 00174 } 00175 virtual TypeHandle get_type() const { 00176 return get_class_type(); 00177 } 00178 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00179 00180 private: 00181 static TypeHandle _type_handle; 00182 00183 friend class ParticleSystemManager; // particleSystemManager.h 00184 00185 static PStatCollector _update_collector; 00186 }; 00187 00188 #include "particleSystem.I" 00189 00190 #endif // PARTICLESYSTEM_H 00191