Table of Contents

Class LosslessFloatDelta

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Exact delta encoding for floats: each changed component travels as the difference between the two values' IEEE-754 bit patterns, zigzag varint packed. The reader adds it back to the baseline's bits, so the decoded value is the written one BIT FOR BIT.

public static class LosslessFloatDelta
Inheritance
LosslessFloatDelta
Inherited Members

Remarks

Why not FishNet's vector deltas. They round each difference to 1 mm (a quaternion's to 1e-4) and do not send a smaller one at all, so a delta reconcile restored the owner up to a couple of millimetres from the server's state. The motor then replayed from a state the server never had, and any threshold a millimetre can cross (the 5 mm ground probe on unstable ground, a climb's arrival and top checks) could decide differently on the replay than on the server, which shows as a correction.

Cost. A difference of N units in the last place packs to about log128(2N) bytes: a few metres from the baseline at a few hundred metres out is 3 bytes an axis, about one more than the rounded form. A component that crosses zero costs up to 5 bytes for that one write, because sign and magnitude are separate in the bit pattern. Unchanged components cost nothing beyond a 3- or 4-bit mask.

Methods

Apply(float, int)

previous moved by a bit-pattern difference; the exact inverse of Difference(float, float).

public static float Apply(float previous, int difference)

Parameters

previous float
difference int

Returns

float

Difference(float, float)

The bit-pattern difference from previous to next; 0 when bitwise equal.

public static int Difference(float previous, float next)

Parameters

previous float
next float

Returns

int

ReadQuaternion(Reader)

public static Quaternion ReadQuaternion(Reader reader)

Parameters

reader Reader

Returns

Quaternion

ReadQuaternion(Reader, Quaternion)

public static Quaternion ReadQuaternion(Reader reader, Quaternion previous)

Parameters

reader Reader
previous Quaternion

Returns

Quaternion

ReadVector3(Reader, Vector3)

public static Vector3 ReadVector3(Reader reader, Vector3 previous)

Parameters

reader Reader
previous Vector3

Returns

Vector3

WriteQuaternion(Writer, Quaternion)

A quaternion written whole and exact: four floats.

public static void WriteQuaternion(Writer writer, Quaternion value)

Parameters

writer Writer
value Quaternion

WriteQuaternion(Writer, Quaternion, Quaternion, bool)

The quaternion form of WriteVector3(Writer, Vector3, Vector3, bool): four components.

public static bool WriteQuaternion(Writer writer, Quaternion previous, Quaternion next, bool always)

Parameters

writer Writer
previous Quaternion
next Quaternion
always bool

Returns

bool

WriteVector3(Writer, Vector3, Vector3, bool)

Writes the changed components of next against previous: a mask byte, then each changed component's difference. Writes nothing and returns false when nothing changed, unless always, which writes an empty mask.

public static bool WriteVector3(Writer writer, Vector3 previous, Vector3 next, bool always)

Parameters

writer Writer
previous Vector3
next Vector3
always bool

Returns

bool