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 librarytopic 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 }
105func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
106func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) }
107func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) }
108func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v }
109func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) }
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
153func biome_of(gx: i64, gz: i64) -> i64
161func terrain_h0(gx: i64, gz: i64) -> i64
175func mw_h3(ix: i64, iy: i64, iz: i64, s: i64) -> i64
184func cave3(gx: i64, gy: i64, gz: i64) -> i64
213func mw_key(gx: i64, gy: i64, gz: i64) -> i64 { return ((gx + EBIAS) << 33) | ((gz + EBIAS) << 6) | gy }
214func mw_ehash(k: i64) -> i64
222func mw_eget(base: i64, gx: i64, gy: i64, gz: i64) -> i64
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
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 }
352func phys_solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64
359func floor_y(base: i64, gx: i64, gz: i64, start_gy: i64) -> i64
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 }
409func tex(base: i64, kind: i64, fk: i64, tu: i64, tv: i64) -> i64
445func shade(lnx: i64, lny: i64, lnz: i64) -> i64
450func packc(col: i64, bright: i64) -> i64
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
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
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
605func face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64
621func ao3(s1: i64, s2: i64, sc: i64) -> i64
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
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) }
868func cam_ptr(base: i64) -> *i64 { return (base + O_CAM) as *i64 }
869func start_at(base: i64) -> i64
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
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
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
1063func peer_body_col(idx: i64) -> i64
1071func draw_peer(base: i64, camx: i64, camy: i64, camz: i64, x256: i64, y256: i64, z256: i64, idx: i64) -> i64
1078func net_pack_self_at(base: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64, pitch1000: i64) -> i64
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) }
1156func break_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
1163func place_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64
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) }
1172func peers_clear() -> i64 { return peers_clear_at(0) }
1173func peer_set(i: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64) -> i64 { return peer_set_at(0, i, x256, y256, z256, yaw1000) }
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 }
1179func start() -> i64 { return start_at(0) }
1180func tick(keys: i64, mdx: i64, mdy: i64) -> i64 { return tick_at(0, keys, mdx, mdy) }
1181func render_cam() -> i64 { return render_cam_at(0) }
1182func dig() -> i64 { return dig_at(0) }
1183func put() -> i64 { return put_at(0) }
1184func net_push() -> i64 { return net_push_at(0) }
1186func invert_state() -> i64 { let c: *i64 = cam_ptr(0); return c[9] * 10 + c[10] }
1189func pack_reset() -> i64 { return pack_default_at(0) }
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 }