Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FastPool<TObject>

An object pool allows to reuse the same instance of an object multiple times without the relatively costly operation of instantiating it. It's especially useful when you need to create and destroy objects quickly (eg. bullets/particles) or create a lot of them at once (eg. loading a level).

Type parameters

  • TObject: object

    Type of the objects stored in the pool

Hierarchy

  • FastPool

Implements

Index

Constructors

constructor

  • Parameters

    • onHydrate: PoolHydrateCallback<TObject>

      A function that's called when hydrating the pool, which must return new instances of objects to populate it.

    • Optional onRelease: PoolReleaseCallback<TObject>

      An optional function called when an object is released.

    • Optional config: PoolConfig

      Configuration

    Returns FastPool

Accessors

availableObjects

  • get availableObjects(): number
  • The number of objects left in the pool

    Returns number

totalObjects

  • get totalObjects(): number
  • The number of used objects in the pool

    Returns number

usedObjects

  • get usedObjects(): number
  • The total number of objects created by this pool

    Returns number

Methods

getOne

  • getOne(): TObject
  • Retrieves a single object. If the pool has no available objects it first hydrates the pool.

    Returns TObject

    The object retrieved from the pool

hydrate

  • hydrate(objectsToCreate: number): void
  • Enlarges the list of available objects by the specified number.

    Parameters

    • objectsToCreate: number

      Number of objects to create

    Returns void

release

  • release(object: TObject): void
  • Releases an object back into the pool

    Parameters

    • object: TObject

      The object to be released. It should be an object previously retrieved from the pool.)

    Returns void

Generated using TypeDoc