An abstract producer of particles. More...
#include <ParticleProducer.h>
Public Types | |
typedef bool(* | getParticleParams )(ParticleProducer *producer, ParticleStorage::Particle *p, float *params) |
Callback used to get the parameters of a particle in copyToTexture(). | |
Public Member Functions | |
ParticleProducer (const char *type, ptr< ParticleStorage > storage) | |
Creates a new ParticleProducer. | |
virtual | ~ParticleProducer () |
Deletes this ParticleProducer. | |
ptr< ParticleStorage > | getStorage () const |
Returns the ParticleStorage used by this producer to create and store its particles. | |
int | getLayerCount () const |
Returns the number of layers of this producer. | |
ptr< ParticleLayer > | getLayer (int index) const |
Returns the layer of this producer whose index is given. | |
template<typename T > | |
T * | getLayer () const |
Returns the first found layer of type T. | |
bool | hasLayers () const |
Returns true if the list of layers is not empty. | |
void | addLayer (ptr< ParticleLayer > l) |
Adds a Layer to this producer. | |
virtual void | getReferencedProducers (vector< ptr< TileProducer > > &producers) const |
Returns the tile producers used by this ParticleProducer. | |
virtual int | getParticleSize () |
Returns the size in bytes of the data that must be stored for each particle. | |
virtual void | updateParticles (double dt) |
Updates the particles produced by this producer. | |
virtual void | moveParticles (double dt) |
Moves the existing particles. | |
virtual void | removeOldParticles () |
Removes old particles. | |
virtual void | addNewParticles () |
Adds new particles. | |
virtual ParticleStorage::Particle * | newParticle () |
Returns a new and initialized particle. | |
ptr< Texture2D > | copyToTexture (ptr< Texture2D > t, int paramCount, getParticleParams getParams, bool useFuncRes=false) |
Copies the particles data to the given texture. | |
Protected Member Functions | |
ParticleProducer () | |
Creates an uninitialized ParticleProducer. | |
ParticleProducer (const char *type) | |
Creates an uninitialized ParticleProducer. | |
void | init (ptr< ParticleStorage > storage) |
Initializes this ParticleProducer. | |
Private Member Functions | |
void | initialize () |
Initializes the storage and the layers associated with this producer. | |
Private Attributes | |
ptr< ParticleStorage > | storage |
The ParticleStorage used by this producer to create and store its particles. | |
vector< ptr< ParticleLayer > > | layers |
The ParticleLayer associated with this producer. | |
int | paramSize |
The size of the params array. | |
float * | params |
Temporary array used in copyToTexture. | |
bool | initialized |
True if this producer and its layers have been initialized. |
An abstract producer of particles.
A ParticleProducer uses an associated ParticleStorage to store its particles. This storage must not be shared with other ParticleProducer instances. The main methods of a particle producer are moveParticles(), removeOldParticles() and addNewParticles(). Their name indicates their role quite clearly. A particle producer can have layers, each layer needing its own fields per particle, and providing its own moveParticles(), removeOldParticles() and addNewParticles() methods using these layer specific fields (and possibly the fields provided by other layers). A producer with layers allocates particles with a size that is sufficient to store the fields of all its layers (plus its own fields). It also calls the three above methods of each layer. The particles can be stored on CPU or on GPU. In the GPU case some data may be replicated on the CPU, like the particles birth date, in order to know on CPU when to remove old particles and when to create new ones (this storage management can only be done on CPU). In the CPU case the particles data can also be copied on GPU if necessary (see copyToTexture()).
typedef bool(* proland::ParticleProducer::getParticleParams)(ParticleProducer *producer, ParticleStorage::Particle *p, float *params) |
Callback used to get the parameters of a particle in copyToTexture().
producer | a particle producer. | |
p | a particle produced by 'producer'. | |
[out] | params | the parameters for the given particle. |
proland::ParticleProducer::ParticleProducer | ( | const char * | type, | |
ptr< ParticleStorage > | storage | |||
) |
Creates a new ParticleProducer.
type | the type of this ParticleProducer. | |
storage | the storage to create and store the particles. |
virtual proland::ParticleProducer::~ParticleProducer | ( | ) | [virtual] |
Deletes this ParticleProducer.
proland::ParticleProducer::ParticleProducer | ( | ) | [protected] |
Creates an uninitialized ParticleProducer.
proland::ParticleProducer::ParticleProducer | ( | const char * | type | ) | [protected] |
Creates an uninitialized ParticleProducer.
type | the type of this producer. |
void proland::ParticleProducer::addLayer | ( | ptr< ParticleLayer > | l | ) |
Adds a Layer to this producer.
l | the layer to be added. |
virtual void proland::ParticleProducer::addNewParticles | ( | ) | [virtual] |
Adds new particles.
The default implementation of this method calls the corresponding method on each layer of this producer.
ptr<Texture2D> proland::ParticleProducer::copyToTexture | ( | ptr< Texture2D > | t, | |
int | paramCount, | |||
getParticleParams | getParams, | |||
bool | useFuncRes = false | |||
) |
Copies the particles data to the given texture.
The texture size must be ceil(paramCount / 4) times maxParticles, where maxParticles is the ParticleStorage capacity. Each particle is stored in its own row of the texture, with parameters stored in columns, four per column.
t | the destination texture, or NULL to create a new one. | |
paramCount | the number of parameters to be stored per particle. | |
getParams | the function used to get the parameters of each particle. | |
useFuncRes | whether the user-defined function's return value has an influence on what should be stored in the texture. If true, the user will have to determine how to access to the particles on GPU. Otherwise, the particles will be stored depending on their index in the storage. Default is false. |
T* proland::ParticleProducer::getLayer | ( | ) | const [inline] |
Returns the first found layer of type T.
T the type of the layer to be looked for.
ptr<ParticleLayer> proland::ParticleProducer::getLayer | ( | int | index | ) | const |
Returns the layer of this producer whose index is given.
index | a layer index between 0 and getLayerCount (exclusive). |
int proland::ParticleProducer::getLayerCount | ( | ) | const |
Returns the number of layers of this producer.
virtual int proland::ParticleProducer::getParticleSize | ( | ) | [virtual] |
Returns the size in bytes of the data that must be stored for each particle.
The default implementation of this method returns 0.
virtual void proland::ParticleProducer::getReferencedProducers | ( | vector< ptr< TileProducer > > & | producers | ) | const [virtual] |
Returns the tile producers used by this ParticleProducer.
[out] | producers | the tile producers used by this ParticleProducer. |
ptr<ParticleStorage> proland::ParticleProducer::getStorage | ( | ) | const |
Returns the ParticleStorage used by this producer to create and store its particles.
bool proland::ParticleProducer::hasLayers | ( | ) | const |
Returns true if the list of layers is not empty.
False otherwise.
void proland::ParticleProducer::init | ( | ptr< ParticleStorage > | storage | ) | [protected] |
Initializes this ParticleProducer.
See ParticleProducer.
void proland::ParticleProducer::initialize | ( | ) | [private] |
Initializes the storage and the layers associated with this producer.
virtual void proland::ParticleProducer::moveParticles | ( | double | dt | ) | [virtual] |
Moves the existing particles.
The default implementation of this method calls the corresponding method on each layer of this producer.
dt | the elapsed time since the last call to this method, in microseconds. |
virtual ParticleStorage::Particle* proland::ParticleProducer::newParticle | ( | ) | [virtual] |
Returns a new and initialized particle.
The default implementation of this method creates a new particle with ParticleStorage::newParticle and initializes it by calling on each layer the ParticleLayer::initParticle method.
virtual void proland::ParticleProducer::removeOldParticles | ( | ) | [virtual] |
Removes old particles.
The default implementation of this method calls the corresponding method on each layer of this producer.
virtual void proland::ParticleProducer::updateParticles | ( | double | dt | ) | [virtual] |
Updates the particles produced by this producer.
This method calls moveParticles(), removeOldParticles() and addNewParticles(), in this order.
dt | the elapsed time since the last call to this method, in microseconds. |
bool proland::ParticleProducer::initialized [private] |
True if this producer and its layers have been initialized.
vector< ptr<ParticleLayer> > proland::ParticleProducer::layers [private] |
The ParticleLayer associated with this producer.
float* proland::ParticleProducer::params [private] |
Temporary array used in copyToTexture.
int proland::ParticleProducer::paramSize [private] |
The size of the params array.
ptr<ParticleStorage> proland::ParticleProducer::storage [private] |
The ParticleStorage used by this producer to create and store its particles.