Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
ParticleSystem.h
Go to the documentation of this file.
1/**
2 * @file ParticleSystem.h
3 * @ingroup mnd_render
4 * @brief Pool-allocated CPU particles drawn as additive billboards.
5 *
6 * The Engine owns one ParticleSystem. Emitter components push particles into
7 * it via Spawn(); each frame Update() ages them, then Render() issues one
8 * billboarded draw per live particle right after the lit pass.
9 *
10 * Scope: hundreds of particles, no instancing yet. Cheap enough for the
11 * boomer-shooter FX budget (sparks, blood, muzzle flash, torches). If counts
12 * grow into the thousands, the obvious upgrade is a single instanced draw
13 * with a streaming VBO of per-particle data.
14 */
15
16#pragma once
17
18#include <cstddef>
19#include <memory>
20#include <vector>
21
22#include "Types.h"
23
24namespace mnd
25{
26class Mesh;
27class ShaderProgram;
28
29struct CameraData;
30
32{
33 vec3 position {0.0F};
34 vec3 velocity {0.0F};
35 vec3 acceleration {0.0F}; ///< World-space gravity / drag, applied each frame.
37 vec4 colorEnd {1.0F};
38 float age = 0.0F;
39 float lifetime = 1.0F;
40 float sizeStart = 0.2F;
41 float sizeEnd = 0.0F;
42
43 [[nodiscard]] bool IsAlive() const { return age < lifetime; }
44};
45
47{
48 public:
49 void Init();
50 void Shutdown();
51
52 /// Step every live particle, swap-erase dead ones.
53 void Update(f32 deltaTime);
54
55 /// Camera-aligned billboard pass. Call after the lit pass, before UI.
56 void Render(const CameraData &cameraData);
57
58 /// Push a fully-configured particle into the pool. Drops oldest if full.
59 void Spawn(const Particle &particle);
60
61 void Clear() { m_particles.clear(); }
62
63 [[nodiscard]] std::size_t GetAliveCount() const { return m_particles.size(); }
64
65 [[nodiscard]] std::size_t GetCapacity() const { return m_capacity; }
66
67 void SetPaused(bool paused) { m_paused = paused; }
68
69 [[nodiscard]] bool IsPaused() const { return m_paused; }
70
71 private:
72 std::shared_ptr<Mesh> m_quad;
73 std::shared_ptr<ShaderProgram> m_shader;
74 std::vector<Particle> m_particles;
75 std::size_t m_capacity = 4096;
76 bool m_paused = false;
77};
78
79} // namespace mnd
Engine-wide primitive type aliases and GLM math imports.
std::size_t GetCapacity() const
void Update(f32 deltaTime)
Step every live particle, swap-erase dead ones.
bool IsPaused() const
std::size_t GetAliveCount() const
void Spawn(const Particle &particle)
Push a fully-configured particle into the pool. Drops oldest if full.
void SetPaused(bool paused)
void Render(const CameraData &cameraData)
Camera-aligned billboard pass. Call after the lit pass, before UI.
glm::vec4 vec4
4-component float vector (e.g. RGBA colour, homogeneous coords).
Definition Types.h:52
glm::vec3 vec3
3-component float vector (e.g. world position, RGB colour, normals).
Definition Types.h:51
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40
Per-frame camera matrices and world-space position.
Definition Common.h:35
vec3 acceleration
World-space gravity / drag, applied each frame.
bool IsAlive() const