nx_wasmfps.nx
buildroot/runtime/nx_wasmfps.nx
about
nx_wasmfps.nx -- FIRST-PERSON voxel world renderer, base-relative so the SAME code runs native (base = an
mmap'd region -> PNG, eyeball-verifiable) and in WASM (base = 0 -> linear memory). Z-buffered, perspective,
distance-culled, with trees; realism directional shading. Camera has a world POSITION (you walk/look), not
orbit. JS owns trig + camera state and calls render(); wasm owns the world + the hardware-f32 math.
World params are constants (fixed world, moving camera). license_tier: ORIGINAL
dependencies 1 imports · 1 importers
imports: nx_f32_hw.nx
imported by: nx_wasmfps_gate.nx
structs
| none |
consts
| 7 | const O_MAGIC_65536: i64 = 65536 |
| 9 | const W: i64 = 200 |
| 10 | const H: i64 = 150 |
| 11 | const HW: i64 = 100 |
| 12 | const HH: i64 = 75 |
| 13 | const ZFAR: i64 = 1073741824 |
| 14 | const FOCAL: i64 = 150 |
| 15 | const WN: i64 = 96 // world is WN x WN columns |
| 16 | const WSEED: i64 = 7 |
| 17 | const WWATER: i64 = 3 |
| 18 | const WMAXH: i64 = 14 |
| 19 | const WLAT: i64 = 6 |
| 20 | const VDIST: i64 = 26 // only draw columns within this Manhattan range of the camera |
| 22 | const O_FB: i64 = 0 |
| 23 | const O_ZB: i64 = 240000 // W*H*8 |
| 24 | const O_R: i64 = 480000 |
| 25 | const O_RY: i64 = 480128 |
| 26 | const O_RX: i64 = 480256 |
| 27 | const O_V: i64 = 480384 |
| 28 | const O_RV: i64 = 480416 |
| 29 | const O_SX: i64 = 480448 |
| 30 | const O_SY: i64 = 480512 |
| 31 | const O_SD: i64 = 480576 |
| 32 | const O_SOK: i64 = 480640 |
| 33 | const O_PJ: i64 = 480704 // project out: x,y,d,ok |
| 34 | const O_DELTA: i64 = 481024 // per-column height edits, WN*WN i64 (block break/place) |
functions
| 36 | func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b } |
| 37 | func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 38 | func iabs(a: i64) -> i64 { if a < 0 { return 0 - a } return a } |
| 39 | func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) } |
| 40 | func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) } |
| 41 | func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v } called by 1: shade |
| 42 | func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) } |
| 44 | func wlat(ix: i64, iz: i64) -> i64 called by 1: terrain_h |
| 49 | func terrain_h(base: i64, gx: i64, gz: i64) -> i64 |
| 73 | func hN(base: i64, gx: i64, gz: i64) -> i64 { return terrain_h(base, gx, gz) } |
| 74 | func top_color(h: i64) -> i64 called by 1: draw_col |
| 80 | func side_color(h: i64) -> i64 called by 1: draw_col |
| 85 | func shade(lnx: i64, lny: i64, lnz: i64) -> i64 |
| 90 | func packc(col: i64, bright: i64) -> i64 called by 1: draw_face |
| 97 | func fill_z(base: i64, x0: i64, y0: i64, d0: i64, x1: i64, y1: i64, d1: i64, x2: i64, y2: i64, d2: i64, col: i64) -> i64 |
| 128 | func project(base: i64, camx: i64, camy: i64, camz: i64, iwx: i64, iwy: i64, iwz: i64) -> i64 |
| 149 | func box_corners(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64, sw: i64, sh: i64, sl: i64) -> i64 |
| 166 | func draw_face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64 |
| 180 | func draw_col(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gz: i64) -> i64 |
| 190 | func has_tree(base: i64, gx: i64, gz: i64) -> i64 |
| 199 | func draw_box(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64, sw: i64, sh: i64, sl: i64, col: i64) -> i64 |
| 208 | func draw_tree(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gz: i64) -> i64 |
| 214 | func render_at(base: i64, camx: i64, camy: i64, camz: i64, cgx: i64, cgz: i64) -> i64 |
| 236 | func build_R(base: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64 |
| 245 | func mem_bytes() -> i64 { return O_DELTA + WN * WN * 8 + 64 } called by 1: main |
| 247 | func render(camx256: i64, camy256: i64, camz256: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64 |
| 255 | func terrain_at(gx: i64, gz: i64) -> i64 { return terrain_h(0, gx, gz) } calls 1: terrain_h |
| 257 | func edit_delta(base: i64, gx: i64, gz: i64, change: i64) -> i64 |
| 266 | func break_block(gx: i64, gz: i64) -> i64 { return edit_delta(0, gx, gz, 0 - 1) } calls 1: edit_delta |
| 267 | func place_block(gx: i64, gz: i64) -> i64 { return edit_delta(0, gx, gz, 1) } calls 1: edit_delta |
| 269 | func pick(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64 calls 1: terrain_h |
| 287 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 288 | func ww() -> i64 { return W } called by 1: main |
| 289 | func hh() -> i64 { return H } called by 1: main |
| 290 | func main() -> i64 { return 0 } |