code wiki / (root) / nx_wasm_mineworld.nx

nx_wasm_mineworld.nx

buildroot/runtime/nx_wasm_mineworld.nx

56246 B1194 linesdepth 1pulls 2 transitivereach 7 importersview sourcekind tooltopic wasm
docsdependenciesstructsconstsfunctions

about

nx_wasm_mineworld.nx -- MINECRAFT-LEVEL PROC GEN: an INFINITE deterministic voxel world (the noise function IS the world -- no fixed array). Multi-octave integer value-noise terrain + CONTINUOUS biome blend (plains/ forest/desert/snow: colors, tree density, hill amplitude -- amplitude blended so biome borders have no cliff), 3D-noise CAVES with unbreakable bedrock at y=0, water, trees. World state = a SLIDING 32x32 height/biome cache window around the camera (refreshed per frame; terrain is a pure fn of (x,z,seed) so roaming is unbounded) + a SPARSE GLOBAL EDIT TABLE (open-address hash, global coords) so dig/place edits PERSIST when you roam away and return (the fixed 48x48 grid of nx_wasmvox3d could not leave its box). Same base-relative pattern + export surface as nx_wasmvox3d (render/terrain_at/break_at/place_at/ww/hh/fb_off) -> same JS shim contract. Scoped 192x144 / VDIST 14 for software-raster speed (the proven envelope). license_tier: ORIGINAL

dependencies 2 imports · 7 importers

nx_f32_hw.nx nx_pets_netstate.nx nx_wasm_mineworld.nx nx_mineworld_autotest.nx nx_mineworld_wasm_vet.nx nx_mw_spawn_probe.nx nx_wasm_mineworld_gate.nx nx_wasm_mineworld_mod_gate.nx nx_wasm_mineworld_mp_gate.nx nx_wasm_mineworld_tick_gate.nx

imports: nx_f32_hw.nxnx_pets_netstate.nx

imported by: nx_mineworld_autotest.nxnx_mineworld_wasm_vet.nxnx_mw_spawn_probe.nxnx_wasm_mineworld_gate.nxnx_wasm_mineworld_mod_gate.nxnx_wasm_mineworld_mp_gate.nxnx_wasm_mineworld_tick_gate.nx

structs

none

consts

