code wiki / _hdl_build / nx_voxel_spec_gate.nx
nx_voxel_spec_gate.nx source
↩ module page · 53 lines · 2412 B
1// nx_voxel_spec_gate.nx -- proves the ENGINE EMIT TARGET: a game-SPEC (DATA) -> a generated 3D voxel world,
2// hands-off. Mirrors the dungeon path's "2 distinct specs -> 2 distinct playable games" but for 3D. Two specs
3// (different seed/water/height/camera) -> render_world -> two BMPs. GREEN iff BOTH render a real world AND the
4// two frames DIFFER (distinct data -> distinct world = real generation, not a baked scene). AUTHOR=ORGAN.
5import "nx_syscalls.nx"
6import "nx_voxel_world.nx"
7
8// assemble an 11-field spec (the DATA contract) into a buffer.
9func make_spec(seed: i64, n: i64, water: i64, maxh: i64, latsp: i64,
10 psin: i64, pcos: i64, ysin: i64, ycos: i64, push: i64, focal: i64) -> *i64 {
11 let s: *i64 = sys_mmap(12 * 8) as *i64
12 s[0] = seed; s[1] = n; s[2] = water; s[3] = maxh; s[4] = latsp
13 s[5] = psin; s[6] = pcos; s[7] = ysin; s[8] = ycos; s[9] = push; s[10] = focal
14 s[11] = 0
15 return s
16}
17func frame_hash(fb: *i64) -> i64 {
18 var h: i64 = 1469598103
19 var i: i64 = 0
20 let n: i64 = world_pixels()
21 while i < n { h = (h * 31 + fb[i]) % 1000000007; i = i + 1 }
22 return h
23}
24func count_world(fb: *i64) -> i64 {
25 let sky: i64 = world_sky()
26 var c: i64 = 0
27 var i: i64 = 0
28 let n: i64 = world_pixels()
29 while i < n { if fb[i] != sky { c = c + 1 } i = i + 1 }
30 return c
31}
32
33func main() -> i64 {
34 let fbA: *i64 = sys_mmap(world_fb_bytes()) as *i64
35 let zbA: *i64 = sys_mmap(world_fb_bytes()) as *i64
36 let fbB: *i64 = sys_mmap(world_fb_bytes()) as *i64
37 let zbB: *i64 = sys_mmap(world_fb_bytes()) as *i64
38
39 // SPEC A: seed 7, low sea, full peaks, gentle frequency, ~35deg view.
40 let sa: *i64 = make_spec(7, 14, 1, 6, 4, 574, 819, 574, 819, 24, 300)
41 render_world(sa, fbA, zbA)
42 write_bmp(fbA, "web_assets/_game_build/f32world_a.bmp" as *u8)
43
44 // SPEC B: seed 42, higher sea, tighter frequency, different camera = a visibly different world.
45 let sb: *i64 = make_spec(42, 14, 2, 6, 3, 469, 883, 342, 940, 22, 320)
46 render_world(sb, fbB, zbB)
47 write_bmp(fbB, "web_assets/_game_build/f32world_b.bmp" as *u8)
48
49 if count_world(fbA) < 6000 { return 1 } // A generated a real world
50 if count_world(fbB) < 6000 { return 2 } // B generated a real world
51 if frame_hash(fbA) == frame_hash(fbB) { return 3 } // distinct specs -> distinct worlds (real gen)
52 return 0
53}