Class LosslessFloatDelta
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
Returns
Difference(float, float)
The bit-pattern difference from previous to next; 0 when bitwise equal.
public static int Difference(float previous, float next)
Parameters
Returns
ReadQuaternion(Reader)
Reads what WriteQuaternion(Writer, Quaternion) wrote.
public static Quaternion ReadQuaternion(Reader reader)
Parameters
readerReader
Returns
- Quaternion
ReadQuaternion(Reader, Quaternion)
Reads what WriteQuaternion(Writer, Quaternion, Quaternion, bool) wrote.
public static Quaternion ReadQuaternion(Reader reader, Quaternion previous)
Parameters
readerReaderpreviousQuaternion
Returns
- Quaternion
ReadVector3(Reader, Vector3)
Reads what WriteVector3(Writer, Vector3, Vector3, bool) wrote.
public static Vector3 ReadVector3(Reader reader, Vector3 previous)
Parameters
readerReaderpreviousVector3
Returns
- Vector3
WriteQuaternion(Writer, Quaternion)
A quaternion written whole and exact: four floats.
public static void WriteQuaternion(Writer writer, Quaternion value)
Parameters
writerWritervalueQuaternion
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
writerWriterpreviousQuaternionnextQuaternionalwaysbool
Returns
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
writerWriterpreviousVector3nextVector3alwaysbool