|
group2 0.1.0
CSE 125 Group 2
|
Fixed-capacity particle pool with O(1) swap-remove. More...
#include <ParticlePool.hpp>
Public Member Functions | |
| T * | spawn () |
| Allocate a new slot (zero-initialised). Returns nullptr when full. | |
| void | kill (uint32_t i) |
| O(1) swap-remove. Does NOT preserve order. | |
| void | update (auto fn) |
| Iterate all live particles. | |
| const T * | rawData () const |
| Pointer to the contiguous live data for GPU upload. | |
| uint32_t | liveCount () const |
| bool | empty () const |
| bool | full () const |
Public Attributes | |
| std::array< T, MaxN > | data {} |
| uint32_t | count = 0 |
Fixed-capacity particle pool with O(1) swap-remove.
Particles are stored in a contiguous array[0..count-1]. Calling kill(i) swaps data[i] with data[count-1] and decrements count — stable ordering is NOT preserved (intentional; no sort needed for upload).
Usage: auto* p = pool.spawn(); // nullptr when full pool.update([](T& p) -> bool { return p.lifetime > 0; }); pool.kill(i);
|
inline |
|
inline |
|
inline |
O(1) swap-remove. Does NOT preserve order.
|
inline |
|
inline |
Pointer to the contiguous live data for GPU upload.
|
inline |
Allocate a new slot (zero-initialised). Returns nullptr when full.
|
inline |
Iterate all live particles.
fn(T& p) → bool: return false to kill. Iterates backwards so kill() inside fn doesn't skip elements.
| uint32_t ParticlePool< T, MaxN >::count = 0 |
| std::array<T, MaxN> ParticlePool< T, MaxN >::data {} |