12const PI2_MAGIC_4096: i64 = 4096
13const PI2_MAGIC_374761393: i64 = 374761393
14const PI2_MAGIC_668265263: i64 = 668265263
15const PI2_MAGIC_1442695041: i64 = 1442695041
16const PI2_MAGIC_1274126177: i64 = 1274126177
17const PI2_MAGIC_65536: i64 = 65536
18const PI2_MAGIC_2246822519: i64 = 2246822519
19const PI2_MAGIC_16777216: i64 = 16777216
20const PI2_MAGIC_2654435761: i64 = 2654435761
21const PI2_MAGIC_3900: i64 = 3900
22const PI2_MAGIC_9999: i64 = 9999
23const PI2_MAGIC_5734: i64 = 5734
25const W: i64 = 256
26const H: i64 = 192
27const HW: i64 = 128
28const HH: i64 = 96
29const ZFAR: i64 = 1073741824
30const FOCAL: i64 = 200
31const YMAX: i64 = 28
32const WSEED: i64 = 7
33const WWATER: i64 = 4
34const VDIST: i64 = 18
35const WWIN: i64 = 40
36const BIAS: i64 = 1048576
37const EBIAS: i64 = 67108864
38const ECAP: i64 = 4096
39const PI4096: i64 = 12868 // pi in 4096-scale radians (integer trig -- NO JS Math on the game path)
40const PI2_4096: i64 = 6434
41const FOG0: i64 = 12 // fog starts (blocks); full at FOG0+8 -> the horizon fades into sky
43const O_FB: i64 = 0
44const O_ZB: i64 = 393216 // W*H*8 (256x192)
45const O_R: i64 = 786432
46const O_RY: i64 = 786560
47const O_RX: i64 = 786688
48const O_V: i64 = 786816
49const O_RV: i64 = 786848
50const O_SX: i64 = 786880
51const O_SY: i64 = 786944
52const O_SD: i64 = 787008
53const O_SOK: i64 = 787072
54const O_PJ: i64 = 787136
55const O_HCORG: i64 = 787200 // sliding-window origin: [0]=orgx [1]=orgz [2]=valid
56const O_HC: i64 = 787224 // height cache, WWIN*WWIN i64 (40x40 covers VDIST 18 + neighbors)
57const O_HB: i64 = 800024 // biome cache, WWIN*WWIN i64
58const O_HT: i64 = 812824 // tree-presence cache, WWIN*WWIN i64 (trees are SOLID blocks now)
59const O_EDIT: i64 = 825624 // sparse edit table: ECAP * (key,val) i64 pairs
60const O_ECNT: i64 = 891160 // live edit count
62const MAXPEERS: i64 = 8
63const O_PEERS: i64 = 891224 // MAXPEERS x {active,x256,y256,z256,yaw1000} i64
64const O_NETF: i64 = 891544 // ps_pack/ps_unpack scratch fields f[10]
65const O_NETOUT: i64 = 891624 // packed self frame (28B) -- JS memcpy's this to the /pstate POST body
66const O_NETIN: i64 = 891656 // roster body in ([len:1][frame] records) -- JS memcpy's /roster here
68const O_CAM: i64 = 895752 // [0]x256 [1]y256(eye) [2]z256 [3]yaw4096rad [4]pitch4096rad [5]vy256 [6]fly [7]onground [8]prevkeys [9]invY [10]invX [11]sens
69const MW_SENS: i64 = 13 // default mouse gain (rad*4096 per pixel); the client owns it as data (c[11])
74const O_BLK: i64 = 895848 // MAXBLK * 4 i64 block records (starts right after O_CAM's 96 bytes)
75const O_STAT: i64 = 896872 // [0] = terrain pixels DRAWN this frame (ground truth for gates; reset per render)
76const MAXBLK: i64 = 32
77const ST_PLAIN: i64 = 0
78const ST_GRASS: i64 = 1
79const ST_STONE: i64 = 2
80const ST_WOOD: i64 = 3
81const ST_LEAF: i64 = 4
82const ST_WATER: i64 = 5
83const ST_ORE: i64 = 6 // stone body (side color) with mineral flecks (top color) -- the harvested ores
85const K_GRASS: i64 = 1
86const K_DIRT: i64 = 2
87const K_STONE: i64 = 3
88const K_SAND: i64 = 4
89const K_SNOW: i64 = 5
90const K_ROCK: i64 = 6
91const K_WATER: i64 = 7
92const K_WOOD: i64 = 8
93const K_LEAF: i64 = 9
94const K_PLANK: i64 = 10
97const K_COBBLE: i64 = 11
98const K_COAL: i64 = 12
99const K_IRON: i64 = 13
100const K_GOLD: i64 = 14
101const K_EMER: i64 = 15
102const K_DARKWOOD: i64 = 16

functions

