Game Development Reference
In-Depth Information
isDead —True if every particle in the system is dead, and false
otherwise. Note that every particle being dead doesn't imply that
the system is empty. Empty means that we have no particles in the
system. Dead means that we have particles in the system, but they
are all marked dead.
removeDeadParticles —Searches the attribute list _particle
and removes any dead particles from the list:
void PSystem::removeDeadParticles()
{
std::list<Attribute>::iterator i;
i = _particles.begin();
while( i != _particles.end() )
{
if( i->_isAlive == false )
{
// erase returns the next iterator, so no need
// to incrememnt to the next one ourselves.
i = _particles.erase(i);
}
else
{
i++; // next in list
}
}
}
Remark: This method is usually called in a subclass's update
method to remove any particles that have been killed (marked as
dead). However, for some particle systems, it may be advantageous to
recycle dead particles rather than remove them. That is, instead of
allocating and deallocating particles from the list as they are born and
killed, we simply reset a dead particle to create a new one. The snow
system we implement in section 14.3 demonstrates this technique.
14.2.1 Drawing a Particle System
Since the particle system is dynamic, we need to update the particle in
the system every frame. An intuitive but inefficient approach to render-
ing the particle system is as follows:
Create a vertex buffer large enough to hold the maximum number
of particles.
For each frame:
A. Update all particles.
B. Copy all living particles to the vertex buffer.
C. Draw the vertex buffer.
Team-Fly ®
Search WWH ::




Custom Search