particleSystem.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Filename: particleSystem.h
  2. // Created by: charles (14Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef NDEBUG
  15. //#define PSDEBUG
  16. #endif
  17. //#define PSSANITYCHECK
  18. #ifndef PARTICLESYSTEM_H
  19. #define PARTICLESYSTEM_H
  20. #include "pandabase.h"
  21. #include "pointerTo.h"
  22. #include "physical.h"
  23. #include "pandaNode.h"
  24. #include "referenceCount.h"
  25. #include "pdeque.h"
  26. #include "pStatTimer.h"
  27. #include "baseParticle.h"
  28. #include "baseParticleRenderer.h"
  29. #include "baseParticleEmitter.h"
  30. #include "baseParticleFactory.h"
  31. class ParticleSystemManager;
  32. ////////////////////////////////////////////////////////////////////
  33. // Class : ParticleSystem
  34. // Description : Contains and manages a particle system.
  35. ////////////////////////////////////////////////////////////////////
  36. class EXPCL_PANDAPHYSICS ParticleSystem : public Physical {
  37. PUBLISHED:
  38. // constructor/destructor
  39. ParticleSystem(int pool_size = 0);
  40. ParticleSystem(const ParticleSystem& copy);
  41. ~ParticleSystem();
  42. // access/queries
  43. INLINE void set_pool_size(int size);
  44. INLINE void set_birth_rate(PN_stdfloat new_br);
  45. INLINE void set_soft_birth_rate(PN_stdfloat new_br);
  46. INLINE void set_litter_size(int new_ls);
  47. INLINE void set_litter_spread(int new_ls);
  48. INLINE void set_local_velocity_flag(bool lv);
  49. INLINE void set_system_grows_older_flag(bool sgo);
  50. INLINE void set_system_lifespan(PN_stdfloat sl);
  51. INLINE void set_system_age(PN_stdfloat age);
  52. INLINE void set_active_system_flag(bool a);
  53. INLINE void set_spawn_on_death_flag(bool sod);
  54. INLINE void set_spawn_render_node(PandaNode *node);
  55. INLINE void set_spawn_render_node_path(const NodePath &node);
  56. INLINE void set_template_system_flag(bool tsf);
  57. INLINE void set_render_parent(PandaNode *node);
  58. INLINE void set_render_parent(const NodePath &node);
  59. INLINE void set_renderer(BaseParticleRenderer *r);
  60. INLINE void set_emitter(BaseParticleEmitter *e);
  61. INLINE void set_factory(BaseParticleFactory *f);
  62. INLINE void set_floor_z(PN_stdfloat z);
  63. INLINE void clear_floor_z();
  64. INLINE int get_pool_size() const;
  65. INLINE PN_stdfloat get_birth_rate() const;
  66. INLINE PN_stdfloat get_soft_birth_rate() const;
  67. INLINE int get_litter_size() const;
  68. INLINE int get_litter_spread() const;
  69. INLINE bool get_local_velocity_flag() const;
  70. INLINE bool get_system_grows_older_flag() const;
  71. INLINE PN_stdfloat get_system_lifespan() const;
  72. INLINE PN_stdfloat get_system_age() const;
  73. INLINE bool get_active_system_flag() const;
  74. INLINE bool get_spawn_on_death_flag() const;
  75. INLINE PandaNode *get_spawn_render_node() const;
  76. INLINE NodePath get_spawn_render_node_path() const;
  77. INLINE bool get_i_was_spawned_flag() const;
  78. INLINE int get_living_particles() const;
  79. INLINE NodePath get_render_parent() const;
  80. INLINE BaseParticleRenderer *get_renderer() const;
  81. INLINE BaseParticleEmitter *get_emitter() const;
  82. INLINE BaseParticleFactory *get_factory() const;
  83. INLINE PN_stdfloat get_floor_z() const;
  84. // particle template vector
  85. INLINE void add_spawn_template(ParticleSystem *ps);
  86. INLINE void clear_spawn_templates();
  87. // methods
  88. INLINE void render();
  89. INLINE void induce_labor();
  90. INLINE void clear_to_initial();
  91. INLINE void soft_stop(PN_stdfloat br = 0.0);
  92. INLINE void soft_start(PN_stdfloat br = 0.0);
  93. void update(PN_stdfloat dt);
  94. virtual void output(ostream &out) const;
  95. virtual void write_free_particle_fifo(ostream &out, int indent=0) const;
  96. virtual void write_spawn_templates(ostream &out, int indent=0) const;
  97. virtual void write(ostream &out, int indent=0) const;
  98. private:
  99. #ifdef PSSANITYCHECK
  100. int sanity_check();
  101. #endif
  102. bool birth_particle();
  103. void kill_particle(int pool_index);
  104. void birth_litter();
  105. void resize_pool(int size);
  106. pdeque< int > _free_particle_fifo;
  107. int _particle_pool_size;
  108. int _living_particles;
  109. PN_stdfloat _cur_birth_rate;
  110. PN_stdfloat _birth_rate;
  111. PN_stdfloat _soft_birth_rate;
  112. PN_stdfloat _tics_since_birth;
  113. int _litter_size;
  114. int _litter_spread;
  115. PN_stdfloat _system_age;
  116. PN_stdfloat _system_lifespan;
  117. PN_stdfloat _floor_z;
  118. PT(BaseParticleFactory) _factory;
  119. PT(BaseParticleEmitter) _emitter;
  120. PT(BaseParticleRenderer) _renderer;
  121. ParticleSystemManager *_manager;
  122. bool _template_system_flag;
  123. // _render_parent is the ALREADY ALLOC'D node under which this
  124. // system will render its particles.
  125. NodePath _render_parent;
  126. NodePath _render_node_path;
  127. bool _active_system_flag;
  128. bool _local_velocity_flag;
  129. bool _system_grows_older_flag;
  130. // information for systems that will spawn
  131. bool _spawn_on_death_flag;
  132. NodePath _spawn_render_node_path;
  133. pvector< PT(ParticleSystem) > _spawn_templates;
  134. void spawn_child_system(BaseParticle *bp);
  135. // information for spawned systems
  136. bool _i_was_spawned_flag;
  137. public:
  138. static TypeHandle get_class_type() {
  139. return _type_handle;
  140. }
  141. static void init_type() {
  142. Physical::init_type();
  143. register_type(_type_handle, "ParticleSystem",
  144. Physical::get_class_type());
  145. }
  146. virtual TypeHandle get_type() const {
  147. return get_class_type();
  148. }
  149. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  150. private:
  151. static TypeHandle _type_handle;
  152. friend class ParticleSystemManager; // particleSystemManager.h
  153. static PStatCollector _update_collector;
  154. };
  155. #include "particleSystem.I"
  156. #endif // PARTICLESYSTEM_H