group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
ParticlePool< T, MaxN > Struct Template Reference

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
 

Detailed Description

template<typename T, uint32_t MaxN>
struct ParticlePool< T, MaxN >

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);

Member Function Documentation

◆ empty()

template<typename T , uint32_t MaxN>
bool ParticlePool< T, MaxN >::empty ( ) const
inline

◆ full()

template<typename T , uint32_t MaxN>
bool ParticlePool< T, MaxN >::full ( ) const
inline

◆ kill()

template<typename T , uint32_t MaxN>
void ParticlePool< T, MaxN >::kill ( uint32_t  i)
inline

O(1) swap-remove. Does NOT preserve order.

Here is the caller graph for this function:

◆ liveCount()

template<typename T , uint32_t MaxN>
uint32_t ParticlePool< T, MaxN >::liveCount ( ) const
inline
Here is the caller graph for this function:

◆ rawData()

template<typename T , uint32_t MaxN>
const T * ParticlePool< T, MaxN >::rawData ( ) const
inline

Pointer to the contiguous live data for GPU upload.

Here is the caller graph for this function:

◆ spawn()

template<typename T , uint32_t MaxN>
T * ParticlePool< T, MaxN >::spawn ( )
inline

Allocate a new slot (zero-initialised). Returns nullptr when full.

Here is the caller graph for this function:

◆ update()

template<typename T , uint32_t MaxN>
void ParticlePool< T, MaxN >::update ( auto  fn)
inline

Iterate all live particles.

fn(T& p) → bool: return false to kill. Iterates backwards so kill() inside fn doesn't skip elements.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ count

template<typename T , uint32_t MaxN>
uint32_t ParticlePool< T, MaxN >::count = 0

◆ data

template<typename T , uint32_t MaxN>
std::array<T, MaxN> ParticlePool< T, MaxN >::data {}

The documentation for this struct was generated from the following file: