Table of Contents

Class MoveAxisCompression

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

Packs a movement input axis into a single signed byte, and exposes the quantisation so a producer can commit to the value it is about to send.

public static class MoveAxisCompression
Inheritance
MoveAxisCompression
Inherited Members

Remarks

Movement axes are inputs in [-1, 1] — usually exactly -1, 0 or +1 from a keyboard, and a smooth ramp from a stick. They were carried as unpacked floats, four bytes each, paid both in the absolute entry of every replicate packet and again whenever they changed. A signed byte resolves 1/127, which is finer than any input device or player can express and well inside what Vector3.ClampMagnitude does to the pair immediately afterwards.

The same rule as AimDirectionCompression applies and for the same reason: quantise at the producer. The owner predicts from the struct it fills in, so storing a raw axis there would have the owner simulate a movement magnitude the wire cannot carry while the server and observers simulate the decoded one. The divergence is small per tick and accumulates over a run of ticks into a position difference that reconcile then has to correct.

Methods

Decode(sbyte)

Unpacks an axis previously produced by Encode(float).

public static float Decode(sbyte packed)

Parameters

packed sbyte

The packed representation.

Returns

float

An axis value in [-1, 1] for anything Encode(float) can produce, which clamps to ±127. A raw −128 off the wire decodes to −1.008; the pair is ClampMagnitude'd by KCCController.SetInputs before it reaches the motor, so the overshoot cannot become movement, but do not treat this return as pre-clamped.

Encode(float)

Packs an axis into a signed byte, clamping to [-1, 1].

public static sbyte Encode(float value)

Parameters

value float

Raw axis value.

Returns

sbyte

The packed representation.

Quantize(float)

Rounds an axis onto the wire's representable set.

public static float Quantize(float value)

Parameters

value float

Raw axis value.

Returns

float

The value the wire will carry.

Remarks

The call a producer makes before storing movement input. See the note on the class for why this has to happen on the way in rather than on the way out.