hoa_video::private_video::ParticleSystem Class Reference

#include <particle_system.h>

Collaboration diagram for hoa_video::private_video::ParticleSystem:

Collaboration graph
[legend]
List of all members.

Public Member Functions

bool Create (const ParticleSystemDef *sys_def)
 initializes this particle system as an instance of the type of particle system specified by the ParticleSystemDef
void Destroy ()
 destroys the system
bool Draw ()
 draws the system
float GetAge () const
 returns the number of seconds since this system was created
int32 GetNumParticles () const
 returns how many particles are alive in this system
bool IsAlive () const
 returns true if system is still alive
bool IsStopped () const
 returns true if system has been stopped by a call to Stop()
 ParticleSystem ()
 Constructor.
void Stop ()
 stops the system, i.e. makes it stop emitting new particles
bool Update (float frame_time, const EffectParameters &params)
 updates the system

Private Member Functions

void _EmitParticles (int32 num_particles, const EffectParameters &params)
 helper function that emits whatever particles still need to be emitted after calling _KillParticles
void _KillParticles (int32 &num_particles, const EffectParameters &params)
 helper function to kill off any particles that have died
void _MoveParticle (int32 src, int32 dest)
 helper function to move a particle from element src to element dest in the array. This is required any time we kill a particle, because killing particles leaves a hole in the array
void _RespawnParticle (int32 i, const EffectParameters &params)
 creates a new particle at element i in the particle array
void _UpdateParticles (float t, const EffectParameters &params)
 helper function to update properties of particles

Private Attributes

float _age
 age of the system, since it was created
bool _alive
 alive gets set to false when the number of active particles drops to zero
hoa_video::AnimatedImage _animation
 Animation for each particle. If it's non-animated, it just has 1 frame.
