ParticlePool Class
Namespace: Stride.ParticlesAssembly: 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
Name | Description | |
---|---|---|
Constructors | ||
ParticlePool(Int32, Int32, ParticlePool.ListPolicy) | ParticlePool constructor |
|
Fields | ||
DefaultMaxFielsPerPool | ||
Properties | ||
AvailableParticles | Gets how many more particles can be spawned |
|
LivingParticles | Get the number of living (active) particles |
|
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. |
|
ParticleCapacity | The maximum allowed number of particles in this ParticlePool. Use SetCapacity(Int32) if you need to change it. |
|
ParticleData | ParticleData is where the memory block (particle pool) actually resides. Its size equals ParticleSize * ParticleCapacity |
|
ParticleSize | ||
Methods | ||
AddParticle() | Add a new particle to the pool. Doesn't worry about initialization. |
|
Dispose() | ||
Dispose(Boolean) | ||
DisposeParticleData() | ||
FieldExists(ParticleFieldDescription, Boolean) | Polls if a filed with this description exists in the pool and optionally forces creation of a new field |
|
Finalize() | ||
FromIndex(Int32) | Get a particle from its index in the pool |
|
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. |
|
GetField<T>(ParticleFieldDescription<T>) | Unsafe method for getting a ParticleFieldAccessor. If the field doesn't exist an invalid accessor is returned to the user. |
|
RemoveField(ParticleFieldDescription) | Removes a particle field from this pool with the specified description, or gets an existing one |
|
Reset() | Clears all particle fields, but keeps the particle capacity the same. |
|
SetCapacity(Int32) | Set a different capacity (maximum Particle count for this pool) Whenever possible, existing particles will be copied and continue simulation |
|
TryGetField<T>(ParticleFieldDescription<T>, out ParticleFieldAccessor<T>) | Gets the particle field with the specified description if the field exists in this pool |
|
Explicit Interface Implementations | ||
IEnumerable.GetEnumerator() |
Constructors
ParticlePool(Int32, Int32, ParticlePool.ListPolicy)
ParticlePool constructor
public ParticlePool(int size, int capacity, ParticlePool.ListPolicy listPolicy = ParticlePool.ListPolicy.Stack)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | Initial size in bytes of a single particle |
System.Int32 | capacity | Initial capacity (maximum number of particles) of the pool |
ParticlePool.ListPolicy | listPolicy | List policy - stack (living particles are in the front) or ring |
Fields
DefaultMaxFielsPerPool
public const int DefaultMaxFielsPerPool = 16
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
AvailableParticles
Gets how many more particles can be spawned
public int AvailableParticles { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
LivingParticles
Get the number of living (active) particles
public int LivingParticles { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
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
Type | Description |
---|---|
System.Int32 |
ParticleCapacity
The maximum allowed number of particles in this ParticlePool. Use SetCapacity(Int32) if you need to change it.
public int ParticleCapacity { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ParticleData
ParticleData is where the memory block (particle pool) actually resides. Its size equals ParticleSize * ParticleCapacity
public IntPtr ParticleData { get; }
Property Value
Type | Description |
---|---|
System.IntPtr |
ParticleSize
public int ParticleSize { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
AddParticle()
Add a new particle to the pool. Doesn't worry about initialization.
public Particle AddParticle()
Returns
Type | Description |
---|---|
Particle |
Dispose()
public void Dispose()
Dispose(Boolean)
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
DisposeParticleData()
protected void DisposeParticleData()
FieldExists(ParticleFieldDescription, Boolean)
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
Type | Name | Description |
---|---|---|
ParticleFieldDescription | fieldDesc | Description of the field |
System.Boolean | forceCreate | Force the creation of non-existing fields if |
Returns
Type | Description |
---|---|
System.Boolean |
Finalize()
protected void Finalize()
FromIndex(Int32)
Get a particle from its index in the pool
public Particle FromIndex(int idx)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | idx |
Returns
Type | Description |
---|---|
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
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
ParticleFieldDescription<T> | fieldDesc |
Returns
Type | Description |
---|---|
ParticleFieldAccessor<T> |
Type Parameters
Name | Description |
---|---|
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
Type | Name | Description |
---|---|---|
ParticleFieldDescription | fieldDesc | Description of the field |
Returns
Type | Description |
---|---|
System.Boolean |
|
Reset()
Clears all particle fields, but keeps the particle capacity the same.
public void Reset()
SetCapacity(Int32)
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
Type | Name | Description |
---|---|---|
System.Int32 | newCapacity | 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
Type | Name | Description |
---|---|---|
ParticleFieldDescription<T> | fieldDesc | Field's decription |
ParticleFieldAccessor<T> | accessor | Accessor for the field |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T | Type data for the field |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |