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
const context = new Context();const options = new Options();const tick = 0;const updates = await updater(context, options, tick);console.log(updates);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
optionsparameter is an instance of theOptionsclass. If not, it creates a newOptionsinstance. - The function extracts various options and properties from the
optionsobject. - The function extracts the
created,removed,symbols, andupdatedproperties from thecontext.pendingobject. - The function extracts the
storeproperty from thecontextobject. - The function checks if the
maskobject or itsentitiesproperty is not present. If so, it processes the creation of entities. - The function checks if the
maskobject or itsactorsproperty is not present. If so, it processes the spawning of actors. - The function checks if the
maskobject or itsentitiesproperty is not present. If so, it processes the removal of entities. - The function checks if the
maskobject or itsactorsproperty is not present. If so, it processes the removal of actors. - The function checks if the
maskobject or itscomponentsproperty is not present. If so, it processes the removal of components. - The function checks if the
maskobject or itscomponentsproperty is not present. If so, it processes the creation of components. - The function checks if the
maskobject or itscomponentsproperty is not present. If so, it processes the update of components. - The function checks if the
maskobject or itsinputsproperty is not present. If so, it processes the creation of inputs. - The function checks if the
maskobject or itssymbolsproperty 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
batcharray to store batches of updates. - The function initializes an empty
batchBlockarray to store the current batch of updates. - The function defines a helper function
mergeBatchto merge the current batch block into the batch array. - The function defines a helper function
queueMessageto queue a message for later processing. - The function defines a helper function
ensureSymbolto ensure that a symbol is indexed if thecompressStringsAsIntsoption is enabled. - The function defines a helper function
upsertComponentsto 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.