nx_netquant.nx
buildroot/runtime/nx_netquant.nx
about
nx_netquant.nx -- sovereign BIT-LEVEL quantized + delta player-state codec for adverse
networks (the "girl on a bad mobile network plays seamlessly with a boy in Texas" problem).
Composes nx_bitio (MSB-first bit writer/reader). 100% nx, no syscalls -> wasm-friendly AND
daemon-reusable. NO logic ever leaves for JS -- the host only moves the resulting bytes.
Two frame kinds (the keyframe+delta model, like video I/P frames or Quake3/Source snapshots):
FULL (keyframe): every field at minimal fixed width -> 88 bits = 11 bytes (raw was 28).
Lossless for in-range values (positions are integer voxels; yaw stored
mod 360 in 9 bits; pitch +bias in 8). Sent on join / periodic resync.
DELTA (vs a baseline): a 10-bit change-mask + zig-zag VARINT for each changed field.
Stationary peer -> ~2 bytes; a small walk -> a few bytes. This is the
low-bandwidth win that keeps the bad-network player smooth.
Fields f[0..9] = x,y,z,yaw,pitch, species,caught,action,anim, flags
x,z: signed voxel (bias +131072, 18 bits each => +/-131071 lossless)
y: 0..4095 (12 bits) yaw: 0..359 mod 360 (9 bits) pitch: -85..85 (+128, 8 bits)
species 3b, caught 7b, action 3b, anim 6b, flags 4b
license_tier: ORIGINAL
dependencies 1 imports · 3 importers
imports: nx_bitio.nx
imported by: nx_adverse_net_gate.nxnx_netquant_gate.nxnx_pets3d_wasm.nx
structs
| none |
consts
| 21 | const NQ_NF: i64 = 10 |
| 22 | const NQ_BIAS: i64 = 131072 // position bias (2^17) -> 18-bit unsigned field |
| 23 | const NQ_FULL_BITS: i64 = 88 // 18+12+18+9+8+3+7+3+6+4 |
functions
| 26 | func nq_zz(v: i64) -> i64 { if v < 0 { return ((0 - v) << 1) - 1 } return v << 1 } called by 1: nq_vput |
| 27 | func nq_unzz(z: i64) -> i64 { if (z & 1) == 1 { return 0 - ((z + 1) >> 1) } return z >> 1 } called by 1: nq_vval |
| 29 | func nq_bitlen(z: i64) -> i64 { var n: i64 = 0; var x: i64 = z; while x > 0 { n = n + 1; x = x >> 1 } return n } called by 1: nq_vput |
| 32 | func nq_vput(buf: *u8, bp: i64, v: i64) -> i64 |
| 40 | func nq_vlen(buf: *u8, bp: i64) -> i64 { return 5 + nx_br_get(buf, bp, 5) } |
| 42 | func nq_vval(buf: *u8, bp: i64) -> i64 |
| 50 | func nq_yawn(yaw: i64) -> i64 { return ((yaw % 360) + 360) % 360 } |
| 53 | func nq_pack_full(buf: *u8, f: *i64) -> i64 |
| 68 | func nq_unpack_full(buf: *u8, f: *i64) -> i64 |
| 84 | func nq_pack_delta(buf: *u8, base: *i64, cur: *i64) -> i64 |
| 97 | func nq_unpack_delta(buf: *u8, base: *i64, out: *i64) -> i64 |