float _last_update_time
 last time the system was updated (based on the system's age)
int32 _max_particles
 Total number of particles that this system can have.
int32 _num_particles
std::vector< Color_particle_colors
std::vector< ParticleTexCoord_particle_texcoords
std::vector< ParticleVertex_particle_vertices
std::vector< Particle_particles
bool _stopped
 if stopped is true, no new particles should be emitted
const ParticleSystemDef_system_def

Detailed Description

Definition at line 236 of file particle_system.h.


Constructor & Destructor Documentation

hoa_video::private_video::ParticleSystem::ParticleSystem (  ) 

Constructor.

Definition at line 28 of file particle_system.cpp.

References _age, _alive, _last_update_time, _max_particles, _num_particles, _stopped, and _system_def.


Member Function Documentation

void hoa_video::private_video::ParticleSystem::_EmitParticles ( int32  num_particles,
const EffectParameters params 
) [private]

helper function that emits whatever particles still need to be emitted after calling _KillParticles

Parameters:
num_particles the number of particles that need to be emitted
params the effect parameters to use for this update (orientation and attractor point)

Definition at line 803 of file particle_system.cpp.

References _RespawnParticle().

Referenced by Update().

Here is the call graph for this function:

void hoa_video::private_video::ParticleSystem::_KillParticles ( int32 num_particles,
const EffectParameters params 
) [private]

helper function to kill off any particles that have died

Parameters:
num_particles this is an optimization that lets us avoid killing particles. Killing particles is expensive, because it leaves holes in our array, so we have to shuffle data around to fill those holes. So instead, say we have 10 particles to kill this frame, and we also want to emit 8 particles. Then, instead of killing 10 particles, we only kill 2, and for the other 8, we respawn them immediately.
params the effect parameters to use for this update (orientation and attractor point)

Definition at line 771 of file particle_system.cpp.

References _MoveParticle(), _particles, and _RespawnParticle().

Referenced by Update().

Here is the call graph for this function:

void hoa_video::private_video::ParticleSystem::_MoveParticle ( int32  src,
int32  dest 
) [private]

helper function to move a particle from element src to element dest in the array. This is required any time we kill a particle, because killing particles leaves a hole in the array

Parameters:
src where to move the particle from
dest where to move the particle to

Definition at line 819 of file particle_system.cpp.

References _particles.

Referenced by _KillParticles().

void hoa_video::private_video::ParticleSystem::_RespawnParticle ( int32  i,
const EffectParameters params 
) [private]

creates a new particle at element i in the particle array

Parameters:
i index of the particle to respawn
params the effect parameters to use for this update (orientation and attractor point)

Definition at line 830 of file particle_system.cpp.

References hoa_video::ParticleEmitter::_initial_speed, hoa_video::ParticleEmitter::_initial_speed_variation, hoa_video::ParticleEmitter::_inner_cone, hoa_video::ParticleEmitter::_omnidirectional, hoa_video::ParticleEmitter::_orientation, hoa_video::ParticleEmitter::_outer_cone, _particles, hoa_video::ParticleEmitter::_radius, hoa_video::ParticleEmitter::_shape, hoa_video::ParticleEmitter::_spin, _system_def, hoa_video::ParticleEmitter::_x, hoa_video::ParticleEmitter::_x2, hoa_video::ParticleEmitter::_x_variation, hoa_video::ParticleEmitter::_y, hoa_video::ParticleEmitter::_y2, hoa_video::ParticleEmitter::_y_variation, hoa_video::private_video::ParticleSystemDef::acceleration_variation_x, hoa_video::private_video::ParticleSystemDef::acceleration_variation_y, hoa_video::private_video::ParticleSystemDef::acceleration_x, hoa_video::private_video::ParticleSystemDef::acceleration_y, hoa_video::private_video::ParticleSystemDef::damping, hoa_video::private_video::ParticleSystemDef::damping_variation, hoa_video::private_video::ParticleSystemDef::emitter, hoa_video::EMITTER_SHAPE_CIRCLE, hoa_video::EMITTER_SHAPE_FILLED_CIRCLE, hoa_video::EMITTER_SHAPE_FILLED_RECTANGLE, hoa_video::EMITTER_SHAPE_LINE, hoa_video::EMITTER_SHAPE_POINT, hoa_video::EMITTER_SPIN_CLOCKWISE, hoa_video::EMITTER_SPIN_COUNTERCLOCKWISE, hoa_video::private_video::ParticleSystemDef::keyframes, hoa_video::private_video::EffectParameters::orientation, hoa_video::private_video::ParticleSystemDef::particle_lifetime, hoa_video::private_video::ParticleSystemDef::particle_lifetime_variation, hoa_video::private_video::ParticleSystemDef::radial_acceleration, hoa_video::private_video::ParticleSystemDef::radial_acceleration_variation, hoa_video::private_video::ParticleSystemDef::random_initial_angle, hoa_video::RandomFloat(), hoa_video::RotatePoint(), hoa_video::private_video::ParticleSystemDef::tangential_acceleration, hoa_video::private_video::ParticleSystemDef::tangential_acceleration_variation, hoa_utils::UTILS_2PI, hoa_video::private_video::ParticleSystemDef::wave_amplitude, hoa_video::private_video::ParticleSystemDef::wave_amplitude_variation, hoa_video::private_video::ParticleSystemDef::wave_length, hoa_video::private_video::ParticleSystemDef::wave_length_variation, hoa_video::private_video::ParticleSystemDef::wave_motion_used, hoa_video::private_video::ParticleSystemDef::wind_velocity_variation_x, hoa_video::private_video::ParticleSystemDef::wind_velocity_variation_y, hoa_video::private_video::ParticleSystemDef::wind_velocity_x, and hoa_video::private_video::ParticleSystemDef::wind_velocity_y.

Referenced by _EmitParticles(), and _KillParticles().

Here is the call graph for this function:

void hoa_video::private_video::ParticleSystem::_UpdateParticles ( float  t,
const EffectParameters params 
) [private]

helper function to update properties of particles

Parameters:
t the current frame time
params the effect parameters to use for this update (orientation and attractor point)

Definition at line 556 of file particle_system.cpp.

References _particles, _system_def, hoa_video::private_video::ParticleSystemDef::keyframes, and hoa_video::RandomFloat().

Referenced by Update().

Here is the call graph for this function:

bool hoa_video::private_video::ParticleSystem::Create ( const ParticleSystemDef sys_def  ) 

initializes this particle system as an instance of the type of particle system specified by the ParticleSystemDef

Parameters:
sys_def particle definition to base the system off of
Returns:
success/failure

Definition at line 45 of file particle_system.cpp.

References _age, _alive, _animation, _max_particles, _num_particles, _particle_colors, _particle_texcoords, _particle_vertices, _particles, _stopped, _system_def, hoa_video::AnimatedImage::AddFrame(), hoa_video::private_video::ParticleSystemDef::animation_frame_filenames, hoa_video::private_video::ParticleSystemDef::animation_frame_times, hoa_video::GameVideo::LoadImage(), hoa_video::private_video::ParticleSystemDef::max_particles, and hoa_video::VideoManager.

Referenced by hoa_video::private_video::ParticleManager::_CreateEffect().

Here is the call graph for this function:

void hoa_video::private_video::ParticleSystem::Destroy (  ) 

destroys the system

Definition at line 534 of file particle_system.cpp.

References _animation, _particle_vertices, _particles, hoa_video::GameVideo::DeleteImage(), and hoa_video::VideoManager.

Referenced by hoa_video::private_video::ParticleManager::_CreateEffect().

Here is the call graph for this function:

bool hoa_video::private_video::ParticleSystem::Draw (  ) 

draws the system

Returns:
success/failure

Definition at line 85 of file particle_system.cpp.

References _animation, hoa_video::GameVideo::_BindTexture(), hoa_video::StillImage::_elements, _num_particles, _particle_vertices, _particles, _system_def, hoa_video::private_video::ParticleSystemDef::blend_mode, hoa_video::private_video::ParticleSystemDef::enabled, hoa_video::AnimatedImage::GetCurrentFrameIndex(), hoa_video::AnimatedImage::GetFrame(), hoa_video::AnimatedImage::GetPercentProgress(), hoa_video::GameVideo::GetSceneLightingColor(), hoa_video::private_video::Image::height, hoa_video::private_video::ParticleSystemDef::max_speed_scale, hoa_video::private_video::ParticleSystemDef::min_speed_scale, hoa_video::private_video::ParticleSystemDef::modify_stencil, hoa_video::private_video::ParticleSystemDef::rotate_to_velocity, hoa_video::RotatePoint(), hoa_video::private_video::ParticleSystemDef::rotation_used, hoa_video::private_video::ParticleSystemDef::scene_lighting, hoa_video::private_video::ParticleSystemDef::speed_scale, hoa_video::private_video::ParticleSystemDef::speed_scale_used, hoa_video::private_video::ParticleSystemDef::stencil_op, hoa_video::private_video::TexSheet::tex_ID, hoa_video::private_video::Image::texture_sheet, hoa_video::private_video::Image::u1, hoa_video::private_video::Image::u2, hoa_video::private_video::ParticleSystemDef::use_stencil, hoa_utils::UTILS_HALF_PI, hoa_video::private_video::Image::v1, hoa_video::private_video::Image::v2, hoa_video::VIDEO_BLEND, hoa_video::VIDEO_NO_BLEND, hoa_video::VIDEO_STENCIL_OP_DECREASE, hoa_video::VIDEO_STENCIL_OP_INCREASE, hoa_video::VIDEO_STENCIL_OP_ZERO, hoa_video::VideoManager, hoa_video::Color::white, and hoa_video::private_video::Image::width.

Here is the call graph for this function:

float hoa_video::private_video::ParticleSystem::GetAge (  )  const

returns the number of seconds since this system was created

Returns:
the age of the system

Definition at line 1025 of file particle_system.cpp.

References _age.

int32 hoa_video::private_video::ParticleSystem::GetNumParticles (  )  const

returns how many particles are alive in this system

Returns:
the number of particles in this system

Definition at line 524 of file particle_system.cpp.

bool hoa_video::private_video::ParticleSystem::IsAlive (  )  const

returns true if system is still alive

Returns:
true if alive, false if dead

Definition at line 424 of file particle_system.cpp.

References _alive, _system_def, and hoa_video::private_video::ParticleSystemDef::enabled.

bool hoa_video::private_video::ParticleSystem::IsStopped (  )  const

returns true if system has been stopped by a call to Stop()

Returns:
true if stopped, false if still going

Definition at line 435 of file particle_system.cpp.

References _stopped.

void hoa_video::private_video::ParticleSystem::Stop (  ) 

stops the system, i.e. makes it stop emitting new particles

Definition at line 546 of file particle_system.cpp.

References _stopped.

Referenced by Update().

bool hoa_video::private_video::ParticleSystem::Update ( float  frame_time,
const EffectParameters params 
)

updates the system

Parameters:
frame_time the current frame time
params the effect parameters to use for this update (orientation and attractor point)
Returns:
success/failure

Definition at line 445 of file particle_system.cpp.

References _age, _alive, _animation, hoa_video::ParticleEmitter::_emission_rate, _EmitParticles(), hoa_video::ParticleEmitter::_emitter_mode, _KillParticles(), _last_update_time, _max_particles, _stopped, _system_def, _UpdateParticles(), hoa_video::private_video::ParticleSystemDef::emitter, hoa_video::EMITTER_MODE_ALWAYS, hoa_video::EMITTER_MODE_BURST, hoa_video::EMITTER_MODE_ONE_SHOT, hoa_video::private_video::ParticleSystemDef::enabled, hoa_video::private_video::ParticleSystemDef::max_particles, Stop(), hoa_video::private_video::ParticleSystemDef::system_lifetime, and hoa_video::AnimatedImage::Update().

Here is the call graph for this function:


Member Data Documentation

float hoa_video::private_video::ParticleSystem::_age [private]

age of the system, since it was created

Definition at line 394 of file particle_system.h.

Referenced by Create(), GetAge(), ParticleSystem(), and Update().

bool hoa_video::private_video::ParticleSystem::_alive [private]

alive gets set to false when the number of active particles drops to zero

Definition at line 391 of file particle_system.h.

Referenced by Create(), IsAlive(), ParticleSystem(), and Update().

hoa_video::AnimatedImage hoa_video::private_video::ParticleSystem::_animation [private]

Animation for each particle. If it's non-animated, it just has 1 frame.

Definition at line 368 of file particle_system.h.

Referenced by Create(), Destroy(), Draw(), and Update().

float hoa_video::private_video::ParticleSystem::_last_update_time [private]

last time the system was updated (based on the system's age)

Definition at line 397 of file particle_system.h.

Referenced by ParticleSystem(), and Update().

int32 hoa_video::private_video::ParticleSystem::_max_particles [private]

Total number of particles that this system can have.

Definition at line 371 of file particle_system.h.

Referenced by Create(), ParticleSystem(), and Update().

int32 hoa_video::private_video::ParticleSystem::_num_particles [private]

Number of active particles in this system. (The size of the vectors may be larger, since we might set a particle quota for the system which is higher than what's actually there.)

Definition at line 375 of file particle_system.h.

Referenced by Create(), Draw(), and ParticleSystem().

std::vector<Color> hoa_video::private_video::ParticleSystem::_particle_colors [private]

Definition at line 380 of file particle_system.h.

Referenced by Create().

std::vector<ParticleTexCoord> hoa_video::private_video::ParticleSystem::_particle_texcoords [private]

Definition at line 381 of file particle_system.h.

Referenced by Create().

std::vector<ParticleVertex> hoa_video::private_video::ParticleSystem::_particle_vertices [private]

The array of particle vertices. Note that this array contains FOUR vertices per particle. This is used for rendering the particles with OpenGL

Definition at line 379 of file particle_system.h.

Referenced by Create(), Destroy(), and Draw().

std::vector<Particle> hoa_video::private_video::ParticleSystem::_particles [private]

This array holds everything except positions and colors. The reason we keep positions and colors separate is so that they can be efficiently fed to OpenGL for rendering.

Definition at line 385 of file particle_system.h.

Referenced by _KillParticles(), _MoveParticle(), _RespawnParticle(), _UpdateParticles(), Create(), Destroy(), and Draw().

bool hoa_video::private_video::ParticleSystem::_stopped [private]

if stopped is true, no new particles should be emitted

Definition at line 388 of file particle_system.h.

Referenced by Create(), IsStopped(), ParticleSystem(), Stop(), and Update().

const ParticleSystemDef* hoa_video::private_video::ParticleSystem::_system_def [private]

The system definition, contains information like the emitter properties, lifetime of particles, particle keyframes, etc. Basically everything which isn't instance-specific

Definition at line 365 of file particle_system.h.

Referenced by _RespawnParticle(), _UpdateParticles(), Create(), Draw(), IsAlive(), ParticleSystem(), and Update().


The documentation for this class was generated from the following files:
Generated on Fri Jul 6 23:16:51 2007 for Hero of Allacrost by  doxygen 1.5.1