104func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 3: min3fill_zfill_zt
105func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 3: max3fill_zfill_zt
106func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) }
called by 2: fill_zfill_zt calls 1: imin
107func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) }
called by 2: fill_zfill_zt calls 1: imax
108func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v }
called by 1: shade
109func 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
111func mw_fd256(v: i64) -> i64 { var q: i64 = v / 256; if v < 0 { if q * 256 != v { q = q - 1 } } return q }
114func mw_sin4096(x0: i64) -> i64
126func mw_cos4096(x: i64) -> i64 { return mw_sin4096(x + PI2_4096) }
129func mw_h2(ix: i64, iz: i64, s: i64) -> i64
139func mw_o2(bx: i64, bz: i64, lat: i64, s: i64) -> i64
called by 3: biome_ofterrain_h0render_at calls 1: mw_h2
153func biome_of(gx: i64, gz: i64) -> i64
called by 4: maincol_packrender_atmain calls 1: mw_o2
161func terrain_h0(gx: i64, gz: i64) -> i64
175func mw_h3(ix: i64, iy: i64, iz: i64, s: i64) -> i64
called by 2: cave3kind_c
184func cave3(gx: i64, gy: i64, gz: i64) -> i64
called by 3: mainsolid_hkind_c calls 1: mw_h3
213func mw_key(gx: i64, gy: i64, gz: i64) -> i64 { return ((gx + EBIAS) << 33) | ((gz + EBIAS) << 6) | gy }
called by 3: mainmw_egetmw_eset
214func mw_ehash(k: i64) -> i64
called by 3: mainmw_egetmw_eset
222func mw_eget(base: i64, gx: i64, gy: i64, gz: i64) -> i64
called by 2: solid_hkind_c calls 2: mw_keymw_ehash
237func mw_eset(base: i64, gx: i64, gy: i64, gz: i64, v: i64) -> i64
262func solid_h(base: i64, gx: i64, gy: i64, gz: i64, hcol: i64) -> i64
called by 1: main calls 3: mw_egetterrain_h0cave3
277func col_pack(base: i64, gx: i64, gz: i64) -> i64
295func kind_c(base: i64, gx: i64, gy: i64, gz: i64) -> i64
350func solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64 { if kind_c(base, gx, gy, gz) != 0 { return 1 } return 0 }
called by 3: draw_voxelraycastmain calls 1: kind_c
352func phys_solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64
called by 3: floor_ytick_atmain calls 1: kind_c
359func floor_y(base: i64, gx: i64, gz: i64, start_gy: i64) -> i64
called by 2: tick_atmain calls 1: phys_solid
368func rgb(r: i64, g: i64, b: i64) -> i64 { return r + g * 256 + b * PI2_MAGIC_65536 }
370func blk_ptr(base: i64) -> *i64 { return (base + O_BLK) as *i64 }
371func blk_set(base: i64, id: i64, top: i64, side: i64, style: i64) -> i64
379func pack_default_at(base: i64) -> i64
403func ensure_pack(base: i64) -> i64 { let b: *i64 = blk_ptr(base); if b[0] == 0 { pack_default_at(base) } return 0 }
405func tbr(v: i64) -> i64 { if v > 255 { return 255 } if v < 0 { return 0 } return v }
called by 1: tex
409func tex(base: i64, kind: i64, fk: i64, tu: i64, tv: i64) -> i64
called by 2: fill_ztmain calls 5: blk_ptrrgbmw_h2packctbr
445func shade(lnx: i64, lny: i64, lnz: i64) -> i64
called by 2: faceface_t calls 1: clamp255
450func packc(col: i64, bright: i64) -> i64
called by 3: texfill_ztface
456func 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: face calls 4: imaxmin3iminmax3
507func fill_zt(base: i64, x0: i64, y0: i64, d0: i64, uv0: i64, x1: i64, y1: i64, d1: i64, uv1: i64, x2: i64, y2: i64, d2: i64, uv2: i64, kind: i64, fk: i64, bright: i64) -> i64
called by 2: mainface_t calls 6: imaxmin3iminmax3packctex
571func project(base: i64, camx: i64, camy: i64, camz: i64, iwx: i64, iwy: i64, iwz: i64) -> i64
591func corners(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64) -> i64
called by 1: draw_voxel calls 1: project
605func face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64
called by 1: draw_boxp calls 3: packcshadefill_z
621func ao3(s1: i64, s2: i64, sc: i64) -> i64
called by 1: draw_voxel
628func face_t(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, kind: i64, fk: i64, vbr: i64, la: i64, lb: i64, lc: i64, ld: i64) -> i64
called by 1: draw_voxel calls 2: shadefill_zt
646func draw_voxel(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gy: i64, gz: i64, kind: i64) -> i64
730func has_tree(gx: i64, gz: i64, h: i64, bio: i64) -> i64
742func render_at(base: i64, camx: i64, camy: i64, camz: i64, cgx: i64, cgz: i64) -> i64
847func build_R(base: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64
862func mem_bytes() -> i64 { return O_STAT + 64 + 64 }
863func drawn_px_at(base: i64) -> i64 { let s: *i64 = (base + O_STAT) as *i64; return s[0] }
864func drawn_px() -> i64 { return drawn_px_at(0) }
calls 1: drawn_px_at
868func cam_ptr(base: i64) -> *i64 { return (base + O_CAM) as *i64 }
869func start_at(base: i64) -> i64
called by 3: mainstartmain calls 2: cam_ptrsurface_y
885func tick_at(base: i64, keys: i64, mdx: i64, mdy: i64) -> i64
963func aim_at(base: i64, out: *i64) -> i64
974func dig_at(base: i64) -> i64
983func put_at(base: i64) -> i64
called by 2: putmain calls 4: cam_ptraim_atraycastmw_eset
992func render_cam_at(base: i64) -> i64
1001func net_push_at(base: i64) -> i64
1006func peer_ptr(base: i64, i: i64) -> *i64 { return (base + O_PEERS + i * 40) as *i64 }
1007func peers_clear_at(base: i64) -> i64
1012func peer_set_at(base: i64, i: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64) -> i64
1020func projectp(base: i64, camx: i64, camy: i64, camz: i64, wx256: i64, wy256: i64, wz256: i64) -> i64
1040func corners_p(base: i64, camx: i64, camy: i64, camz: i64, x256: i64, y256: i64, z256: i64, w256: i64, h256: i64, l256: i64) -> i64
called by 1: draw_boxp calls 1: projectp
1054func draw_boxp(base: i64, camx: i64, camy: i64, camz: i64, x256: i64, y256: i64, z256: i64, w256: i64, h256: i64, l256: i64, col: i64) -> i64
called by 1: draw_peer calls 2: corners_pface
1063func peer_body_col(idx: i64) -> i64
called by 1: draw_peer
1071func draw_peer(base: i64, camx: i64, camy: i64, camz: i64, x256: i64, y256: i64, z256: i64, idx: i64) -> i64
called by 1: render_at calls 2: draw_boxppeer_body_col
1078func net_pack_self_at(base: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64, pitch1000: i64) -> i64
called by 2: net_push_atnet_pack_self calls 1: ps_pack
1086func net_ingest_roster_at(base: i64, total0: i64) -> i64
1111func surface_y(base: i64, gx: i64, gz: i64) -> i64
1120func raycast(base: i64, camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64, out: *i64) -> i64
1146func render(camx256: i64, camy256: i64, camz256: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64
1154func terrain_at(gx: i64, gz: i64) -> i64 { return surface_y(0, gx, gz) }
calls 1: surface_y
1156func break_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
calls 2: raycastmw_eset
1163func place_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
calls 2: raycastmw_eset
1169func edit_count_at(base: i64) -> i64 { let c: *i64 = (base + O_ECNT) as *i64; return c[0] }
1170func edit_count() -> i64 { return edit_count_at(0) }
calls 1: edit_count_at
1172func peers_clear() -> i64 { return peers_clear_at(0) }
calls 1: peers_clear_at
1173func peer_set(i: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64) -> i64 { return peer_set_at(0, i, x256, y256, z256, yaw1000) }
calls 1: peer_set_at
1174func net_pack_self(x256: i64, y256: i64, z256: i64, yaw1000: i64, pitch1000: i64) -> i64 { return net_pack_self_at(0, x256, y256, z256, yaw1000, pitch1000) }
1175func net_ingest_roster(total: i64) -> i64 { return net_ingest_roster_at(0, total) }
1176func net_out_off() -> i64 { return O_NETOUT }
1177func net_in_off() -> i64 { return O_NETIN }
called by 1: main
1179func start() -> i64 { return start_at(0) }
calls 1: start_at
1180func tick(keys: i64, mdx: i64, mdy: i64) -> i64 { return tick_at(0, keys, mdx, mdy) }
calls 1: tick_at
1181func render_cam() -> i64 { return render_cam_at(0) }
calls 1: render_cam_at
1182func dig() -> i64 { return dig_at(0) }
calls 1: dig_at
1183func put() -> i64 { return put_at(0) }
calls 1: put_at
1184func net_push() -> i64 { return net_push_at(0) }
calls 1: net_push_at
1186func invert_state() -> i64 { let c: *i64 = cam_ptr(0); return c[9] * 10 + c[10] }
calls 1: cam_ptr
1189func pack_reset() -> i64 { return pack_default_at(0) }
calls 1: pack_default_at
1190func pack_block(id: i64, top: i64, side: i64, style: i64) -> i64 { ensure_pack(0); return blk_set(0, id, top, side, style) }
1191func fb_off() -> i64 { return O_FB }
1192func ww() -> i64 { return W }
1193func hh() -> i64 { return H }
1194func main() -> i64 { return 0 }