Game Development Reference
In-Depth Information
_emitRate —The rate at which new particles are added to the
system. This is usually measured in particles per second.
_size —The size of all the particles in the system
_particles —A list of particle attributes in the system. We work
with this list to create, destroy, and update particles. When we are
ready to draw the particles, we copy a portion of the list nodes to
the vertex buffer and draw the particles. Then we copy another
batch and draw the particles, and we repeat this process until all
the particles have been drawn. This is an oversimplification; we
explain the drawing process in detail in section 14.2.1.
_maxParticles —The maximum number of particles that the
system is allowed to have at a given time. For instance, if particles
are being created faster than they are being destroyed, we end up
with a huge amount of particles over time. This member helps us
avoid that scenario.
_vbSize —The number of particles that our vertex buffer can hold
at a given time. This value is independent of the number of parti-
cles in the actual particle system.
Note: The data member _vbOffset and _vbBatchSize are used to
render the particle system. We defer a discussion of them until section
14.2.1.
Methods:
PSystem / ~PSystem —The constructor initializes default values
and the destructor releases device interfaces (vertex buffer,
texture).
init —This method does Direct3D device-dependent initialization
work, such as creating the vertex buffer to store the point sprites
and creating the texture. The vertex buffer creation contains some
flags that we have discussed but haven't used until now:
hr = device->CreateVertexBuffer(
_vbSize * sizeof(Particle),
D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY,
Particle::FVF,
D3DPOOL_DEFAULT,
&_vb,
0);
Notice that we are using a dynamic vertex buffer. This is
because we will need to update our particles every frame,
which means we will need to access the vertex buffer's mem-
ory. Recall that accessing a static vertex buffer is unacceptably
slow; we therefore use a dynamic vertex buffer.
Search WWH ::




Custom Search