About Ghost Dynamic Buffers

How are dynamic buffers replicated? Particularly with a static ghost. Does the entire buffer get synchronized if only one element’s value changes? If not, does it have to send a bit for each unchanged value?

I’m wondering how performant it would be to use a very large dynamic buffer instead of many individual ghosts, because indexing the data and associating it with an entity is simpler that way.

Static optimisation does not affect how the dynamic buffer is serialised. In general, static ptimisation trade-of CPU for bandwidth by using more checks to avoid sending and processing whole ghosts chunks (or single ghosts data in that case too) if there were not changes since the latest ack-ed packet for that chunk (it is slightly different but that should give an idea).

Dynamic buffer are serialized in delta in respect the last acked packet from the client. They always use at minimum two bits. in particular:

  • If the buffer didn’t change size, all elements are encoded in delta in respect to the baseline. If there is no element changes, we just use pretty much 2 bits of information.
  • If the buffer element changes but size stay the same, we serialise the element in delta in repspect the baseline, thus we send a changemask that, in the most common case, has num element * num_fields bits. + 2 bits for header
  • if the buffer change size, because we make 0 assumptions about data, we resend the full buffer (no delta compression). This is a limit of the current implementation, and being the code hardcode in the package it is hard to change without modifying send and receive side.

Large buffers are not great to use because the serialization is not cheap. Also there is even a bigger problem; either the buffer is sent in full (so all element) or nothing. That imply, if the buffer data is pretty large, the GhostSendSystem need to send the data using fragmented pipeline (that is still unreliable), that imply sending multiple packets (split in chunks of MTU bytes, ~1400). Depending on the network condition, if packet are lost, you will not able to decode the received data. You need to wait until the ghost is sent again, and if everything is received., the data is decoded and buffer replicated as expected.

With individual ghosts, the send system has more opportunity to prioritise and sending partials set of ghosts, depending on their archetype priority and custom priority scaling, thus optimise the bandiwith used by server to actually deliver to the client what they need the most. In that case, unless a single ghost cannot fit into a single packet (a very large ghost), one 1 single packet per network interval is sent. If that get lost will not affect successive packet decoding.