# Snapshot Compression
Source: https://gafferongames.com/post/snapshot_compression/
Author: Glenn Fiedler | Date: 2015-01-04

## Goal
Raise snapshot rate (toward 60 Hz) while hitting ~256 kbps. Start from ~17 Mbps uncompressed for 901 cubes.

## Orientation: smallest three
Unit quaternion: drop largest component (2-bit index), send other three. Negate quat so dropped w≥0 (no sign bit). Bound remaining components to ±1/√2. ~9 bits each → 2+9+9+9 = 29 bits (from 128).

## Linear velocity
Bound (e.g. ±32 m/s), quantize (~11 bits/component). "At rest" bit omits velocity. At 60 Hz, linear velocity often unnecessary → omit entirely (best optimization: don't send).

## Position
Bound world (e.g. xy ±256 m, z [0,32]), quantize (~2 mm → 18+18+14 = 50 bits).

## Delta compression
Encode snapshot N relative to baseline B the receiver has acked. Steady state: baseline ≈ RTT in the past. Until first ack: flag "relative to known initial state" or send non-delta bootstrap block.

Big win: unchanged object → 1 bit. Alternatives: send only changed cubes with index; crossover vs bit-per-cube. Relative indices (encode offsets) lower average bits. Relative position/orientation multi-level small/large ranges. Position-changed / orientation-changed bits for partial updates.

Hand bit-packing can still be beaten ~25% by context-aware arithmetic coding (Fabian Giesen). Predicting orientation from angular velocity can beat delta-on-smallest-three.