Vixen
02b45cc4
csharp
public static class DeltaCodec

Encodes one version of a value as its difference from the previous one.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A pure transform between three bit streams, with no knowledge of any component type. The previous encoding and the current encoding go in and a delta comes out; the delta and the previous encoding go in and the current one comes back. Nothing here touches a world, an entity or a field — which is why there is one of these rather than one per component, and why "delta then apply equals full state" is a property that can be tested over random bits instead of over a hand-written example.

The layout is: one bit per lane saying whether it changed, then, for each lane that did, either the new value whole or a difference. A difference gets a two-bit selector choosing 4, 8 or 16 bits of zig-zagged offset, or the fourth code meaning "the whole value". So a lane that moved a little costs six bits where it cost sixteen, a lane that jumped costs two more than it did, and a lane that did not move costs one.

Narrow lanes are never offset. Below MinimumOffsetBits the selector costs more than the encoding saves, so those are written whole — a flag that changed is one bit of mask and one bit of value, and a byte is nine.

Fields and properties (2)

  • public const int SelectorBits

    How many bits choose between the offset widths.

  • public const int MinimumOffsetBits

    The narrowest lane worth encoding as an offset rather than whole.

Methods (5)

  • public static int TotalBits(ReadOnlySpan<WireLane> lanes)

    How many bits an encoding described by these lanes occupies.

  • public static int OffsetWidth(uint selector, int bits)

    How many bits of offset a selector code stands for, on a lane of a given width.

  • public static int MaxBits(ReadOnlySpan<WireLane> lanes)

    The most a delta over these lanes could ever cost.

  • public static bool TryEncode(ReadOnlySpan<WireLane> lanes, ref BitReader previous, ref BitReader current, ref BitWriter delta, Span<int> costs = default(Span<int>))

    Writes the difference between two encodings of the same value.

  • public static bool TryDecode(ReadOnlySpan<WireLane> lanes, ref BitReader previous, ref BitReader delta, ref BitWriter current)

    Rebuilds an encoding from the one before it and a difference.

Used by (9)

  • DeltaCodecTargetVixen.Net.Fuzz
  • DeltaTestsVixen.Net.Tests
  • NetworkAudioTestsVixen.Net.Audio.Tests
  • NetworkBonesTestsVixen.Net.Animation.Tests
  • ReplicationClientVixen.Net
  • ReplicationGeneratorTestsVixen.Net.Generators.Tests
  • ReplicationServerVixen.Net
  • SnapshotInspectorVixen.Net
  • SyncStateTestsVixen.Net.Engine.Tests