particleSystem.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Filename: particleSystem.h
  2. // Created by: charles (14Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef NDEBUG
  19. //#define PSDEBUG
  20. #endif
  21. //#define PSSANITYCHECK
  22. #ifndef PARTICLESYSTEM_H
  23. #define PARTICLESYSTEM_H
  24. #include "pandabase.h"
  25. #include "pointerTo.h"
  26. #include "physical.h"
  27. #include "pandaNode.h"
  28. #include "referenceCount.h"
  29. #include "pdeque.h"
  30. #include "baseParticle.h"
  31. #include "baseParticleRenderer.h"
  32. #include "baseParticleEmitter.h"
  33. #include "baseParticleFactory.h"
  34. class ParticleSystemManager;
  35. ////////////////////////////////////////////////////////////////////
  36. // Class : ParticleSystem
  37. // Description : Contains and manages a particle system.
  38. ////////////////////////////////////////////////////////////////////
  39. class EXPCL_PANDAPHYSICS ParticleSystem : public Physical {
  40. private:
  41. #ifdef PSSANITYCHECK
  42. int sanity_check();
  43. #endif
  44. bool birth_particle();
  45. void kill_particle(int pool_index);
  46. void birth_litter();
  47. void resize_pool(int size);
  48. pdeque< int > _free_particle_fifo;
  49. int _particle_pool_size;
  50. int _living_particles;
  51. float _birth_rate;
  52. float _tics_since_birth;
  53. int _litter_size;
  54. int _litter_spread;
  55. float _system_age;
  56. float _system_lifespan;
  57. PT(BaseParticleFactory) _factory;
  58. PT(BaseParticleEmitter) _emitter;
  59. PT(BaseParticleRenderer) _renderer;
  60. ParticleSystemManager *_manager;
  61. bool _template_system_flag;
  62. // _render_parent is the ALREADY ALLOC'D node under which this
  63. // system will render its particles.
  64. PT(PandaNode) _render_parent;
  65. PT(PandaNode) _render_node;
  66. bool _active_system_flag;
  67. bool _local_velocity_flag;
  68. bool _system_grows_older_flag;
  69. // information for systems that will spawn
  70. bool _spawn_on_death_flag;
  71. PT(PandaNode) _spawn_render_node;
  72. pvector< PT(ParticleSystem) > _spawn_templates;
  73. void spawn_child_system(BaseParticle *bp);
  74. // information for spawned systems
  75. bool _i_was_spawned_flag;
  76. PUBLISHED:
  77. // constructor/destructor
  78. ParticleSystem(int pool_size = 0);
  79. ParticleSystem(const ParticleSystem& copy);
  80. ~ParticleSystem();
  81. // access/queries
  82. INLINE void set_pool_size(int size);
  83. INLINE void set_birth_rate(float new_br);
  84. INLINE void set_litter_size(int new_ls);
  85. INLINE void set_litter_spread(int new_ls);
  86. INLINE void set_local_velocity_flag(bool lv);
  87. INLINE void set_system_grows_older_flag(bool sgo);
  88. INLINE void set_system_lifespan(float sl);
  89. INLINE void set_system_age(float age);
  90. INLINE void set_active_system_flag(bool a);
  91. INLINE void set_spawn_on_death_flag(bool sod);
  92. INLINE void set_spawn_render_node(PandaNode *node);
  93. INLINE void set_template_system_flag(bool tsf);
  94. INLINE void set_render_parent(PandaNode *node);
  95. INLINE void set_renderer(BaseParticleRenderer *r);
  96. INLINE void set_emitter(BaseParticleEmitter *e);
  97. INLINE void set_factory(BaseParticleFactory *f);
  98. INLINE int get_pool_size() const;
  99. INLINE float get_birth_rate() const;
  100. INLINE int get_litter_size() const;
  101. INLINE int get_litter_spread() const;
  102. INLINE bool get_local_velocity_flag() const;
  103. INLINE bool get_system_grows_older_flag() const;
  104. INLINE float get_system_lifespan() const;
  105. INLINE float get_system_age() const;
  106. INLINE bool get_active_system_flag() const;
  107. INLINE bool get_spawn_on_death_flag() const;
  108. INLINE PandaNode *get_spawn_render_node() const;
  109. INLINE bool get_i_was_spawned_flag() const;
  110. INLINE int get_living_particles() const;
  111. INLINE PandaNode *get_render_parent() const;
  112. INLINE BaseParticleRenderer *get_renderer() const;
  113. INLINE BaseParticleEmitter *get_emitter() const;
  114. INLINE BaseParticleFactory *get_factory() const;
  115. // particle template vector
  116. INLINE void add_spawn_template(ParticleSystem *ps);
  117. INLINE void clear_spawn_templates();
  118. // methods
  119. INLINE void render();
  120. INLINE void induce_labor();
  121. void update(float dt);
  122. public:
  123. friend class ParticleSystemManager;
  124. };
  125. #include "particleSystem.I"
  126. #endif // PARTICLESYSTEM_H