code wiki / _hdl_build / nx_lerp_smooth_gate.nx
nx_lerp_smooth_gate.nx source
↩ module page · 80 lines · 4408 B
1// nx_lerp_smooth_gate.nx -- proves the sovereign peer render-smoothing primitive (nx_lerp_smooth), the EXACT
2// code the wasm game uses for smooth peer motion. Native nx_cc->nxasm, NO node.
3// 1) interpolation endpoints: alpha 0=prev, 128=midpoint, 256=cur
4// 2) monotone glide: as alpha advances, rendered moves prev->cur monotonically, each per-frame step bounded
5// 3) bounded extrapolation: past cur it keeps gliding (no freeze) but is CLAMPED (no runaway)
6// 4) reaches cur in ~5 frames (the ~80ms sync at ~60fps)
7// 5) anti-tautology (neg): rendered actually depends on alpha (not constant); works for downward motion too
8// license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_gate_emit_lib.nx"
11import "nx_lerp_smooth.nx"
12import "nx_gate_verdict.nx"
13
14func g_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
15
16func main() -> i64 {
17 g_puts("nx_lerp_smooth gate (sovereign peer-render smoothing, the wasm's exact code, NO node)\n" as *u8)
18 var pass: i64 = 0; var total: i64 = 0
19 let P: i64 = 0; let C: i64 = 100
20
21 // 1) endpoints
22 var r1: i64 = 1
23 if ls_interp(P, C, 0) != 0 { r1 = 0 }
24 if ls_interp(P, C, 128) != 50 { r1 = 0 }
25 if ls_interp(P, C, 256) != 100 { r1 = 0 }
26 pass = pass + g_check("interpolation endpoints (0=prev, 128=mid, 256=cur)" as *u8, r1); total=total+1
27
28 // 2) monotone glide + bounded per-frame step (alpha 0 -> cur)
29 var a: i64 = 0
30 var prev_r: i64 = ls_interp(P, C, a)
31 var mono: i64 = 1
32 var max_step: i64 = 0
33 var frames: i64 = 0
34 while a < 256 {
35 a = ls_advance(a)
36 let r: i64 = ls_interp(P, C, a)
37 if r < prev_r { mono = 0 } // never moves backward
38 let st: i64 = g_abs(r - prev_r); if st > max_step { max_step = st }
39 prev_r = r
40 frames = frames + 1
41 }
42 g_puts(" [measure] glide prev->cur in " as *u8); g_pn(frames); g_puts(" frames, max per-frame step=" as *u8); g_pn(max_step); g_puts(" (raw jump would be 100)\n" as *u8)
43 var r2: i64 = 1
44 if mono != 1 { r2 = 0 }
45 if max_step > 25 { r2 = 0 } // each frame moves <= ~1/4 of the gap (smooth, not a teleport)
46 pass = pass + g_check("monotone glide, each frame-step << the raw 100-voxel jump" as *u8, r2); total=total+1
47
48 // 3) bounded extrapolation past cur (no freeze, no runaway)
49 let ex: i64 = ls_interp(P, C, 320) // 25% past cur
50 var r3: i64 = 1
51 if ex <= 100 { r3 = 0 } // it DID glide past cur (kept moving on a dropped sync)
52 if ex > 130 { r3 = 0 } // but bounded (<= 125 by design)
53 if ls_advance(320) != 320 { r3 = 0 } // clamped: never advances past the cap (no runaway)
54 if ls_advance(300) != 320 { r3 = 0 } // and clamps the overshoot exactly to the cap
55 g_puts(" [measure] extrapolated at cap = " as *u8); g_pn(ex); g_puts(" (cur=100, bounded +25%)\n" as *u8)
56 pass = pass + g_check("bounded extrapolation (glides past cur, clamped, no runaway)" as *u8, r3); total=total+1
57
58 // 4) reaches cur in ~5 frames
59 var a2: i64 = 0; var f2: i64 = 0
60 while a2 < 256 { a2 = ls_advance(a2); f2 = f2 + 1 }
61 pass = pass + g_check("reaches cur in <= 6 frames (the ~80ms sync)" as *u8, f2 <= 6); total=total+1
62
63 // 5) anti-tautology + downward motion
64 var r5: i64 = 1
65 if ls_interp(0, 100, 64) == ls_interp(0, 100, 192) { r5 = 0 } // alpha actually matters
66 if ls_interp(100, 0, 0) != 100 { r5 = 0 } // downward: prev
67 if ls_interp(100, 0, 256) != 0 { r5 = 0 } // downward: cur
68 pass = pass + g_check("anti-tautology: rendered depends on alpha; downward motion ok" as *u8, r5); total=total+1
69
70 g_puts("---- lerp-smooth gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
71 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
72 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
73 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
74 let ctr__dry: *i64 = gv_ctr()
75 ctr__dry[0] = pass
76 ctr__dry[1] = total
77 let rc__dry: i64 = gv_verdict("LERP-SMOOTH-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
78 sys_exit(rc__dry)
79 return rc__dry
80}