rfw2d
    Preparing search index...

    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 should:

    1. Implement abstract methods.
    2. Provide a storage (some type of buffer that can then be used in rendering).
    3. Possibly override Batcher#applyBatchChanges to reset any marked changes in storage.
    4. Override Batcher#applyEntryChange to apply change to storage.

    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)

    Index

    Constructors

    Properties

    batches: B[] = []

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

    changeTracker: ChangeTracker

    Changes to objects will be propagated to the change tracker

    queuedEntries: E[] = []

    New entries are queued until all changes are applied to a batch.

    Accessors

    Methods

    • Add an object to the batcher. Additions are queued, apply with Batcher#finalize.

      Parameters

      • object: O

        Object to add

      Returns E

      Created entry

      If called more than once with the same object, more than one entry will be created.

    • Apply only entries with queued changes. Entries in between will may be moved if gaps occur or space is needed.

      Parameters

      • batch: B

        Batch

      Returns void

    • Called when an entry change is applied.

      Parameters

      • entry: E

        Changed entry

      • batch: B

        Batch containing entry

      • offset: number

        Element offset in batch

      Returns void

    • Check if entry can be added to batch.

      Parameters

      • entry: E

        Entry

      • batch: B

        Batch

      • OptionaladditionalSize: number

        Optional, if set this is the additional size required

      Returns boolean

      true if entry fits into batch

    • Mark an entry as changed. Changes are queued, apply with Batcher#finalize.

      Parameters

      • entry: E

        Changed entry

      Returns boolean

      true if the entry was present

      Change handling code for the given entry will only be called once, even if this method is called multiple times with the same entry.

    • Called when an entry is marked as changed. Should set sizes and any other properties.

      Parameters

      • entry: E

        Entry

      • batch: undefined | B

        Batch containing entry

      Returns void

    • Move data within a batch. Used if e.g. entries change size and multiple entries must be moved to fill gaps or crate space.

      Parameters

      • batch: B

        Affected batch

      • target: number

        Target element offset

      • start: number

        Start element offset

      • end: number

        End element offset

      Returns void

      Generally should call copyWithin on batch storage or its buffer.

    • Create an entry for object.

      Parameters

      • object: O

        Object

      Returns E

      Created entry

      If using an entry pool, take from pool here.

    • Delete an entry. Deletes are queued unless the entry is itself queued for add, apply with Batcher#finalize.

      Parameters

      • entry: E

        Entry

      Returns boolean

      true if an entry was deleted/queued

      Deletion be done once, even if this method is called multiple times with the same entry.

    • Discard an entry.

      Parameters

      • entry: E

        Entry

      Returns void

      If using an entry pool, return to pool here.

    • Find an entry for object by doing a linear search through all batches and entries.

      Parameters

      • object: O

        Object to find entry for

      Returns undefined | E

      First entry, if present

      If Batcher#add was called multiple times with the same object, multiple entries can exist for the same object. In this case this method returns only the first entry it finds.

      Generally, the returned entry from Batcher#add should be stored to then reuse it for Batcher#change and Batcher#change calls.

    • Called when an entry was removed from a batch.

      Parameters

      • entry: E

        Deleted entry

      • batch: B

        Batch containing entry

      Returns void

    • Decide if a batch should be completely rebuilt. Generally this should be true if most/all of the batch's entries must be processed anyways.

      Parameters

      • batch: B

        Batch

      Returns boolean

      true if batch should be rebuilt.