group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
ParticleSystem.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "ParticleEvents.hpp"
17#include "renderer/Camera.hpp"
18#include "sdf/SdfRenderer.hpp"
19
20#include <entt/entt.hpp>
21#include <glm/glm.hpp>
22#include <string_view>
23
35{
36public:
42 bool init(SDL_GPUDevice* dev, SDL_GPUTextureFormat colorFmt, SDL_GPUShaderFormat shaderFmt);
43
45 void quit();
46
47 // Spawn API (call from weapon / game event logic)
48
50 void spawnProjectileTracer(entt::entity e, Registry& reg);
51
53 void spawnRibbonTrail(entt::entity e, Registry& reg);
54
59 void spawnBulletTracer(glm::vec3 origin, glm::vec3 dir, float range = 500.f);
60
62 void spawnHitscanBeam(glm::vec3 origin, glm::vec3 hitPos, WeaponType wt);
63
65 void spawnImpactEffect(glm::vec3 pos, glm::vec3 normal, SurfaceType surf, WeaponType wt);
66
68 void spawnBulletHole(glm::vec3 pos, glm::vec3 normal, WeaponType wt);
69
71 void spawnSmoke(glm::vec3 pos, float radius);
72
74 void spawnExplosion(glm::vec3 pos, float blastRadius);
75
76 // SDF text (queued per frame, flushed in render)
77
83 void drawWorldText(glm::vec3 worldPos, std::string_view text, glm::vec4 color, float worldHeight);
84
90 void drawScreenText(glm::vec2 pixelPos, std::string_view text, glm::vec4 color, float pixelHeight);
91
92 // Frame lifecycle
93
95 void setScreenSize(float w, float h)
96 {
97 screenW_ = w;
98 screenH_ = h;
99 }
100
102 void update(float dt, const Camera& cam, Registry& reg);
103
105 void uploadToGpu(SDL_GPUCommandBuffer* cmd);
106
108 void render(SDL_GPURenderPass* pass, SDL_GPUCommandBuffer* cmd);
109
110 // entt::dispatcher event handlers
112 void onWeaponFired(const WeaponFiredEvent& e);
113
115 void onImpact(const ProjectileImpactEvent& e);
116
118 void onExplosion(const ExplosionEvent& e);
119
120 // Live-count accessors (for debug UI)
121 [[nodiscard]] uint32_t impactCount() const { return impact_.count(); }
122 [[nodiscard]] uint32_t tracerCount() const { return tracers_.count(); }
123 [[nodiscard]] uint32_t ribbonVertexCount() const { return ribbons_.count(); }
124 [[nodiscard]] uint32_t hitscanBeamCount() const { return hitscan_.activeBeamCount(); }
125 [[nodiscard]] uint32_t arcVertexCount() const { return hitscan_.arcCount(); }
126 [[nodiscard]] uint32_t smokeCount() const { return smoke_.count(); }
127 [[nodiscard]] uint32_t decalCount() const { return decals_.count(); }
128 [[nodiscard]] bool sdfReady() const { return sdf_.ready(); }
129
130private:
131 ParticleRenderer renderer_;
132 TracerEffect tracers_;
133 RibbonTrail ribbons_;
134 HitscanEffect hitscan_;
135 SmokeEffect smoke_;
136 ImpactEffect impact_;
137 BulletHoleDecal decals_;
138 ExplosionEffect explosions_;
139 SdfRenderer sdf_;
140
141 // Cached each frame from Camera
142 glm::vec3 camPos_{};
143 glm::vec3 camForward_{};
144 glm::vec3 camRight_{};
145 glm::vec3 camUp_{};
146 float screenW_ = 1280.f;
147 float screenH_ = 720.f;
148
149 float frameDt_ = 0.016f; // last dt, needed by spawn callbacks
150};
Ring-buffer pool of world-space decal quads for bullet holes and scorch marks.
Shockwave ring and fireball explosion effect for rocket impacts.
Hitscan energy beam effect using fBm path deviation and Bezier spines.
Spark burst and impact flash effect for projectile hits.
Event structs dispatched via entt::dispatcher for particle spawning.
Owns all particle GPU pipelines and per-category GPU buffers.
Projectile component and weapon/surface type enumerations.
SurfaceType
Surface material hit by a projectile — drives impact effect parameters.
Definition Projectile.hpp:21
WeaponType
Weapon type — determines tracer style, damage, sound, and impact effects.
Definition Projectile.hpp:11
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
Camera-facing ribbon trail builder for slow/arcing projectiles.
High-level SDF text renderer for world-space and screen-space text.
Volumetric smoke billboard particle manager with back-to-front sorting.
Oriented-capsule tracer management for fast-bullet projectile entities.
Ring-buffer pool of 512 world-space decal quads (bullet holes, scorch marks).
Definition BulletHoleDecal.hpp:18
uint32_t count() const
Definition BulletHoleDecal.hpp:31
Definition Camera.hpp:6
Spawns shockwave ring + fireball + smoke cloud for rocket explosions.
Definition ExplosionEffect.hpp:16
Hitscan energy beam using fBm (fractional Brownian motion) path deviation.
Definition HitscanEffect.hpp:33
uint32_t activeBeamCount() const
Get the number of active beams.
Definition HitscanEffect.cpp:394
uint32_t arcCount() const
Get the number of arc vertices currently generated.
Definition HitscanEffect.hpp:53
Spawns spark bursts + impact flash quads on hit events.
Definition ImpactEffect.hpp:14
uint32_t count() const
Definition ImpactEffect.hpp:27
Owns all particle GPU pipelines and per-category GPU buffers.
Definition ParticleRenderer.hpp:20
Top-level particle system orchestrator.
Definition ParticleSystem.hpp:35
bool init(SDL_GPUDevice *dev, SDL_GPUTextureFormat colorFmt, SDL_GPUShaderFormat shaderFmt)
Initialise all effect sub-systems and the GPU renderer.
Definition ParticleSystem.cpp:13
void onWeaponFired(const WeaponFiredEvent &e)
Handle a weapon-fired event (spawns hitscan beam if applicable).
Definition ParticleSystem.cpp:163
void update(float dt, const Camera &cam, Registry &reg)
Simulate all effects. Called once per render frame (not per physics tick).
Definition ParticleSystem.cpp:54
uint32_t tracerCount() const
Definition ParticleSystem.hpp:122
void drawWorldText(glm::vec3 worldPos, std::string_view text, glm::vec4 color, float worldHeight)
Queue world-space SDF text for this frame.
Definition ParticleSystem.cpp:151
void quit()
Tear down all GPU resources and effect sub-systems.
Definition ParticleSystem.cpp:46
void drawScreenText(glm::vec2 pixelPos, std::string_view text, glm::vec4 color, float pixelHeight)
Queue screen-space HUD SDF text for this frame.
Definition ParticleSystem.cpp:156
void spawnImpactEffect(glm::vec3 pos, glm::vec3 normal, SurfaceType surf, WeaponType wt)
Spawn spark burst + impact flash + bullet hole decal.
Definition ParticleSystem.cpp:128
uint32_t ribbonVertexCount() const
Definition ParticleSystem.hpp:123
uint32_t impactCount() const
Definition ParticleSystem.hpp:121
void spawnHitscanBeam(glm::vec3 origin, glm::vec3 hitPos, WeaponType wt)
Spawn an instant energy beam from origin to hitPos.
Definition ParticleSystem.cpp:123
bool sdfReady() const
Definition ParticleSystem.hpp:128
void spawnBulletHole(glm::vec3 pos, glm::vec3 normal, WeaponType wt)
Place a bullet-hole decal on a surface.
Definition ParticleSystem.cpp:134
void spawnSmoke(glm::vec3 pos, float radius)
Spawn a smoke cloud at pos.
Definition ParticleSystem.cpp:139
uint32_t smokeCount() const
Definition ParticleSystem.hpp:126
void spawnBulletTracer(glm::vec3 origin, glm::vec3 dir, float range=500.f)
Spawn a one-shot bullet-tracer streak (no ECS entity needed).
Definition ParticleSystem.cpp:117
uint32_t arcVertexCount() const
Definition ParticleSystem.hpp:125
void onExplosion(const ExplosionEvent &e)
Handle an explosion event (spawns explosion and smoke).
Definition ParticleSystem.cpp:174
uint32_t decalCount() const
Definition ParticleSystem.hpp:127
void setScreenSize(float w, float h)
Set screen dimensions for HUD rendering. Call before render().
Definition ParticleSystem.hpp:95
void render(SDL_GPURenderPass *pass, SDL_GPUCommandBuffer *cmd)
Issue all particle draw calls. Must be called INSIDE a render pass.
Definition ParticleSystem.cpp:96
void spawnRibbonTrail(entt::entity e, Registry &reg)
Attach a ribbon trail to a slow/arcing projectile entity (rocket).
Definition ParticleSystem.cpp:111
void uploadToGpu(SDL_GPUCommandBuffer *cmd)
Upload all particle data to GPU. Must be called BEFORE render pass.
Definition ParticleSystem.cpp:81
void spawnExplosion(glm::vec3 pos, float blastRadius)
Spawn rocket explosion at pos.
Definition ParticleSystem.cpp:144
void spawnProjectileTracer(entt::entity e, Registry &reg)
Attach an oriented-capsule tracer to a fast-bullet projectile entity.
Definition ParticleSystem.cpp:103
uint32_t hitscanBeamCount() const
Definition ParticleSystem.hpp:124
void onImpact(const ProjectileImpactEvent &e)
Handle a projectile impact event (spawns sparks and decal).
Definition ParticleSystem.cpp:169
Builds camera-facing ribbon trails for slow/arcing projectiles (rockets).
Definition RibbonTrail.hpp:17
uint32_t count() const
Definition RibbonTrail.hpp:26
Queues SDF glyph quads for world-space and screen-space text.
Definition SdfRenderer.hpp:18
bool ready() const
Check whether the underlying atlas is ready for rendering.
Definition SdfRenderer.hpp:71
Manages volumetric smoke billboard particles.
Definition SmokeEffect.hpp:20
uint32_t count() const
Definition SmokeEffect.hpp:36
Manages oriented-capsule tracers for fast-bullet projectile entities.
Definition TracerEffect.hpp:18
uint32_t count() const
Definition TracerEffect.hpp:41
Emitted when a rocket/grenade explodes.
Definition ParticleEvents.hpp:33
Emitted when a projectile or hitscan hits a surface.
Definition ParticleEvents.hpp:24
Emitted when a weapon fires (both hitscan and projectile).
Definition ParticleEvents.hpp:13