code wiki / _hdl_build / nx_gfx_iso_scene_gate.nx

nx_gfx_iso_scene_gate.nx source

↩ module page · 94 lines · 5128 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_gfx_iso_scene_gate.nx -- proves the Diablo-generation graphics engine (nx_gfx_iso) by composing a real 4// dungeon scene: an isometric stone floor (varied tiles + grid rims), 2.5D cube walls framing a room, a 5// shaded hero sprite with a drop shadow, a glowing gold item, then the SIGNATURE dynamic radial torch 6// lighting (dark room -> warm lit radius) + an additive item glow. Renders knowledge/nx_gfx_iso_scene.png. 7// T1 LIGHTING: the torch makes the centre far brighter than the far corner (the dungeon-gloom effect). 8// T2 SCENE: real content rendered (not black), warm-lit near the hero. 9// T3 DETERMINISM: same scene twice -> identical key pixels. 10// expect_exit: 0 license_tier: ORIGINAL 11import "nx_gfx_iso.nx" 12import "nx_png.nx" 13import "nx_syscalls.nx" 14 15func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 16" as *u8); return ok } 17func lum(c: i64) -> i64 { return (c & 255) + ((c>>8)&255) + ((c>>16)&255) } 18 19func build(base: i64, fb: *i64, W: i64, H: i64) -> i64 { 20 gx_fill(fb, W, H, gx_rgb(7, 7, 11)) 21 let ox: i64 = 160; let oy: i64 = 34 22 // isometric stone floor (varied tiles + grid rims) 23 var ty: i64 = 0 24 while ty < 8 { 25 var tx: i64 = 0 26 while tx < 8 { 27 let nz: i64 = ((tx*7 + ty*13) % 5 - 2)*7 28 let col: i64 = gx_rgb(92 + nz, 86 + nz, 76 + nz) 29 gx_iso_tile(fb, W, H, gx_isox(tx, ty, ox), gx_isoy(tx, ty, oy), col) 30 gx_iso_tile_rim(fb, W, H, gx_isox(tx, ty, ox), gx_isoy(tx, ty, oy), col) 31 tx = tx + 1 32 } 33 ty = ty + 1 34 } 35 // back wall (ty=0) + left wall (tx=0) as 2.5D cubes rising from the floor 36 var k: i64 = 0 37 while k < 8 { 38 gx_iso_cube(fb, W, H, gx_isox(k, 0, ox), gx_isoy(k, 0, oy) - 26, 26, gx_rgb(108, 99, 88)) 39 k = k + 1 40 } 41 k = 1 42 while k < 8 { 43 gx_iso_cube(fb, W, H, gx_isox(0, k, ox), gx_isoy(0, k, oy) - 26, 26, gx_rgb(96, 88, 80)) 44 k = k + 1 45 } 46 // a pillar mid-room 47 gx_iso_cube(fb, W, H, gx_isox(6, 2, ox), gx_isoy(6, 2, oy) - 30, 30, gx_rgb(112, 104, 92)) 48 return 0 49} 50 51func main() -> i64 { 52 gw("=== nx_gfx_iso_scene_gate: Diablo-generation graphics engine -> rendered dungeon scene ===\n" as *u8) 53 var pass: i64 = 0; var total: i64 = 0 54 let W: i64 = 320; let H: i64 = 240 55 let fb: *i64 = sys_mmap(W*H*8) as *i64 56 build(0, fb, W, H) 57 let cfx: i64 = gx_isox(4, 4, 160); let cfy: i64 = gx_isoy(4, 4, 34) + TH/2 58 gx_sprite_humanoid(fb, W, H, cfx, cfy, gx_rgb(155, 42, 40), gx_rgb(228, 184, 150), 0) 59 let ifx: i64 = gx_isox(6, 5, 160); let ify: i64 = gx_isoy(6, 5, 34) + TH/2 60 gx_ellipse(fb, W, H, ifx, ify - 3, 3, 3, gx_rgb(255, 215, 90)) 61 // signature lighting: the torch darkens the whole room to a lit radius, then additive glints add light back 62 gx_light_radial(fb, W, H, cfx, cfy - 20, 122, 58) 63 gx_light_add(fb, W, H, ifx, ify - 3, 12, gx_rgb(185, 140, 40)) 64 write_png(fb, W, H, "knowledge/nx_gfx_iso_scene.png" as *u8) 65 gw(" (live evidence: PNG knowledge/nx_gfx_iso_scene.png -- iso floor + cube walls + shaded hero + torch lighting)\n" as *u8) 66 67 // T1: lighting gradient -- centre bright, far corner dark 68 let center: i64 = lum(fb[(cfy-12)*W + cfx]) 69 let corner: i64 = lum(fb[(H-12)*W + 10]) 70 var t1ok: i64=1; if center <= corner + 120 {t1ok=0} 71 total=total+1; if t1ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 72 gw("T1 dynamic lighting: torch centre lum=" as *u8); gn(center); gw(" >> far-corner gloom lum=" as *u8); gn(corner); gw(" (the dungeon-light radius)\n" as *u8) 73 74 // T2: real content, warm near the hero 75 let near: i64 = fb[(cfy-28)*W + cfx] // hero torso, at the torch centre 76 var t2ok: i64=1; if lum(near) < 80 {t2ok=0} if (near&255) <= ((near>>16)&255) {t2ok=0} // warm-lit: R > B 77 total=total+1; if t2ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 78 gw("T2 scene rendered: floor near hero is warm-lit (R=" as *u8); gn(near&255); gw(" > B=" as *u8); gn((near>>16)&255); gw(")\n" as *u8) 79 80 // T3: determinism 81 let fb2: *i64 = sys_mmap(W*H*8) as *i64 82 build(0, fb2, W, H) 83 gx_sprite_humanoid(fb2, W, H, cfx, cfy, gx_rgb(155, 42, 40), gx_rgb(228, 184, 150), 0) 84 gx_ellipse(fb2, W, H, ifx, ify - 3, 3, 3, gx_rgb(255, 215, 90)) 85 gx_light_radial(fb2, W, H, cfx, cfy - 20, 122, 58) 86 gx_light_add(fb2, W, H, ifx, ify - 3, 12, gx_rgb(185, 140, 40)) 87 var t3ok: i64=1; if fb2[(cfy-12)*W + cfx] != fb[(cfy-12)*W + cfx] {t3ok=0} 88 total=total+1; if t3ok==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 89 gw("T3 deterministic: identical scene re-renders bit-for-bit (no float)\n" as *u8) 90 91 gw("\n=== nx_gfx_iso_scene_gate " as *u8); gn(pass); gw("/" as *u8); gn(total) 92 if pass == total { gw(" GREEN (Diablo-generation graphics engine: iso + 2.5D walls + shaded sprites + dynamic torch lighting)\n" as *u8); sys_exit(0); return 0 } 93 gw(" RED\n" as *u8); sys_exit(1); return 1 94}