SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CParticleEngine< P, PD, VEC > Class Template Reference

An abstract particle engine. More...

#include <SageParticleEngine.h>

Inheritance diagram for Sage::CParticleEngine< P, PD, VEC >:
Collaboration diagram for Sage::CParticleEngine< P, PD, VEC >:

Public Member Functions

 CParticleEngine ()
 Constructor.
 
virtual ~CParticleEngine ()
 Destructor.
 
void Create (const PD &d)
 Create particle.
 
void Step ()
 Animation step.
 
void Clear (float=0.1f)
 Fade out all particles.
 
void Clear (UINT)
 Clear out a particular kind of particle.
 
void Translate (const VEC &)
 Translate all particles.
 
void TranslateTo (const VEC &)
 Translate all particles to a point.
 
void SetOrigin (const VEC &)
 Set origin.
 

Protected Member Functions

void Move ()
 Move all particles.
 
const float GetLifeFraction (const P *) const
 Get life fraction.
 
void Cull ()
 Cull old dead particles.
 
void Rescale ()
 Compute new particle scales.
 
void Fade ()
 Compute new particle alpha channel.
 

Protected Attributes

std::list< P * > m_stdList
 Particle list.
 
VEC m_vOrigin
 Origin in world space.
 

Additional Inherited Members

- Static Protected Attributes inherited from Sage::CComponent
static std::unique_ptr< CTimerm_pTimer = std::make_unique<CTimer>()
 Pointer to a timer.
 
static std::unique_ptr< CRandomm_pRandom = std::make_unique<CRandom>()
 Pointer to a PRNG.
 
static std::unique_ptr< CSoundm_pSound = std::make_unique<CSound>()
 Pointer to sound manager.
 
static std::unique_ptr< CKeyboardm_pKeyboard
 Pointer to a keyboard handler.
 
static std::unique_ptr< CMousem_pMouse = std::make_unique<CMouse>()
 Pointer to a mouse handler.
 
static std::unique_ptr< CControllerm_pController
 Pointer to a controller.
 

Detailed Description

template<class P, class PD, class VEC>
class Sage::CParticleEngine< P, PD, VEC >

A particle engine is responsible for managing a system of particles. Its step function must be called once per animation frame. Templates are used to make this class independent of operating system and renderer implementation.

Template Parameters
PPartice class.
PParticle descriptor.
VECVector.

Constructor & Destructor Documentation

◆ CParticleEngine()

template<class P , class PD , class VEC >
CParticleEngine::CParticleEngine ( )

Constructor.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ ~CParticleEngine()

template<class P , class PD , class VEC >
CParticleEngine::~CParticleEngine ( )
virtual

Destructor. Delete all of the particles in the particle list.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

Member Function Documentation

◆ Clear() [1/2]

template<class P , class PD , class VEC >
void CParticleEngine::Clear ( float t = 0.1f)

Pre-emptively trigger a fade out of all particles.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.
Parameters
tTime over which to fade out.

◆ Clear() [2/2]

template<class P , class PD , class VEC >
void CParticleEngine::Clear ( UINT n)

Pre-emptively trigger scale out of all particles of a given type.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.
Parameters
nSprite type of particle to be cleared.

◆ Create()

template<class P , class PD , class VEC >
void CParticleEngine::Create ( const PD & d)

Create a particle given its particle descriptor.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.
Parameters
dParticle descriptor.

◆ Cull()

template<class P , class PD , class VEC >
void CParticleEngine::Cull ( )
protected

Remove from the particle list and delete those particles that have reached or exceeded their lifespan.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ Fade()

template<class P , class PD , class VEC >
void CParticleEngine::Fade ( )
protected

Fade out all particles in the particle list according to how much of their lifespans they have lived up to this point.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ GetLifeFraction()

template<class P , class PD , class VEC >
const float CParticleEngine::GetLifeFraction ( const P * p) const
protected

Get the remaining fraction of a particle's lifespan.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.
Parameters
pPointer to a particle.
Returns
Particle's age as a float between 0.0f and 1.0f.
Here is the call graph for this function:

◆ Move()

template<class P , class PD , class VEC >
void CParticleEngine::Move ( )
protected

Move all particles in the particle list.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ Rescale()

template<class P , class PD , class VEC >
void CParticleEngine::Rescale ( )
protected

Rescale all of the particles in the particle list according to how much of their lifespans they have lived up to this point.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ SetOrigin()

template<class P , class PD , class VEC >
void CParticleEngine::SetOrigin ( const VEC & v)

Set origin in world space.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.
Parameters
vNew origin.

◆ Step()

template<class P , class PD , class VEC >
void CParticleEngine::Step ( )

Move all particles, cull any that have exceeded their lifespan, and recompute the scale and transparency of the ones remaining.

Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ Translate()

template<class P , class PD , class VEC >
void CParticleEngine::Translate ( const VEC & delta)

Translate all particles simultaneously by the same amount.

Parameters
deltaTranslation amount.
Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.

◆ TranslateTo()

template<class P , class PD , class VEC >
void CParticleEngine::TranslateTo ( const VEC & v)

Translate all particles simultaneously to the same point.

Parameters
vDestination.
Template Parameters
PParticle type, 2D or 3D.
PDParticle descriptor type, 2D or 3D.
VECVector type, 2D or 3D.