vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
live_particles.h
1#pragma once
2
3#include <cstdint>
4#include <unordered_map>
5#include <vector>
6
7#include <glm/glm.hpp>
8
9#include "ecs/entity.h"
10
11namespace Vkm::Engine {
12
16struct Particle {
17 glm::vec3 position{0.0f};
18 glm::vec3 velocity{0.0f};
19 float age = 0.0f;
20 float lifetime = 1.0f;
21};
22
31 struct Pool {
32 EntityId emitter;
33 std::vector<Particle> particles;
34 float spawnAccumulator = 0.0f;
35 uint64_t seen = 0;
36 };
37
38 std::unordered_map<uint32_t, Pool> pools;
39
46 const std::vector<Particle>* of(EntityId emitter) const {
47 const auto found = pools.find(emitter.slot());
48 if (found == pools.end() || found->second.emitter != emitter) return nullptr;
49 return &found->second.particles;
50 }
51};
52
53} // namespace Vkm::Engine
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
Every emitter's live particles: ParticleSystem's per-frame product.
Definition live_particles.h:30
std::unordered_map< uint32_t, Pool > pools
By emitter entity slot.
Definition live_particles.h:38
const std::vector< Particle > * of(EntityId emitter) const
The particles emitter has alive, or null when it has none.
Definition live_particles.h:46
One live particle.
Definition live_particles.h:16
float age
Seconds since spawn.
Definition live_particles.h:19
float lifetime
Seconds.
Definition live_particles.h:20
glm::vec3 velocity
World space.
Definition live_particles.h:18
glm::vec3 position
World space.
Definition live_particles.h:17