Class PoolBucket
Group of reusable entity instances of the same spawn type. Manages active and available instances for pooling.
Inherited Members
Namespace: Serenity.GameSpawner.Domain.Entities
Assembly: Serenity.GameSpawner.Domain.dll
Syntax
public class PoolBucket
Constructors
PoolBucket(SpawnType)
Creates a new PoolBucket for the specified spawn type.
Declaration
public PoolBucket(SpawnType type)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnType | type | The spawn type this bucket manages. |
Properties
ActiveCount
Gets the number of currently active instances.
Declaration
public int ActiveCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
ActiveHandles
Gets a read-only view of the currently active handles.
Declaration
public IReadOnlyList<SpawnHandle> ActiveHandles { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<SpawnHandle> |
AvailableCount
Gets the number of available (pooled) instances.
Declaration
public int AvailableCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
TotalCount
Gets the total number of instances (active + available).
Declaration
public int TotalCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Type
Gets the spawn type this bucket manages.
Declaration
public SpawnType Type { get; }
Property Value
| Type | Description |
|---|---|
| SpawnType |
Methods
Acquire()
Acquires an instance from the pool or creates a new one.
Declaration
public SpawnHandle Acquire()
Returns
| Type | Description |
|---|---|
| SpawnHandle | A SpawnHandle for the acquired instance. |
Clear()
Drops every active and available handle, emptying the bucket.
Declaration
public void Clear()
IsAvailable(SpawnHandle)
Checks whether a handle is parked in the available pool awaiting reuse.
Declaration
public bool IsAvailable(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle | The handle to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the handle is currently available for reuse; otherwise false. |
RegisterActive(SpawnHandle)
Adopts an externally created handle as an active instance of this bucket.
Declaration
public void RegisterActive(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle | The handle to register as active. |
Release(SpawnHandle)
Releases an instance back into the pool.
Declaration
public bool Release(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle | The handle to release. |
Returns
| Type | Description |
|---|---|
| bool | True if the handle was found and released; otherwise false. |
ReleaseAllActive()
Moves every active handle into the available pool for reuse.
Declaration
public void ReleaseAllActive()
RemoveActive(SpawnHandle)
Removes an active handle without returning it to the available pool.
Declaration
public bool RemoveActive(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle | The handle to remove. |
Returns
| Type | Description |
|---|---|
| bool | True if the handle was found and removed; otherwise false. |
ToSnapshot()
Creates a snapshot of the current pool state.
Declaration
public PoolStateSnapshot ToSnapshot()
Returns
| Type | Description |
|---|---|
| PoolStateSnapshot | A read-only snapshot of the pool state. |
TryAcquireAvailable(out SpawnHandle)
Attempts to acquire an instance from the available pool without creating a new one.
Declaration
public bool TryAcquireAvailable(out SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle | The acquired handle, moved from available into active. |
Returns
| Type | Description |
|---|---|
| bool | True if an available handle was found and moved to active; otherwise false. |