Table of Contents

Class ParticlePool

Namespace
Stride.Particles
Assembly
Stride.Particles.dll

The ParticlePool is a class which manages an unmanaged memory block used for the particles. The maximum required size calculated on the number of particles and their fields' sizes is calculated every time the sizes or the count change

public class ParticlePool : IDisposable, IEnumerable
Inheritance
ParticlePool
Implements
Extension Methods

Constructors

ParticlePool(int, int, ListPolicy)

ParticlePool constructor

public ParticlePool(int size, int capacity, ParticlePool.ListPolicy listPolicy = ListPolicy.Stack)

Parameters

size int

Initial size in bytes of a single particle

capacity int

Initial capacity (maximum number of particles) of the pool

listPolicy ParticlePool.ListPolicy

List policy - stack (living particles are in the front) or ring

Fields

DefaultMaxFielsPerPool

public const int DefaultMaxFielsPerPool = 16

Field Value

int

Properties

AvailableParticles

Gets how many more particles can be spawned

public int AvailableParticles { get; }

Property Value

int

LivingParticles

Get the number of living (active) particles

public int LivingParticles { get; }

Property Value

int

NextFreeIndex

NextFreeIndex points to the next index ready for allocation, between 0 and ParticleCapacity - 1. In case of stack list the NextFreeIndex equals the number of living particles in the pool.

public int NextFreeIndex { get; }

Property Value

int

ParticleCapacity

The maximum allowed number of particles in this ParticlePool. Use SetCapacity(int) if you need to change it.

public int ParticleCapacity { get; }

Property Value

int

ParticleData

ParticleData is where the memory block (particle pool) actually resides. Its size equals ParticleSize * ParticleCapacity

public nint ParticleData { get; }

Property Value

nint

ParticleSize

Returns the size of a single Particle. If PARTICLES_SOA is defined, the size of the Particle is the sum of all field strides. Otherwise, the size of the Particle is the pool's stride.

public int ParticleSize { get; }

Property Value

int

Methods

AddParticle()

Add a new particle to the pool. Doesn't worry about initialization.

public Particle AddParticle()

Returns

Particle

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

DisposeParticleData()

protected void DisposeParticleData()

FieldExists(ParticleFieldDescription, bool)

Polls if a filed with this description exists in the pool and optionally forces creation of a new field

public bool FieldExists(ParticleFieldDescription fieldDesc, bool forceCreate = false)

Parameters

fieldDesc ParticleFieldDescription

Description of the field

forceCreate bool

Force the creation of non-existing fields if true

Returns

bool

~ParticlePool()

protected ~ParticlePool()

FromIndex(int)

Get a particle from its index in the pool

public Particle FromIndex(int idx)

Parameters

idx int

Returns

Particle

GetEnumerator()

Returns an ParticlePool.Enumerator to the particles in this ParticlePool In case of Ring dead particles are returned too, so the calling entity should handle such cases.

public ParticlePool.Enumerator GetEnumerator()

Returns

ParticlePool.Enumerator

GetField<T>(ParticleFieldDescription<T>)

Unsafe method for getting a ParticleFieldAccessor. If the field doesn't exist an invalid accessor is returned to the user.

public ParticleFieldAccessor<T> GetField<T>(ParticleFieldDescription<T> fieldDesc) where T : struct

Parameters

fieldDesc ParticleFieldDescription<T>

Returns

ParticleFieldAccessor<T>

Type Parameters

T

RemoveField(ParticleFieldDescription)

Removes a particle field from this pool with the specified description, or gets an existing one

public bool RemoveField(ParticleFieldDescription fieldDesc)

Parameters

fieldDesc ParticleFieldDescription

Description of the field

Returns

bool

true if the field was successfully removed, false otherwise

Reset()

Clears all particle fields, but keeps the particle capacity the same.

public void Reset()

SetCapacity(int)

Set a different capacity (maximum Particle count for this pool) Whenever possible, existing particles will be copied and continue simulation

public void SetCapacity(int newCapacity)

Parameters

newCapacity int

New maximum capacity

TryGetField<T>(ParticleFieldDescription<T>, out ParticleFieldAccessor<T>)

Gets the particle field with the specified description if the field exists in this pool

public bool TryGetField<T>(ParticleFieldDescription<T> fieldDesc, out ParticleFieldAccessor<T> accessor) where T : struct

Parameters

fieldDesc ParticleFieldDescription<T>

Field's decription

accessor ParticleFieldAccessor<T>

Accessor for the field

Returns

bool

Type Parameters

T

Type data for the field