Panda3D

Loading...
Searching...
No Matches
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 PARTICLESYSTEM_H
15#define PARTICLESYSTEM_H
16
17#include "pandabase.h"
18#include "pointerTo.h"
19#include "physical.h"
20#include "pandaNode.h"
21#include "referenceCount.h"
22#include "pdeque.h"
23#include "pStatTimer.h"
24#include "baseParticle.h"
25#include "baseParticleRenderer.h"
26#include "baseParticleEmitter.h"
27#include "baseParticleFactory.h"
28
29 class ParticleSystemManager;
30
31/**
32 * Contains and manages a particle system.
33 */
34 class EXPCL_PANDA_PARTICLESYSTEM ParticleSystem : public Physical {
35PUBLISHED:
36 // constructordestructor
37
38 explicit ParticleSystem(int pool_size = 0);
39 ParticleSystem(const ParticleSystem& copy);
40 ~ParticleSystem();
41
42 // accessqueries
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
64 INLINE void clear_floor_z();
65
66 INLINE int get_pool_size() const;
67 INLINE PN_stdfloat get_birth_rate() const;
68 INLINE PN_stdfloat get_soft_birth_rate() const;
69 INLINE int get_litter_size() const;
70 INLINE int get_litter_spread() const;
71 INLINE bool get_local_velocity_flag() const;
72 INLINE bool get_system_grows_older_flag() const;
73 INLINE PN_stdfloat get_system_lifespan() const;
74 INLINE PN_stdfloat get_system_age() const;
75 INLINE bool get_active_system_flag() const;
76 INLINE bool get_spawn_on_death_flag() const;
77 INLINE PandaNode *get_spawn_render_node() const;
78 INLINE NodePath get_spawn_render_node_path() const;
79 INLINE bool get_i_was_spawned_flag() const;
80 INLINE int get_living_particles() const;
81 INLINE NodePath get_render_parent() const;
82 INLINE BaseParticleRenderer *get_renderer() const;
83 INLINE BaseParticleEmitter *get_emitter() const;
84 INLINE BaseParticleFactory *get_factory() const;
85 INLINE PN_stdfloat get_floor_z() const;
86 INLINE PN_stdfloat get_tics_since_birth() const;
87
88 // particle template vector
89
90 INLINE void add_spawn_template(ParticleSystem *ps);
91 INLINE void clear_spawn_templates();
92
93 // methods
94
95 INLINE void render();
96 INLINE void induce_labor();
97 INLINE void clear_to_initial();
98 INLINE void soft_stop(PN_stdfloat br = 0.0);
99 INLINE void soft_start(PN_stdfloat br = 0.0);
100 INLINE void soft_start(PN_stdfloat br, PN_stdfloat first_birth_delay);
101 void update(PN_stdfloat dt);
102
103 virtual void output(std::ostream &out) const;
104 virtual void write_free_particle_fifo(std::ostream &out, int indent=0) const;
105 virtual void write_spawn_templates(std::ostream &out, int indent=0) const;
106 virtual void write(std::ostream &out, int indent=0) const;
107
108 private:
109 #ifdef PSSANITYCHECK
110 int sanity_check();
111 #endif
112
113 bool birth_particle();
114 void kill_particle(int pool_index);
115 void birth_litter();
116 void resize_pool(int size);
117
118 pdeque< int > _free_particle_fifo;
119
120 int _particle_pool_size;
121 int _living_particles;
122 PN_stdfloat _cur_birth_rate;
123 PN_stdfloat _birth_rate;
124 PN_stdfloat _soft_birth_rate;
125 PN_stdfloat _tics_since_birth;
126 int _litter_size;
127 int _litter_spread;
128 PN_stdfloat _system_age;
129 PN_stdfloat _system_lifespan;
130 PN_stdfloat _floor_z;
131
132 PT(BaseParticleFactory) _factory;
133 PT(BaseParticleEmitter) _emitter;
134 PT(BaseParticleRenderer) _renderer;
135 ParticleSystemManager *_manager;
136
137 bool _template_system_flag;
138
139 // _render_parent is the ALREADY ALLOC'D node under which this system will
140 // render its particles.
141
142 NodePath _render_parent;
143 NodePath _render_node_path;
144
145 bool _active_system_flag;
146 bool _local_velocity_flag;
147 bool _system_grows_older_flag;
148
149 // information for systems that will spawn
150
151 bool _spawn_on_death_flag;
152 NodePath _spawn_render_node_path;
153 pvector< PT(ParticleSystem) > _spawn_templates;
154
155 void spawn_child_system(BaseParticle *bp);
156
157 // information for spawned systems
158 bool _i_was_spawned_flag;
159
160 public:
161 static TypeHandle get_class_type() {
162 return _type_handle;
163 }
164 static void init_type() {
165 Physical::init_type();
166 register_type(_type_handle, "ParticleSystem",
167 Physical::get_class_type());
168 }
169 virtual TypeHandle get_type() const {
170 return get_class_type();
171 }
172 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
173
174 private:
175 static TypeHandle _type_handle;
176
177 friend class ParticleSystemManager; // particleSystemManager.h
178
179 static PStatCollector _update_collector;
180};
181
182#include "particleSystem.I"
183
184#endif // PARTICLESYSTEM_H
baseParticleEmitter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
baseParticleFactory.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
baseParticleRenderer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
baseParticle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BaseParticleEmitter
Definition baseParticleEmitter.h:25
BaseParticleFactory
Pure Virtual base class for creating particles.
Definition baseParticleFactory.h:28
BaseParticleRenderer
Pure virtual particle renderer base class.
Definition baseParticleRenderer.h:32
BaseParticle
An individual, physically-modelable particle abstract base class.
Definition baseParticle.h:23
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
PStatCollector
A lightweight class that represents a single element that may be timed and/or counted via stats.
Definition pStatCollector.h:43
PandaNode
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
ParticleSystemManager
Manages a set of individual ParticleSystem objects, so that each individual one doesn't have to be up...
Definition particleSystemManager.h:27
ParticleSystem::soft_start
void soft_start(PN_stdfloat br=0.0)
Causes system to use birth rate set by set_birth_rate()
Definition particleSystem.I:54
ParticleSystem::induce_labor
void induce_labor()
Forces the birth of a particle litter this frame by resetting _tics_since_birth.
Definition particleSystem.I:28
ParticleSystem::clear_to_initial
void clear_to_initial()
Resets the system to its start state by resizing to 0, then resizing back to current size.
Definition particleSystem.I:37
ParticleSystem::soft_stop
void soft_stop(PN_stdfloat br=0.0)
Causes system to use birth rate set by set_soft_birth_rate()
Definition particleSystem.I:77
ParticleSystem::write_free_particle_fifo
virtual void write_free_particle_fifo(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition particleSystem.cxx:689
ParticleSystem::update
void update(PN_stdfloat dt)
Updates the particle system.
Definition particleSystem.cxx:457
ParticleSystem::write_spawn_templates
virtual void write_spawn_templates(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition particleSystem.cxx:705
ParticleSystem::ParticleSystem
ParticleSystem(int pool_size=0)
Default Constructor.
Definition particleSystem.cxx:45
ParticleSystem::render
void render()
Populates an attached GeomNode structure with the particle geometry for rendering.
Definition particleSystem.I:19
Physical::Physical
Physical(int total_objects=1, bool pre_alloc=false)
Default Constructor The idea here is that most physicals will NOT be collections of sets (i....
Definition physical.cxx:35
Physical::write
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
Physical::output
virtual void output(std::ostream &out=std::cout) const
Write a string representation of this instance to <out>.
Definition physical.cxx:129
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
pdeque< int >
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
pStatTimer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandaNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
particleSystem.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pdeque.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physical.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
referenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22