@zimmed/prefab / Exports / ObjectPool
| Name | Type |
|---|---|
O |
extends PoolObject |
- [iterator]
- add
- alloc
- clear
- create
- dealloc
- deallocateObject
- forceSpawn
- free
- insert
- items
- realloc
- reallocUnsafe
- spawn
- toJSON
• new ObjectPool<O>(PoolObjectClass, allocSize?)
| Name | Type |
|---|---|
O |
extends PoolObject<O> |
| Name | Type | Default value |
|---|---|---|
PoolObjectClass |
() => O |
undefined |
allocSize |
number |
0 |
• Protected Readonly _Class: () => O
• new ObjectPool()
• Private _active: number = 0
• Protected Readonly _list: LinkedList<O, PoolState<O>>
• Private _max: number = 0
▪ Static Object: typeof PoolObject = PoolObject
Objects within the pool must inherit from ObjectPool.Object
• get count(): number
The current count of active objects in the pool
number
• get size(): number
The current (max) size of the object pool
number
▸ [iterator](): Generator<O, void, unknown>
Generator<O, void, unknown>
▸ Protected add(obj): void
Append new object to end of the pool queue
| Name | Type |
|---|---|
obj |
O |
void
▸ alloc(size?): ObjectPool<O>
Increases pool size and allocates new objects to fill it
| Name | Type | Default value |
|---|---|---|
size |
number |
1 |
ObjectPool<O>
▸ clear(): ObjectPool<O>
Completely clear the pool, freeing all objects from memory
ObjectPool<O>
▸ Protected create(): O
Create and return new PoolObject
O
▸ dealloc(size?): ObjectPool<O>
Downsize pool by specified amount, deallocating overflowing objects
| Name | Type | Default value |
|---|---|---|
size |
number |
1 |
ObjectPool<O>
▸ Protected deallocateObject(obj?, del?): boolean
Cleans and removes object from pool entirely
| Name | Type | Default value |
|---|---|---|
obj? |
O |
undefined |
del |
boolean |
true |
boolean
▸ forceSpawn(...args): O
Spawns and initializes object from pool, or create new object and increase pool size if full
| Name | Type |
|---|---|
...args |
InitArgs<O> |
O
▸ free(item): ObjectPool<O>
Returns object back to pool to be re-used later
| Name | Type |
|---|---|
item |
O |
ObjectPool<O>
▸ Protected insert(obj): void
Insert new object into front of the pool queue
| Name | Type |
|---|---|
obj |
O |
void
▸ items(): Generator<O, void, unknown>
Generator<O, void, unknown>
▸ realloc(size?): ObjectPool<O>
Sets max pool size, but ignores call if provided size is smaller than current max
| Name | Type |
|---|---|
size |
number |
ObjectPool<O>
▸ reallocUnsafe(size?): ObjectPool<O>
Overrides max pool size, deallocating any overflowing objects
| Name | Type |
|---|---|
size |
number |
ObjectPool<O>
▸ spawn(...args): undefined | O
Spawns and initializes object from pool (if any are free)
| Name | Type |
|---|---|
...args |
InitArgs<O> |
undefined | O
▸ toJSON(): O[]
O[]