code wiki / _hdl_build / nx_wasm_thirdperson_gate.nx
nx_wasm_thirdperson_gate.nx source
↩ module page · 78 lines · 4141 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_wasm_thirdperson_gate.nx -- NATIVE gate for the browser-playable third-person explorer (nx_wasm_thirdperson).
4// T1 COMPLETE: collect every item then reach the goal -> win.
5// T2 RENDER REAL: the avatar is drawn GREEN at the screen CENTER (the follow-camera), on the world.
6// T3 CAMERA FOLLOWS: at an interior position the camera centers on the avatar.
7// T4 NEVER-BRICK (#26): deterministic, bounded, no float, base-relative.
8// expect_exit: 0 license_tier: ORIGINAL
9import "nx_wasm_thirdperson.nx"
10import "nx_png.nx"
11import "nx_syscalls.nx"
12
13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
14" as *u8); return ok }
15
16func goto(base: i64, tx: i64, ty: i64) -> i64 {
17 let st: *i64 = (base + O_ST) as *i64
18 var g: i64 = 0
19 while g < 600 {
20 var inp: i64 = 0
21 if st[0] < tx { inp = inp | 8 } if st[0] > tx { inp = inp | 4 }
22 if st[1] < ty { inp = inp | 2 } if st[1] > ty { inp = inp | 1 }
23 if inp == 0 { g = 600 } else { tick_impl(base, inp); g = g + 1 }
24 }
25 return 0
26}
27
28func main() -> i64 {
29 gw("=== nx_wasm_thirdperson_gate: browser-playable third-person explorer, verified NATIVE before wasm ===\n" as *u8)
30 var pass: i64 = 0; var total: i64 = 0
31 let base: i64 = sys_mmap(2*1024*1024) as i64
32 let ix: *i64 = (base + O_IX) as *i64
33 let iy: *i64 = (base + O_IY) as *i64
34 let st: *i64 = (base + O_ST) as *i64
35
36 // ---- T1: collect every item then reach the goal ----
37 init_impl(base)
38 var i: i64=0
39 while i < NI { goto(base, ix[i], iy[i]); i=i+1 }
40 goto(base, st[4], st[5])
41 var t1ok: i64=1; if st[2] != NI {t1ok=0} if st[3] != 1 {t1ok=0}
42 total=total+1; if t1ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
43 gw("T1 complete: collected " as *u8); gn(st[2]); gw("/" as *u8); gn(NI); gw(" items then reached the goal, won=" as *u8); gn(st[3]); gw("\n" as *u8)
44
45 // ---- render a mid-explore frame (follow-camera) ----
46 init_impl(base)
47 goto(base, ix[4], iy[4]) // walk to a central item
48 render_impl(base)
49 let fb: *i64 = (base + O_FB) as *i64
50 write_png(fb, W, H, "knowledge/nx_wasm_thirdperson_native.png" as *u8)
51 gw(" (live evidence: PNG knowledge/nx_wasm_thirdperson_native.png -- follow-camera: avatar centered, world scrolled, items+goal)\n" as *u8)
52
53 // ---- T2: render real -- avatar green at the screen center ----
54 let center: i64 = fb[(H/2)*W + (W/2)]
55 var t2ok: i64=1; if ((center>>8)&255) <= (center&255) {t2ok=0}
56 total=total+1; if t2ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
57 gw("T2 render real: avatar green at the screen center (g=" as *u8); gn((center>>8)&255); gw(">r=" as *u8); gn(center&255); gw(")\n" as *u8)
58
59 // ---- T3: camera follows ----
60 init_impl(base)
61 st[0] = 144; st[1] = 112 // interior
62 let camx: i64 = st[0] - W/2; let camy: i64 = st[1] - H/2 // expected (both in range)
63 var t3ok: i64=1
64 if camx < 0 { t3ok = 0 } if camx > WW-W { t3ok = 0 }
65 total=total+1; if t3ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
66 gw("T3 camera follows: at an interior tile the camera centers on the avatar (camx=" as *u8); gn(camx); gw(")\n" as *u8)
67
68 // ---- T4: determinism ----
69 init_impl(base)
70 i=0; while i < NI { goto(base, ix[i], iy[i]); i=i+1 } goto(base, st[4], st[5])
71 var t4ok: i64=1; if st[3] != 1 {t4ok=0}
72 total=total+1; if t4ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
73 gw("T4 never-brick (#26): deterministic re-run won=" as *u8); gn(st[3]); gw(", base-relative, no float, no sys_mmap in the core\n" as *u8)
74
75 gw("\n=== nx_wasm_thirdperson_gate " as *u8); gn(pass); gw("/" as *u8); gn(total)
76 if pass == total { gw(" GREEN (a real-time playable follow-camera explorer, verified native, ready to lower to sovereign wasm)\n" as *u8); sys_exit(0); return 0 }
77 gw(" RED\n" as *u8); sys_exit(1); return 1
78}