nx_lerp_smooth.nx source
↩ module page · 15 lines · 1236 B
1// nx_lerp_smooth.nx -- sovereign per-peer render-smoothing primitive. Interpolate prev->cur by an alpha that
2// advances one step per frame, with BOUNDED extrapolation so a dropped network sync keeps the avatar gliding
3// (no freeze / no teleport) instead of snapping. This is the nx_interp render-in-between mechanism reduced to
4// two pure functions, shared identically by the wasm game (b_draw_peers / gi_net_smooth) AND its native gate
5// (author-by-organ: same code both sides, gated by nx_cc->nxasm with no node). Q8 alpha: 0=prev, 256=cur.
6// license_tier: ORIGINAL
7
8const LS_CUR: i64 = 256 // alpha at which rendered == cur
9const LS_MAX: i64 = 320 // alpha cap = 256 + 64 -> 25% bounded extrapolation past cur (no runaway on loss)
10const LS_STEP: i64 = 52 // ~5 frames per ~80ms sync to glide prev->cur
11
12// rendered value at alpha a between prev p and cur c. a in [0,256] interpolates; a in (256,LS_MAX] extrapolates.
13func ls_interp(p: i64, c: i64, a: i64) -> i64 { return p + (c - p) * a / LS_CUR }
14// advance an alpha one frame toward (and slightly past) cur, CLAMPED at LS_MAX so long loss holds bounded.
15func ls_advance(a: i64) -> i64 { let n: i64 = a + LS_STEP; if n > LS_MAX { return LS_MAX } return n }