Should not have side-effects
Should not have side-effects TODO make this a pure function rather than a method?
Applies diff to the allow-listed components of registered entities
mentioned therein. Additionally, it will create entities mentioned in
message
and add their components if necessary. Conversely, it will remove
entities that are ommitted by message
.
For convenience
For convenience
Get the operations necessary to bring the network up-to-date with the local world instance.
Target.
Add component of the given type to the allow list, meaning the data of any instances of registered entities will be sent and recieved over the socket. TODO should allowed components only be passed in constructor?
For convenience
For convenience
Generated using TypeDoc
A message producer and consumer for diff/delta-based networking of Entities. How it works: Comparing the local game state with a cached representation of the game state, it produces a diff. The diff contains two kinds of operations:
upsert
Either creates an entity or adds a component to an existing entity, or both. It can also update a component's data. In the following example
Would be the resulting diff if Mega Man's velocity is 6 while the cache says it's some other integer. When another client is applying this diff to its game state, it would set Mega Man's velocity to 6, adding the velocity component if necessary, and also creating the Mega Man entity if necessary.
When comparing components, it first passes each component through an associated identity function, if available, otherwise it grabs
component.value
. Either way, it assumes the resulting values should be compared by reference (===
in JavaScript.) This is handy for when a by reference comparison would be misleading. For example, if the velocity component were an array:Then two velocity components would never appear equal even if they contain the same value. An identity function that concatinates the numbers in to a JS string would solve this, since JS strings are equal by reference if and only if they contain the same value. remove
Either removes a component from an entity or removes an entire entity. Example:
Would remove the velocity component from Mega Man, and remove the Dr. Wily component altogether.
In addition to producing and consuming diffs, it provides a static function that will update the cache given a diff. The cache tells it what the world looked like last time so it knows what's changed when producing a diff. The cache is its memory.
It has a reference to the entire game state (the world, in ECS parlance) but it doesn't concern itself with every component of every entity. That could be too expensive in terms of CPU and network usage. Instead the system that's using it must tell it what entities to care about. It also must be told what types of components to care about. We supply it with a string identifier for each entity and each component type which it uses when producing and consuming diffs.