group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
ParticleSystem Class Reference

Top-level particle system orchestrator. More...

#include <ParticleSystem.hpp>

Collaboration diagram for ParticleSystem:
[legend]

Public Member Functions

bool init (SDL_GPUDevice *dev, SDL_GPUTextureFormat colorFmt, SDL_GPUShaderFormat shaderFmt)
 Initialise all effect sub-systems and the GPU renderer.
void quit ()
 Tear down all GPU resources and effect sub-systems.
void spawnProjectileTracer (entt::entity e, Registry &reg)
 Attach an oriented-capsule tracer to a fast-bullet projectile entity.
void spawnRibbonTrail (entt::entity e, Registry &reg)
 Attach a ribbon trail to a slow/arcing projectile entity (rocket).
void spawnBulletTracer (glm::vec3 origin, glm::vec3 dir, float range=500.f)
 Spawn a one-shot bullet-tracer streak (no ECS entity needed).
void spawnHitscanBeam (glm::vec3 origin, glm::vec3 hitPos, WeaponType wt)
 Spawn an instant energy beam from origin to hitPos.
void spawnImpactEffect (glm::vec3 pos, glm::vec3 normal, SurfaceType surf, WeaponType wt)
 Spawn spark burst + impact flash + bullet hole decal.
void spawnBulletHole (glm::vec3 pos, glm::vec3 normal, WeaponType wt)
 Place a bullet-hole decal on a surface.
void spawnSmoke (glm::vec3 pos, float radius)
 Spawn a smoke cloud at pos.
void spawnFire (glm::vec3 pos, float radius)
 Spawn a one-shot fire puff at pos (orange/red flame billboards).
void spawnExplosion (glm::vec3 pos, float blastRadius)
 Spawn rocket explosion at pos.
void spawnDeathDissolve (const std::vector< glm::vec3 > &worldPoints, glm::vec3 center, glm::vec4 color)
 Spawn a "Thanos snap" death dissolve from a character's posed mesh.
void spawnExplosionVfx (glm::vec3 pos, glm::vec3 normal, float blastRadius, ExplosionVfxKind kind=ExplosionVfxKind::Rocket)
 Spawn a fresh typed explosion VFX profile at pos.
void driveGroundFire (entt::entity fieldEntity, glm::vec3 pos, float radius, float remaining, float duration)
 Drive molotov ground-fire visuals from a replicated FireField entity.
