nx_gen_content.nx source
↩ module page · 104 lines · 5210 B
1// nx_gen.nx -- ★R5 of the Infinigen ladder: the UNIFIED SOVEREIGN GENERATOR (their V2 bet = ProcFunc, a
2// function-oriented abstraction over ALL asset generators). One data-driven request envelope + a self-describing
3// registry dispatches to every heterogeneous organ, so a caller asks for any asset by KIND + SEED + PARAMS through
4// a single surface and gets back a standard result. This is the abstraction the eventual public generate-UI (R10)
5// and the world compositor both sit on. Adding a generator = one registry row + a thin adapter, never touching a
6// caller (composition over configuration). license_tier: ORIGINAL
7import "nx_worldgen.nx"
8import "nx_treegen.nx"
9import "nx_creaturegen.nx"
10import "nx_figuregen.nx"
11import "nx_persongen.nx"
12import "nx_sdfrender.nx" // fb_off / sdf_render / sdf_bytes for the FACE adapter
13
14const GEN_WORLD: i64 = 0
15const GEN_TREE: i64 = 1
16const GEN_CREATURE: i64 = 2
17const GEN_FIGURE: i64 = 3
18const GEN_FACE: i64 = 4
19const GEN_NKIND: i64 = 5
20const GEN_TREEBG: i64 = 13763290 // 210 + 224*256 + 238*65536
21const GEN_ANATBG: i64 = 2890778 // 26 + 28*256 + 44*65536
22
23// ---- self-describing registry (what makes this an ABSTRACTION, not a switch buried in each caller) ----
24func gen_kind_count() -> i64 { return GEN_NKIND }
25func gen_kind_name(k: i64) -> *u8 {
26 if k == GEN_WORLD { return "world" as *u8 }
27 if k == GEN_TREE { return "tree" as *u8 }
28 if k == GEN_CREATURE { return "creature" as *u8 }
29 if k == GEN_FIGURE { return "figure" as *u8 }
30 if k == GEN_FACE { return "face" as *u8 }
31 return "?" as *u8
32}
33func gen_param_schema(k: i64) -> *u8 {
34 if k == GEN_WORLD { return "seed, mode(0clear/1sunset/2overcast), biome(0temperate/1desert/2arctic/3autumn)" as *u8 }
35 if k == GEN_TREE { return "seed, species(0broadleaf/1conifer/2birch/3palm/4dead)" as *u8 }
36 if k == GEN_CREATURE { return "seed, plan(0quadruped/1bird/2fish)" as *u8 }
37 if k == GEN_FIGURE { return "seed" as *u8 }
38 if k == GEN_FACE { return "seed" as *u8 }
39 return "" as *u8
40}
41
42func gen_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
43func gen_lum(px: i64) -> i64 { return (px&255)+((px>>8)&255)+((px>>16)&255) }
44func gen_content_bg(fb: *i64, npx: i64, bg: i64) -> i64 { var c: i64=0; var i: i64=0; while i<npx { if fb[i]!=bg { c=c+1 } i=i+1 } return c }
45func gen_content_lum(fb: *i64, npx: i64, thr: i64) -> i64 { var c: i64=0; var i: i64=0; while i<npx { if gen_lum(fb[i])>thr { c=c+1 } i=i+1 } return c }
46
47// ★THE UNIFIED SURFACE. spec = [kind, seed, p0, p1]. res = [ok, W, H, content_px, fb_ptr, kind].
48// Renders the described asset into a fresh framebuffer; caller reads res[4] (fb ptr) to write PNG / composite.
49// Unknown kind -> res[0]=0 (fail-closed). Deterministic: same spec -> same bytes.
50func nx_gen(spec: *i64, res: *i64) -> i64 {
51 let kind: i64 = spec[0]
52 let seed: i64 = spec[1]
53 res[0]=0; res[1]=0; res[2]=0; res[3]=0; res[4]=0; res[5]=kind
54 if kind == GEN_WORLD {
55 let W: i64 = wg_w(); let H: i64 = wg_h()
56 let fb: *i64 = sys_mmap(W*H*8) as *i64
57 let dep: *i64 = sys_mmap(W*H*8) as *i64
58 wg_set_gi(1)
59 worldgen_render_bd(seed, spec[2], spec[3], fb, dep)
60 res[0]=1; res[1]=W; res[2]=H; res[3]=W*H; res[4]=fb as i64
61 return 1
62 }
63 if kind == GEN_TREE {
64 let P: *i64 = sys_mmap(TG_CAP*TG_STR*8) as *i64
65 let n: i64 = treegen_build_sp(P, seed, spec[2])
66 let W: i64 = tg_w(); let H: i64 = tg_h()
67 let fb: *i64 = sys_mmap(W*H*8) as *i64
68 treegen_render(P, n, 300, 4, 210, 224, 238, fb)
69 res[0]=1; res[1]=W; res[2]=H; res[3]=gen_content_bg(fb, W*H, GEN_TREEBG); res[4]=fb as i64
70 return 1
71 }
72 if kind == GEN_CREATURE {
73 let AP: *i64 = sys_mmap(96*AS_STRIDE*8) as *i64
74 let n: i64 = creaturegen_build_plan(AP, seed, spec[2])
75 let W: i64 = as_w(); let H: i64 = as_h()
76 let fb: *i64 = sys_mmap(W*H*8) as *i64
77 var yaw: i64 = 4800
78 if spec[2] == 2 { yaw = 4200 }
79 anatstack_render(AP, n, yaw, 3, 1, 45, 150, 116, 84, fb)
80 res[0]=1; res[1]=W; res[2]=H; res[3]=gen_content_bg(fb, W*H, GEN_ANATBG); res[4]=fb as i64
81 return 1
82 }
83 if kind == GEN_FIGURE {
84 let AP: *i64 = sys_mmap(96*AS_STRIDE*8) as *i64
85 let sk: *i64 = sys_mmap(8*8) as *i64
86 let n: i64 = figuregen_build(AP, seed, sk)
87 let W: i64 = as_w(); let H: i64 = as_h()
88 let fb: *i64 = sys_mmap(W*H*8) as *i64
89 anatstack_render(AP, n, 0, 3, 1, 42, sk[0], sk[1], sk[2], fb)
90 res[0]=1; res[1]=W; res[2]=H; res[3]=gen_content_bg(fb, W*H, GEN_ANATBG); res[4]=fb as i64
91 return 1
92 }
93 if kind == GEN_FACE {
94 let base: i64 = sys_mmap(sdf_bytes()) as i64
95 let sk: *i64 = sys_mmap(8*8) as *i64
96 let idv: *i64 = sys_mmap(8*8) as *i64
97 persongen_build(base, seed, sk, idv)
98 sdf_render(base, 200, 4, sk[0], sk[1], sk[2])
99 let fb: *i64 = (base + fb_off()) as *i64
100 res[0]=1; res[1]=512; res[2]=384; res[3]=gen_content_lum(fb, 512*384, 150); res[4]=fb as i64
101 return 1
102 }
103 return 0 // unknown kind: fail-closed
104}