Updater
The updater
function updates the context based on the provided options. It processes various updates such as creating entities, spawning actors, removing entities and components, and updating components and inputs. It supports batching of updates and can handle different options such as compressing strings as integers, enabling rollback, and diffing changes.
Example Usage
The code above creates a new context and options, and then calls the updater
function to update the context based on the options. The current tick is set to 0. The function returns a promise that resolves to an array of arrays, where each sub-array represents a batch of updates. The updates are logged to the console.
Inputs
context
(Context): The current context.options
(Options | any): The options for updating the context.tick
(number, optional): The current tick. Defaults to the current time.
Flow
- The function checks if the
options
parameter is an instance of theOptions
class. If not, it creates a newOptions
instance. - The function extracts various options and properties from the
options
object. - The function extracts the
created
,removed
,symbols
, andupdated
properties from thecontext.pending
object. - The function extracts the
store
property from thecontext
object. - The function checks if the
mask
object or itsentities
property is not present. If so, it processes the creation of entities. - The function checks if the
mask
object or itsactors
property is not present. If so, it processes the spawning of actors. - The function checks if the
mask
object or itsentities
property is not present. If so, it processes the removal of entities. - The function checks if the
mask
object or itsactors
property is not present. If so, it processes the removal of actors. - The function checks if the
mask
object or itscomponents
property is not present. If so, it processes the removal of components. - The function checks if the
mask
object or itscomponents
property is not present. If so, it processes the creation of components. - The function checks if the
mask
object or itscomponents
property is not present. If so, it processes the update of components. - The function checks if the
mask
object or itsinputs
property is not present. If so, it processes the creation of inputs. - The function checks if the
mask
object or itssymbols
property is not present. If so, it processes the addition of symbols. - The function checks if batching is enabled and there are batches to process. If so, it sends the batches of updates to the responder.
- The function returns the batch array.
Closures
- The function initializes an empty
batch
array to store batches of updates. - The function initializes an empty
batchBlock
array to store the current batch of updates. - The function defines a helper function
mergeBatch
to merge the current batch block into the batch array. - The function defines a helper function
queueMessage
to queue a message for later processing. - The function defines a helper function
ensureSymbol
to ensure that a symbol is indexed if thecompressStringsAsInts
option is enabled. - The function defines a helper function
upsertComponents
to handle the creation and update of components.
Outputs
- A promise that resolves to an array of arrays, where each sub-array represents a batch of updates.