code wiki / _hdl_build / nx_world_style_gate.nx

nx_world_style_gate.nx source

↩ module page · 52 lines · 2046 B

1// nx_world_style_gate.nx -- proves the engine is NOT one-look: the SAME world spec rendered in 3 art styles 2// (realism / toon-anime / flat-artsy), style = a spec field. 3 BMPs. GREEN iff the realism frame rendered a 3// real world AND the 3 styles produce 3 DISTINCT frames (style actually changes the output). AUTHOR=ORGAN. 4import "nx_syscalls.nx" 5import "nx_voxel_world.nx" 6 7func mk(seed: i64, n: i64, water: i64, maxh: i64, latsp: i64, 8 psin: i64, pcos: i64, ysin: i64, ycos: i64, push: i64, focal: i64, style: i64) -> *i64 { 9 let s: *i64 = sys_mmap(12 * 8) as *i64 10 s[0] = seed; s[1] = n; s[2] = water; s[3] = maxh; s[4] = latsp 11 s[5] = psin; s[6] = pcos; s[7] = ysin; s[8] = ycos; s[9] = push; s[10] = focal; s[11] = style 12 return s 13} 14func fhash(fb: *i64) -> i64 { 15 var h: i64 = 1469598103 16 var i: i64 = 0 17 let n: i64 = world_pixels() 18 while i < n { h = (h * 31 + fb[i]) % 1000000007; i = i + 1 } 19 return h 20} 21func nonsky(fb: *i64) -> i64 { 22 let sky: i64 = world_sky() 23 var c: i64 = 0 24 var i: i64 = 0 25 let n: i64 = world_pixels() 26 while i < n { if fb[i] != sky { c = c + 1 } i = i + 1 } 27 return c 28} 29 30func main() -> i64 { 31 let fb: *i64 = sys_mmap(world_fb_bytes()) as *i64 32 let zb: *i64 = sys_mmap(world_fb_bytes()) as *i64 33 34 render_world(mk(7, 14, 1, 6, 4, 574, 819, 574, 819, 24, 300, 0), fb, zb) // realism 35 let nreal: i64 = nonsky(fb) 36 let hreal: i64 = fhash(fb) 37 write_bmp(fb, "web_assets/_game_build/world_real.bmp" as *u8) 38 39 render_world(mk(7, 14, 1, 6, 4, 574, 819, 574, 819, 24, 300, 1), fb, zb) // toon / anime 40 let htoon: i64 = fhash(fb) 41 write_bmp(fb, "web_assets/_game_build/world_toon.bmp" as *u8) 42 43 render_world(mk(7, 14, 1, 6, 4, 574, 819, 574, 819, 24, 300, 2), fb, zb) // flat / artsy 44 let hflat: i64 = fhash(fb) 45 write_bmp(fb, "web_assets/_game_build/world_flat.bmp" as *u8) 46 47 if nreal < 6000 { return 1 } 48 if hreal == htoon { return 2 } 49 if hreal == hflat { return 3 } 50 if htoon == hflat { return 4 } 51 return 0 52}