code wiki / _hdl_build / nx_wasmfps_gate.nx

nx_wasmfps_gate.nx source

↩ module page · 39 lines · 1696 B

1// nx_wasmfps_gate.nx -- NATIVE eyeball check of the EXACT wasm-targeted first-person renderer: runs nx_wasmfps's 2// render_at with base = an mmap'd region (instead of wasm linear-memory base 0) and writes PNGs. Same code path 3// the browser will run -> verify-by-eye before compiling to wasm. license_tier: ORIGINAL 4import "nx_syscalls.nx" 5import "nx_f32_hw.nx" 6import "nx_png.nx" 7import "nx_wasmfps.nx" 8 9func main() -> i64 { 10 let base: i64 = sys_mmap(mem_bytes()) as i64 11 let cgx: i64 = 48 12 let cgz: i64 = 10 13 let eye: i64 = terrain_h(base, cgx, cgz) + 4 14 let camx256: i64 = cgx * 256 + 128 15 let camy256: i64 = eye * 256 16 let camz256: i64 = cgz * 256 + 128 17 let camx: i64 = f32_div(f32_of(camx256), f32_of(256)) 18 let camy: i64 = f32_div(f32_of(camy256), f32_of(256)) 19 let camz: i64 = f32_div(f32_of(camz256), f32_of(256)) 20 21 // EDIT the world to verify break(-)/place(+): one tall tower dead-center + flanking pits 22 edit_delta(base, 48, 14, 14) 23 edit_delta(base, 47, 14, 14) 24 edit_delta(base, 45, 13, 0 - 6) 25 edit_delta(base, 51, 13, 0 - 6) 26 27 // view 1: looking +z, pitched down ~12 deg 28 build_R(base, 1000, 0, 978, 0 - 208) 29 render_at(base, camx, camy, camz, camx256 / 256, camz256 / 256) 30 write_png((base + fb_off()) as *i64, ww(), hh(), "/mnt/c/Users/elder/AppData/Local/Temp/fpsw1.png" as *u8) 31 32 // view 2: yaw ~40 deg, level 33 build_R(base, 766, 643, 1000, 0) 34 render_at(base, camx, camy, camz, camx256 / 256, camz256 / 256) 35 write_png((base + fb_off()) as *i64, ww(), hh(), "/mnt/c/Users/elder/AppData/Local/Temp/fpsw2.png" as *u8) 36 37 sys_write(1, "wasmfps gate: wrote fpsw1.png fpsw2.png\n" as *u8, 39) 38 return 0 39}