code wiki / (root) / nx_netquant.nx

nx_netquant.nx

buildroot/runtime/nx_netquant.nx

5145 B112 linesdepth 1pulls 1 transitivereach 3 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_bitio.nx nx_netquant.nx nx_adverse_net_gate.nx nx_netquant_gate.nx nx_pets3d_wasm.nx

imports: nx_bitio.nx

imported by: nx_adverse_net_gate.nxnx_netquant_gate.nxnx_pets3d_wasm.nx

structs

none

consts

21const NQ_NF: i64 = 10
22const NQ_BIAS: i64 = 131072 // position bias (2^17) -> 18-bit unsigned field
23const NQ_FULL_BITS: i64 = 88 // 18+12+18+9+8+3+7+3+6+4

functions

26func nq_zz(v: i64) -> i64 { if v < 0 { return ((0 - v) << 1) - 1 } return v << 1 }
called by 1: nq_vput
27func nq_unzz(z: i64) -> i64 { if (z & 1) == 1 { return 0 - ((z + 1) >> 1) } return z >> 1 }
called by 1: nq_vval
29func 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
32func nq_vput(buf: *u8, bp: i64, v: i64) -> i64
40func nq_vlen(buf: *u8, bp: i64) -> i64 { return 5 + nx_br_get(buf, bp, 5) }
called by 1: nq_unpack_delta calls 1: nx_br_get
42func nq_vval(buf: *u8, bp: i64) -> i64
called by 1: nq_unpack_delta calls 2: nx_br_getnq_unzz
50func nq_yawn(yaw: i64) -> i64 { return ((yaw % 360) + 360) % 360 }
53func nq_pack_full(buf: *u8, f: *i64) -> i64
68func nq_unpack_full(buf: *u8, f: *i64) -> i64
called by 2: mainb_ingest_frame_at calls 1: nx_br_get
84func nq_pack_delta(buf: *u8, base: *i64, cur: *i64) -> i64
called by 2: mainmain calls 2: nx_bw_putnq_vput
97func nq_unpack_delta(buf: *u8, base: *i64, out: *i64) -> i64
called by 1: main calls 3: nx_br_getnq_vvalnq_vlen