Class Batcher<O, E, B>Abstract

Manages a collection of objects and distributes them into a set of batches, based on batcher-specific criteria (like size, number of textures, ...).

A new batcher derived from Batcher must:

  1. Define an add method. There is no default/overridable add method because the needs of a batcher can change it. This method should ultimately call Batcher.addEntryQueued.
  2. Implement Batcher.changeEntry. It is the job of the batcher to find out what actually changed after a consumer calls Batcher.change. Any actual change must then be propagated to the batch and optionally stored in the entry.
  3. Implement Batcher.addToBatch. Adds an entry to a batch, with any additional data necessary.
  4. Implement Batcher.canBatchInclude. Returns if a batch can fit the given entry.

Implementing these allows for batching on many different criteria.

Depending on what is being batched and what the criteria for when a batch is 'full' are, derived versions of Batch and BatchEntry may be necessary.

Type Parameters

Hierarchy (View Summary)

Implements

Constructors

Properties

_batches: B[] = []
batches: readonly B[] = ...

Batches. All batches in this collection are at least partially occupied.

batchPool: Pool<B>

Object pool for batches

changeTracker: ChangeTracker

Changes to objects will be propagated to the change tracker

entryPool: Pool<E>

Object pool for batch entries

maxSize: number

Max size of a batch. Unit depends on batcher.

objectBatches: Map<O, B> = ...

For faster lookup of object -> batch.

queuedAdds: E[] = []

Newly added entries are queued until all changes are applied to a batch.

Methods

  • Check if a batch can contain an entry.

    Parameters

    • batch: B

      Batch to check

    • entry: E

      Entry

    Returns boolean

  • Apply changes of an object to its entry (and possible batch).

    Parameters

    • batch: undefined | B

      Batch entry belongs to. Can be undefined in case entry does not have a batch (e.g., when only queued for an add)

    • entry: E

      Entry to change

    • object: O

      Associated object

    Returns void

  • Finalize batches for this tick by applying all queued changes, adding all queued new entries, and cleaning up unused batches.

    Returns readonly B[]

    Finalized batches