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 spawnExplosion (glm::vec3 pos, float blastRadius)
 Spawn rocket explosion at pos.
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 Camera &cam, Registry &reg)
 Simulate all effects. Called once per render frame (not per physics tick).
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 arcVertexCount () const
uint32_t smokeCount () const
uint32_t decalCount () const
bool sdfReady () const
const SdfAtlassdfAtlas () const
 Access the SDF atlas for shared use by the HUD system.

Private Attributes

ParticleRenderer renderer_
TracerEffect tracers_
RibbonTrail ribbons_
HitscanEffect hitscan_
SmokeEffect smoke_
ImpactEffect impact_
BulletHoleDecal decals_
ExplosionEffect explosions_
SdfRenderer sdf_
glm::vec3 camPos_ {}
glm::vec3 camForward_ {}
glm::vec3 camRight_ {}
glm::vec3 camUp_ {}
float screenW_ = 1280.f
float screenH_ = 720.f
float frameDt_ = 0.016f

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:

◆ 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.

◆ 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.

◆ 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:

◆ 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:

◆ spawnExplosion()

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

Spawn rocket explosion at pos.

Here is the caller graph for this function:

◆ 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()

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

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

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

◆ camForward_

glm::vec3 ParticleSystem::camForward_ {}
private

◆ camPos_

glm::vec3 ParticleSystem::camPos_ {}
private

◆ camRight_

glm::vec3 ParticleSystem::camRight_ {}
private

◆ camUp_

glm::vec3 ParticleSystem::camUp_ {}
private

◆ decals_

BulletHoleDecal ParticleSystem::decals_
private

◆ explosions_

ExplosionEffect ParticleSystem::explosions_
private

◆ frameDt_

float ParticleSystem::frameDt_ = 0.016f
private

◆ hitscan_

HitscanEffect ParticleSystem::hitscan_
private

◆ impact_

ImpactEffect ParticleSystem::impact_
private

◆ renderer_

ParticleRenderer ParticleSystem::renderer_
private

◆ ribbons_

RibbonTrail ParticleSystem::ribbons_
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

◆ tracers_

TracerEffect ParticleSystem::tracers_
private

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