code wiki / _hdl_build / nx_authorworld_gate.nx
nx_authorworld_gate.nx source
↩ module page · 178 lines · 7364 B
1// nx_authorworld_gate.nx -- ★AUTHORING, CONTENT TYPE 2: describe a WORLD -> the staged pipeline generates it with the
2// requested CHARACTER (the Orca pattern generalised beyond creatures). All measured against a default world, causally.
3// T1 "a snowy mountainous world" -> more snow AND higher peaks than default. T2 "an ocean world with islands" -> more
4// sea. T3 "a flat hot desert" -> lower peaks + ~no snow. T4 REFUSAL: "a purple feeling" -> kind 0 (no world). T5
5// determinism. T6 evidence: three described worlds rendered. license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_png.nx"
8import "nx_trimesh.nx"
9import "nx_authorgen.nx"
10
11func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
13func clearfb(fb: *i64, n: i64, c: i64) -> i64 { var i: i64=0; while i<n { fb[i]=c; i=i+1 } return 0 }
14
15const BG: i64 = 30 + 40*256 + 58*65536
16
17// measure the CURRENTLY-CONFIGURED world over a grid. out[0]=snow cells, out[1]=ocean cells, out[2]=peak height
18func measure_world(out: *i64) -> i64 {
19 wp_hydro_bake()
20 var snow: i64 = 0
21 var ocean: i64 = 0
22 var peak: i64 = 0 - 1000000
23 var gz: i64 = 0
24 while gz < 31 {
25 var gx: i64 = 0
26 while gx < 31 {
27 let x: i64 = (gx-15)*600
28 let z: i64 = (gz-15)*600
29 let h: i64 = wp_height(x, z)
30 if h > peak { peak = h }
31 if h < 0 { ocean = ocean + 1 }
32 if wp_biome(x, z) == 4 { snow = snow + 1 }
33 gx = gx + 1
34 }
35 gz = gz + 1
36 }
37 out[0] = snow
38 out[1] = ocean
39 out[2] = peak
40 return 0
41}
42
43func render_world(fb: *i64, W: i64, H: i64) -> i64 {
44 tm_reset()
45 tm_set_spec(0)
46 tm_set_image(0 as *u8, 0, 0)
47 tm_set_tex(0)
48 let TN: i64 = 61
49 let SP: i64 = 160
50 let terrFrom: i64 = tm_nv()
51 var gz: i64 = 0
52 while gz < TN {
53 var gx: i64 = 0
54 while gx < TN {
55 let wx: i64 = (gx-30)*SP
56 let wz: i64 = (gz-30)*SP
57 var h: i64 = wp_height(wx, wz)
58 let slope: i64 = wp_iabs(wp_height(wx+SP, wz) - h) + wp_iabs(wp_height(wx, wz+SP) - h)
59 let col: i64 = wp_surface(wx, wz, h, slope)
60 if h < 0-14 { h = 0-14 }
61 let vi: i64 = tm_vert(wx, h, wz)
62 tm_vcol(vi, col)
63 gx = gx + 1
64 }
65 gz = gz + 1
66 }
67 gz = 0
68 while gz < TN-1 {
69 var qx: i64 = 0
70 while qx < TN-1 {
71 let v0: i64 = terrFrom + gz*TN + qx
72 tm_quad(v0, v0+1, v0+TN+1, v0+TN, 0)
73 qx = qx + 1
74 }
75 gz = gz + 1
76 }
77 tm_compute_normals()
78 tm_place(0, tm_nv(), 0, 0-460, 0, 1000)
79 tm_set_sun(340, 780, 0-300)
80 tm_shadow_bake()
81 tm_set_tex(64)
82 tm_set_shadow(1)
83 clearfb(fb, W*H, BG)
84 trimesh_render_aa(fb, W, H, 620, 0-300, 6200, 380, 2)
85 tm_set_shadow(0)
86 tm_set_tex(0)
87 return 0
88}
89
90func main() -> i64 {
91 hw("=== nx_authorworld_gate -- describe a WORLD -> the pipeline generates its character ===\n" as *u8)
92 var fails: i64 = 0
93 let base: *i64 = sys_mmap(32) as *i64
94 let m: *i64 = sys_mmap(32) as *i64
95
96 // baseline (default world)
97 wp_init(7)
98 measure_world(base)
99 hw(" DEFAULT world: snow="); pn(base[0]); hw(" ocean="); pn(base[1]); hw(" peak="); pn(base[2]); hw("\n" as *u8)
100
101 // ---- T1 "a snowy mountainous world" ----
102 ag_parse("a snowy mountainous world" as *u8)
103 let k1: i64 = ag_kind()
104 measure_world(m)
105 hw(" 'a snowy mountainous world' -> kind="); pn(k1); hw(" snow="); pn(m[0]); hw(" peak="); pn(m[2]); hw("\n" as *u8)
106 var t1: i64 = 0
107 if k1 == 2 { if m[0] > base[0] + 20 { if m[2] > base[2] { t1 = 1 } } }
108 if t1 == 1 { hw("T1 PASS a SNOWY MOUNTAINOUS world was generated (more snow AND higher peaks than default)\n" as *u8) }
109 else { fails=fails+1; hw("T1 FAIL\n" as *u8) }
110
111 // ---- T2 "an ocean world with islands" ----
112 ag_parse("an ocean world with islands" as *u8)
113 let k2: i64 = ag_kind()
114 measure_world(m)
115 hw(" 'an ocean world with islands' -> kind="); pn(k2); hw(" ocean="); pn(m[1]); hw(" (default "); pn(base[1]); hw(")\n" as *u8)
116 var t2: i64 = 0
117 if k2 == 2 { if m[1] > base[1] + 60 { t2 = 1 } }
118 if t2 == 1 { hw("T2 PASS an OCEAN/ISLAND world was generated (far more sea than default)\n" as *u8) }
119 else { fails=fails+1; hw("T2 FAIL\n" as *u8) }
120
121 // ---- T3 "a flat hot desert" ----
122 ag_parse("a flat hot desert" as *u8)
123 let k3: i64 = ag_kind()
124 measure_world(m)
125 hw(" 'a flat hot desert' -> kind="); pn(k3); hw(" snow="); pn(m[0]); hw(" peak="); pn(m[2]); hw("\n" as *u8)
126 var t3: i64 = 0
127 if k3 == 2 { if m[0] < 4 { if m[2] < base[2] { t3 = 1 } } }
128 if t3 == 1 { hw("T3 PASS a FLAT HOT DESERT was generated (~no snow + lower peaks than default)\n" as *u8) }
129 else { fails=fails+1; hw("T3 FAIL\n" as *u8) }
130
131 // ---- T4 refusal: not a world, not a creature ----
132 ag_parse("a purple feeling of nostalgia" as *u8)
133 let k4: i64 = ag_kind()
134 hw(" 'a purple feeling of nostalgia' -> kind="); pn(k4); hw(" (0 = honestly refused)\n" as *u8)
135 var t4: i64 = 0
136 if k4 == 0 { t4 = 1 }
137 if t4 == 1 { hw("T4 PASS a non-world/non-creature request is REFUSED (no fake generation)\n" as *u8) }
138 else { fails=fails+1; hw("T4 FAIL\n" as *u8) }
139
140 // ---- T5 determinism ----
141 ag_parse("a snowy mountainous world" as *u8)
142 measure_world(m)
143 let s5: i64 = m[0]
144 ag_parse("a snowy mountainous world" as *u8)
145 measure_world(m)
146 var t5: i64 = 0
147 if m[0] == s5 { t5 = 1 }
148 if t5 == 1 { hw("T5 PASS deterministic (same words -> same world)\n" as *u8) } else { fails=fails+1; hw("T5 FAIL\n" as *u8) }
149
150 // ---- T6 evidence: three described worlds ----
151 let W: i64 = 360
152 let H: i64 = 300
153 let GW: i64 = W*3
154 let gal: *i64 = sys_mmap(GW*H*8) as *i64
155 clearfb(gal, GW*H, BG)
156 let fb: *i64 = sys_mmap(W*H*8) as *i64
157 var slot: i64 = 0
158 while slot < 3 {
159 if slot == 0 { ag_parse("a snowy mountainous world" as *u8) }
160 if slot == 1 { ag_parse("an ocean world with islands" as *u8) }
161 if slot == 2 { ag_parse("a flat hot desert" as *u8) }
162 render_world(fb, W, H)
163 var y: i64 = 0
164 while y < H {
165 var x: i64 = 0
166 while x < W { gal[y*GW + slot*W + x] = fb[y*W + x]; x = x + 1 }
167 y = y + 1
168 }
169 slot = slot + 1
170 }
171 write_png(gal, GW, H, "knowledge/nx_authorworld.png" as *u8)
172 hw("T6 evidence -> knowledge/nx_authorworld.png (snowy-mountain | ocean-islands | flat-desert, each from a sentence)\n" as *u8)
173
174 if fails == 0 { hw("AUTHORWORLD-GATE GREEN -- content type 2: describe a WORLD -> the staged pipeline generates its measured character (climate/relief/land-sea from adjectives), causally, deterministically; non-worlds refused. Residual: free-NL (rule-based v0), named structures/settlements, edit-existing, streaming the authored world.\n" as *u8); sys_exit(0); return 0 }
175 hw("AUTHORWORLD-GATE RED fails="); pn(fails); hw("\n" as *u8)
176 sys_exit(1)
177 return 1
178}