code wiki / (root) / nx_wasmfps.nx

nx_wasmfps.nx

buildroot/runtime/nx_wasmfps.nx

12386 B290 linesdepth 1pulls 1 transitivereach 1 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_f32_hw.nx nx_wasmfps.nx nx_wasmfps_gate.nx

imports: nx_f32_hw.nx

imported by: nx_wasmfps_gate.nx

structs

none

consts

7const O_MAGIC_65536: i64 = 65536
9const W: i64 = 200
10const H: i64 = 150
11const HW: i64 = 100
12const HH: i64 = 75
13const ZFAR: i64 = 1073741824
14const FOCAL: i64 = 150
15const WN: i64 = 96 // world is WN x WN columns
16const WSEED: i64 = 7
17const WWATER: i64 = 3
18const WMAXH: i64 = 14
19const WLAT: i64 = 6
20const VDIST: i64 = 26 // only draw columns within this Manhattan range of the camera
22const O_FB: i64 = 0
23const O_ZB: i64 = 240000 // W*H*8
24const O_R: i64 = 480000
25const O_RY: i64 = 480128
26const O_RX: i64 = 480256
27const O_V: i64 = 480384
28const O_RV: i64 = 480416
29const O_SX: i64 = 480448
30const O_SY: i64 = 480512
31const O_SD: i64 = 480576
32const O_SOK: i64 = 480640
33const O_PJ: i64 = 480704 // project out: x,y,d,ok
34const O_DELTA: i64 = 481024 // per-column height edits, WN*WN i64 (block break/place)

functions

36func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 2: min3fill_z
37func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 2: max3fill_z
38func iabs(a: i64) -> i64 { if a < 0 { return 0 - a } return a }
39func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) }
called by 1: fill_z calls 1: imin
40func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) }
called by 1: fill_z calls 1: imax
41func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v }
called by 1: shade
42func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) }
called by 1: build_R calls 2: f32_divf32_of
44func wlat(ix: i64, iz: i64) -> i64
called by 1: terrain_h
49func terrain_h(base: i64, gx: i64, gz: i64) -> i64
73func hN(base: i64, gx: i64, gz: i64) -> i64 { return terrain_h(base, gx, gz) }
called by 1: draw_col calls 1: terrain_h
74func top_color(h: i64) -> i64
called by 1: draw_col
80func side_color(h: i64) -> i64
called by 1: draw_col
85func shade(lnx: i64, lny: i64, lnz: i64) -> i64
called by 1: draw_face calls 1: clamp255
90func packc(col: i64, bright: i64) -> i64
called by 1: draw_face
97func 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
called by 1: draw_face calls 4: imaxmin3iminmax3
128func project(base: i64, camx: i64, camy: i64, camz: i64, iwx: i64, iwy: i64, iwz: i64) -> i64
149func box_corners(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64, sw: i64, sh: i64, sl: i64) -> i64
called by 2: draw_coldraw_box calls 1: project
166func draw_face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64
called by 2: draw_coldraw_box calls 3: packcshadefill_z
180func draw_col(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gz: i64) -> i64
190func has_tree(base: i64, gx: i64, gz: i64) -> i64
called by 1: render_at calls 1: terrain_h
199func 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
called by 1: draw_tree calls 2: box_cornersdraw_face
208func draw_tree(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gz: i64) -> i64
called by 1: render_at calls 2: terrain_hdraw_box
214func render_at(base: i64, camx: i64, camy: i64, camz: i64, cgx: i64, cgz: i64) -> i64
236func build_R(base: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64
245func mem_bytes() -> i64 { return O_DELTA + WN * WN * 8 + 64 }
called by 1: main
247func render(camx256: i64, camy256: i64, camz256: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64
255func terrain_at(gx: i64, gz: i64) -> i64 { return terrain_h(0, gx, gz) }
calls 1: terrain_h
257func edit_delta(base: i64, gx: i64, gz: i64, change: i64) -> i64
266func break_block(gx: i64, gz: i64) -> i64 { return edit_delta(0, gx, gz, 0 - 1) }
calls 1: edit_delta
267func place_block(gx: i64, gz: i64) -> i64 { return edit_delta(0, gx, gz, 1) }
calls 1: edit_delta
269func pick(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
calls 1: terrain_h
287func fb_off() -> i64 { return O_FB }
called by 1: main
288func ww() -> i64 { return W }
called by 1: main
289func hh() -> i64 { return H }
called by 1: main
290func main() -> i64 { return 0 }