void debugEnergyTeslaArc (glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
 Spawn a short debug preview of the sustained EnergyGun Tesla arc.
void debugEnergyTeslaPreview (glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
void drawWorldText (glm::vec3 worldPos, std::string_view text, glm::vec4 color, float worldHeight)
 Queue world-space SDF text for this frame.
void drawScreenText (glm::vec2 pixelPos, std::string_view text, glm::vec4 color, float pixelHeight)
 Queue screen-space HUD SDF text for this frame.
void setScreenSize (float w, float h)
 Set screen dimensions for HUD rendering. Call before render().
void update (float dt, const NewCamera &cam, Registry &reg)
 Simulate all effects. Called once per render frame (not per physics tick).
void update (float dt, glm::vec3 eye, glm::vec3 forward, glm::vec3 right, glm::vec3 up, Registry &reg)
void setLocalEnergyBeamOriginOverride (glm::vec3 origin)
 Override the local EnergyGun beam origin with the first-person muzzle marker.
void clearLocalEnergyBeamOriginOverride ()
 Clear the local EnergyGun beam origin override for this frame.
void uploadToGpu (SDL_GPUCommandBuffer *cmd)
 Upload all particle data to GPU. Must be called BEFORE render pass.
void render (SDL_GPURenderPass *pass, SDL_GPUCommandBuffer *cmd)
 Issue all particle draw calls. Must be called INSIDE a render pass.
void onWeaponFired (const WeaponFiredEvent &e)
 Handle a weapon-fired event (spawns hitscan beam if applicable).
void onImpact (const ProjectileImpactEvent &e)
 Handle a projectile impact event (spawns sparks and decal).
void onExplosion (const ExplosionEvent &e)
 Handle an explosion event (spawns explosion and smoke).
uint32_t impactCount () const
uint32_t tracerCount () const
uint32_t ribbonVertexCount () const
uint32_t hitscanBeamCount () const
uint32_t railgunArcVertexCount () const
uint32_t energyTeslaArcVertexCount () const
uint32_t energyTeslaBeamCount () const
uint32_t arcVertexCount () const
uint32_t smokeCount () const
uint32_t explosionSpriteCount () const
uint32_t explosionDebrisCount () const
uint32_t decalCount () const
bool sdfReady () const
const SdfAtlas & sdfAtlas () const
 Access the SDF atlas for shared use by the HUD system.

Private Member Functions

void driveRocketSmokeTrails (float dt, Registry &reg)
 Emit short smoke puffs behind live rocket projectile entities.

Private Attributes

ParticleRenderer renderer_
TracerEffect tracers_
RibbonTrail ribbons_
HitscanEffect hitscan_
TeslaBeamEffect tesla_
EnergyTeslaArcEffect energyTesla_
SmokeEffect smoke_
ImpactEffect impact_
BulletHoleDecal decals_
ExplosionVfxEffect explosionVfx_
DeathDissolveEffect death_
SdfRenderer sdf_
glm::vec3 camPos_ {}
glm::vec3 camForward_ {}
glm::vec3 camRight_ {}
glm::vec3 camUp_ {}
glm::vec3 localEnergyBeamOriginOverride_ {0.0f}
bool localEnergyBeamOriginOverrideValid_ = false
float screenW_ = 1280.f
float screenH_ = 720.f
float frameDt_ = 0.016f
std::unordered_map< entt::entity, float > rocketSmokeAccumulators_
std::vector< ArcVertex > arcScratch_

Detailed Description

Top-level particle system orchestrator.

Owns all effect sub-systems and the ParticleRenderer. Lifecycle: Game::init() → particleSystem.init() Game::iterate() → particleSystem.update(dt, cam) Renderer::drawFrame() calls internally: particleSystem.uploadToGpu(cmd) [before render pass] particleSystem.render(pass, cmd) [inside render pass] Game::quit() → particleSystem.quit()

Member Function Documentation

◆ arcVertexCount()

uint32_t ParticleSystem::arcVertexCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ clearLocalEnergyBeamOriginOverride()

void ParticleSystem::clearLocalEnergyBeamOriginOverride ( )
inline

Clear the local EnergyGun beam origin override for this frame.

◆ debugEnergyTeslaArc()

void ParticleSystem::debugEnergyTeslaArc ( glm::vec3 origin,
glm::vec3 guidePoint,
glm::vec3 hitPoint,
bool locked,
float lockStrength )

Spawn a short debug preview of the sustained EnergyGun Tesla arc.

Here is the caller graph for this function:

◆ debugEnergyTeslaPreview()

void ParticleSystem::debugEnergyTeslaPreview ( glm::vec3 origin,
glm::vec3 guidePoint,
glm::vec3 hitPoint,
bool locked,
float lockStrength )
Here is the caller graph for this function:

◆ decalCount()

uint32_t ParticleSystem::decalCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ drawScreenText()

void ParticleSystem::drawScreenText ( glm::vec2 pixelPos,
std::string_view text,
glm::vec4 color,
float pixelHeight )

Queue screen-space HUD SDF text for this frame.

Parameters
pixelPosScreen position in pixels (top-left origin).
textUTF-8 string to render.
colorRGBA text colour.
pixelHeightGlyph height in pixels.

◆ drawWorldText()

void ParticleSystem::drawWorldText ( glm::vec3 worldPos,
std::string_view text,
glm::vec4 color,
float worldHeight )

Queue world-space SDF text for this frame.

Parameters
worldPosWorld-space anchor position.
textUTF-8 string to render.
colorRGBA text colour.
worldHeightGlyph height in world units.

◆ driveGroundFire()

void ParticleSystem::driveGroundFire ( entt::entity fieldEntity,
glm::vec3 pos,
float radius,
float remaining,
float duration )

Drive molotov ground-fire visuals from a replicated FireField entity.

◆ driveRocketSmokeTrails()

void ParticleSystem::driveRocketSmokeTrails ( float dt,
Registry & reg )
private

Emit short smoke puffs behind live rocket projectile entities.

Here is the caller graph for this function:

◆ energyTeslaArcVertexCount()

uint32_t ParticleSystem::energyTeslaArcVertexCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ energyTeslaBeamCount()

uint32_t ParticleSystem::energyTeslaBeamCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ explosionDebrisCount()

uint32_t ParticleSystem::explosionDebrisCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ explosionSpriteCount()

uint32_t ParticleSystem::explosionSpriteCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ hitscanBeamCount()

uint32_t ParticleSystem::hitscanBeamCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ impactCount()

uint32_t ParticleSystem::impactCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ init()

bool ParticleSystem::init ( SDL_GPUDevice * dev,
SDL_GPUTextureFormat colorFmt,
SDL_GPUShaderFormat shaderFmt )

Initialise all effect sub-systems and the GPU renderer.

Parameters
devThe SDL GPU device.
colorFmtSwapchain colour format.
shaderFmtShader binary format (SPIRV or MSL).
Returns
True on success.

◆ onExplosion()

void ParticleSystem::onExplosion ( const ExplosionEvent & e)

Handle an explosion event (spawns explosion and smoke).

Here is the call graph for this function:

◆ onImpact()

void ParticleSystem::onImpact ( const ProjectileImpactEvent & e)

Handle a projectile impact event (spawns sparks and decal).

Here is the call graph for this function:

◆ onWeaponFired()

void ParticleSystem::onWeaponFired ( const WeaponFiredEvent & e)

Handle a weapon-fired event (spawns hitscan beam if applicable).

Here is the call graph for this function:

◆ quit()

void ParticleSystem::quit ( )

Tear down all GPU resources and effect sub-systems.

◆ railgunArcVertexCount()

uint32_t ParticleSystem::railgunArcVertexCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ render()

void ParticleSystem::render ( SDL_GPURenderPass * pass,
SDL_GPUCommandBuffer * cmd )

Issue all particle draw calls. Must be called INSIDE a render pass.

◆ ribbonVertexCount()

uint32_t ParticleSystem::ribbonVertexCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ sdfAtlas()

const SdfAtlas & ParticleSystem::sdfAtlas ( ) const
inlinenodiscard

Access the SDF atlas for shared use by the HUD system.

◆ sdfReady()

bool ParticleSystem::sdfReady ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ setLocalEnergyBeamOriginOverride()

void ParticleSystem::setLocalEnergyBeamOriginOverride ( glm::vec3 origin)
inline

Override the local EnergyGun beam origin with the first-person muzzle marker.

◆ setScreenSize()

void ParticleSystem::setScreenSize ( float w,
float h )
inline

Set screen dimensions for HUD rendering. Call before render().

◆ smokeCount()

uint32_t ParticleSystem::smokeCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ spawnBulletHole()

void ParticleSystem::spawnBulletHole ( glm::vec3 pos,
glm::vec3 normal,
WeaponType wt )

Place a bullet-hole decal on a surface.

Here is the caller graph for this function:

◆ spawnBulletTracer()

void ParticleSystem::spawnBulletTracer ( glm::vec3 origin,
glm::vec3 dir,
float range = 500.f )

Spawn a one-shot bullet-tracer streak (no ECS entity needed).

Parameters
originMuzzle world position (e.g. hip-fire offset from eye).
dirNormalised fire direction.
rangeStreak length in world units.
Here is the caller graph for this function:

◆ spawnDeathDissolve()

void ParticleSystem::spawnDeathDissolve ( const std::vector< glm::vec3 > & worldPoints,
glm::vec3 center,
glm::vec4 color )

Spawn a "Thanos snap" death dissolve from a character's posed mesh.

Parameters
worldPointsWorld-space points sampled from the death pose.
centerBody center (world) for the radial/sweep basis.
colorParticle tint (mesh has no texture; ~light grey).

◆ spawnExplosion()

void ParticleSystem::spawnExplosion ( glm::vec3 pos,
float blastRadius )

Spawn rocket explosion at pos.

Here is the call graph for this function:

◆ spawnExplosionVfx()

void ParticleSystem::spawnExplosionVfx ( glm::vec3 pos,
glm::vec3 normal,
float blastRadius,
ExplosionVfxKind kind = ExplosionVfxKind::Rocket )

Spawn a fresh typed explosion VFX profile at pos.

Here is the caller graph for this function:

◆ spawnFire()

void ParticleSystem::spawnFire ( glm::vec3 pos,
float radius )

Spawn a one-shot fire puff at pos (orange/red flame billboards).

◆ spawnHitscanBeam()

void ParticleSystem::spawnHitscanBeam ( glm::vec3 origin,
glm::vec3 hitPos,
WeaponType wt )

Spawn an instant energy beam from origin to hitPos.

Here is the caller graph for this function:

◆ spawnImpactEffect()

void ParticleSystem::spawnImpactEffect ( glm::vec3 pos,
glm::vec3 normal,
SurfaceType surf,
WeaponType wt )

Spawn spark burst + impact flash + bullet hole decal.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawnProjectileTracer()

void ParticleSystem::spawnProjectileTracer ( entt::entity e,
Registry & reg )

Attach an oriented-capsule tracer to a fast-bullet projectile entity.

◆ spawnRibbonTrail()

void ParticleSystem::spawnRibbonTrail ( entt::entity e,
Registry & reg )

Attach a ribbon trail to a slow/arcing projectile entity (rocket).

◆ spawnSmoke()

void ParticleSystem::spawnSmoke ( glm::vec3 pos,
float radius )

Spawn a smoke cloud at pos.

Here is the caller graph for this function:

◆ tracerCount()

uint32_t ParticleSystem::tracerCount ( ) const
inlinenodiscard
Here is the caller graph for this function:

◆ update() [1/2]

void ParticleSystem::update ( float dt,
const NewCamera & cam,
Registry & reg )

Simulate all effects. Called once per render frame (not per physics tick).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update() [2/2]

void ParticleSystem::update ( float dt,
glm::vec3 eye,
glm::vec3 forward,
glm::vec3 right,
glm::vec3 up,
Registry & reg )
Here is the call graph for this function:

◆ uploadToGpu()

void ParticleSystem::uploadToGpu ( SDL_GPUCommandBuffer * cmd)

Upload all particle data to GPU. Must be called BEFORE render pass.

Member Data Documentation

◆ arcScratch_

std::vector<ArcVertex> ParticleSystem::arcScratch_
private

◆ camForward_

glm::vec3 ParticleSystem::camForward_ {}
private

◆ camPos_

glm::vec3 ParticleSystem::camPos_ {}
private

◆ camRight_

glm::vec3 ParticleSystem::camRight_ {}
private

◆ camUp_

glm::vec3 ParticleSystem::camUp_ {}
private

◆ death_

DeathDissolveEffect ParticleSystem::death_
private

◆ decals_

BulletHoleDecal ParticleSystem::decals_
private

◆ energyTesla_

EnergyTeslaArcEffect ParticleSystem::energyTesla_
private

◆ explosionVfx_

ExplosionVfxEffect ParticleSystem::explosionVfx_
private

◆ frameDt_

float ParticleSystem::frameDt_ = 0.016f
private

◆ hitscan_

HitscanEffect ParticleSystem::hitscan_
private

◆ impact_

ImpactEffect ParticleSystem::impact_
private

◆ localEnergyBeamOriginOverride_

glm::vec3 ParticleSystem::localEnergyBeamOriginOverride_ {0.0f}
private

◆ localEnergyBeamOriginOverrideValid_

bool ParticleSystem::localEnergyBeamOriginOverrideValid_ = false
private

◆ renderer_

ParticleRenderer ParticleSystem::renderer_
private

◆ ribbons_

RibbonTrail ParticleSystem::ribbons_
private

◆ rocketSmokeAccumulators_

std::unordered_map<entt::entity, float> ParticleSystem::rocketSmokeAccumulators_
private

◆ screenH_

float ParticleSystem::screenH_ = 720.f
private

◆ screenW_

float ParticleSystem::screenW_ = 1280.f
private

◆ sdf_

SdfRenderer ParticleSystem::sdf_
private

◆ smoke_

SmokeEffect ParticleSystem::smoke_
private

◆ tesla_

TeslaBeamEffect ParticleSystem::tesla_
private

◆ tracers_

TracerEffect ParticleSystem::tracers_
private

The documentation for this class was generated from the following files: