Panda3D
particleSystem.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file particleSystem.h
10  * @author charles
11  * @date 2000-06-14
12  */
13 
14 #ifndef NDEBUG
15 // #define PSDEBUG
16 #endif
17 
18 // #define PSSANITYCHECK
19 
20 #ifndef PARTICLESYSTEM_H
21 #define PARTICLESYSTEM_H
22 
23 #include "pandabase.h"
24 #include "pointerTo.h"
25 #include "physical.h"
26 #include "pandaNode.h"
27 #include "referenceCount.h"
28 #include "pdeque.h"
29 #include "pStatTimer.h"
30 #include "baseParticle.h"
31 #include "baseParticleRenderer.h"
32 #include "baseParticleEmitter.h"
33 #include "baseParticleFactory.h"
34 
36 
37 /**
38  * Contains and manages a particle system.
39  */
40 class EXPCL_PANDA_PARTICLESYSTEM ParticleSystem : public Physical {
41 PUBLISHED:
42  // constructordestructor
43 
44  explicit ParticleSystem(int pool_size = 0);
45  ParticleSystem(const ParticleSystem& copy);
46  ~ParticleSystem();
47 
48  // accessqueries
49  INLINE void set_pool_size(int size);
50  INLINE void set_birth_rate(PN_stdfloat new_br);
51  INLINE void set_soft_birth_rate(PN_stdfloat new_br);
52  INLINE void set_litter_size(int new_ls);
53  INLINE void set_litter_spread(int new_ls);
54  INLINE void set_local_velocity_flag(bool lv);
55  INLINE void set_system_grows_older_flag(bool sgo);
56  INLINE void set_system_lifespan(PN_stdfloat sl);
57  INLINE void set_system_age(PN_stdfloat age);
58  INLINE void set_active_system_flag(bool a);
59  INLINE void set_spawn_on_death_flag(bool sod);
60  INLINE void set_spawn_render_node(PandaNode *node);
61  INLINE void set_spawn_render_node_path(const NodePath &node);
62  INLINE void set_template_system_flag(bool tsf);
63  INLINE void set_render_parent(PandaNode *node);
64  INLINE void set_render_parent(const NodePath &node);
65  INLINE void set_renderer(BaseParticleRenderer *r);
66  INLINE void set_emitter(BaseParticleEmitter *e);
67  INLINE void set_factory(BaseParticleFactory *f);
68  INLINE void set_floor_z(PN_stdfloat z);
69 
70  INLINE void clear_floor_z();
71 
72  INLINE int get_pool_size() const;
73  INLINE PN_stdfloat get_birth_rate() const;
74  INLINE PN_stdfloat get_soft_birth_rate() const;
75  INLINE int get_litter_size() const;
76  INLINE int get_litter_spread() const;
77  INLINE bool get_local_velocity_flag() const;
78  INLINE bool get_system_grows_older_flag() const;
79  INLINE PN_stdfloat get_system_lifespan() const;
80  INLINE PN_stdfloat get_system_age() const;
81  INLINE bool get_active_system_flag() const;
82  INLINE bool get_spawn_on_death_flag() const;
83  INLINE PandaNode *get_spawn_render_node() const;
84  INLINE NodePath get_spawn_render_node_path() const;
85  INLINE bool get_i_was_spawned_flag() const;
86  INLINE int get_living_particles() const;
87  INLINE NodePath get_render_parent() const;
88  INLINE BaseParticleRenderer *get_renderer() const;
89  INLINE BaseParticleEmitter *get_emitter() const;
90  INLINE BaseParticleFactory *get_factory() const;
91  INLINE PN_stdfloat get_floor_z() const;
92 
93  // particle template vector
94 
95  INLINE void add_spawn_template(ParticleSystem *ps);
96  INLINE void clear_spawn_templates();
97 
98  // methods
99 
100  INLINE void render();
101  INLINE void induce_labor();
102  INLINE void clear_to_initial();
103  INLINE void soft_stop(PN_stdfloat br = 0.0);
104  INLINE void soft_start(PN_stdfloat br = 0.0);
105  void update(PN_stdfloat dt);
106 
107  virtual void output(std::ostream &out) const;
108  virtual void write_free_particle_fifo(std::ostream &out, int indent=0) const;
109  virtual void write_spawn_templates(std::ostream &out, int indent=0) const;
110  virtual void write(std::ostream &out, int indent=0) const;
111 
112 private:
113  #ifdef PSSANITYCHECK
114  int sanity_check();
115  #endif
116 
117  bool birth_particle();
118  void kill_particle(int pool_index);
119  void birth_litter();
120  void resize_pool(int size);
121 
122  pdeque< int > _free_particle_fifo;
123 
124  int _particle_pool_size;
125  int _living_particles;
126  PN_stdfloat _cur_birth_rate;
127  PN_stdfloat _birth_rate;
128  PN_stdfloat _soft_birth_rate;
129  PN_stdfloat _tics_since_birth;
130  int _litter_size;
131  int _litter_spread;
132  PN_stdfloat _system_age;
133  PN_stdfloat _system_lifespan;
134  PN_stdfloat _floor_z;
135 
136  PT(BaseParticleFactory) _factory;
137  PT(BaseParticleEmitter) _emitter;
138  PT(BaseParticleRenderer) _renderer;
139  ParticleSystemManager *_manager;
140 
141  bool _template_system_flag;
142 
143  // _render_parent is the ALREADY ALLOC'D node under which this system will
144  // render its particles.
145 
146  NodePath _render_parent;
147  NodePath _render_node_path;
148 
149  bool _active_system_flag;
150  bool _local_velocity_flag;
151  bool _system_grows_older_flag;
152 
153  // information for systems that will spawn
154 
155  bool _spawn_on_death_flag;
156  NodePath _spawn_render_node_path;
157  pvector< PT(ParticleSystem) > _spawn_templates;
158 
159  void spawn_child_system(BaseParticle *bp);
160 
161  // information for spawned systems
162  bool _i_was_spawned_flag;
163 
164 public:
165  static TypeHandle get_class_type() {
166  return _type_handle;
167  }
168  static void init_type() {
169  Physical::init_type();
170  register_type(_type_handle, "ParticleSystem",
171  Physical::get_class_type());
172  }
173  virtual TypeHandle get_type() const {
174  return get_class_type();
175  }
176  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
177 
178 private:
179  static TypeHandle _type_handle;
180 
181  friend class ParticleSystemManager; // particleSystemManager.h
182 
183  static PStatCollector _update_collector;
184 };
185 
186 #include "particleSystem.I"
187 
188 #endif // PARTICLESYSTEM_H
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Pure Virtual base class for creating particles.
Manages a set of individual ParticleSystem objects, so that each individual one doesn&#39;t have to be up...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(), along with zero to four record_derivation()s.
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight class that represents a single element that may be timed and/or counted via stats...
Contains and manages a particle system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Pure virtual particle renderer base class.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a set of physically modeled attributes.
Definition: physical.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An individual, physically-modelable particle abstract base class.
Definition: baseParticle.h:23
virtual void write(std::ostream &out=std::cout, int indent=0) const
Write a string representation of this instance to <out>.
Definition: physical.cxx:187
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
virtual void output(std::ostream &out=std::cout) const
Write a string representation of this instance to <out>.
Definition: physical.cxx:129