nx_wasm_mineworld.nx
buildroot/runtime/nx_wasm_mineworld.nx
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
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
| 12 | const PI2_MAGIC_4096: i64 = 4096 |
| 13 | const PI2_MAGIC_374761393: i64 = 374761393 |
| 14 | const PI2_MAGIC_668265263: i64 = 668265263 |
| 15 | const PI2_MAGIC_1442695041: i64 = 1442695041 |
| 16 | const PI2_MAGIC_1274126177: i64 = 1274126177 |
| 17 | const PI2_MAGIC_65536: i64 = 65536 |
| 18 | const PI2_MAGIC_2246822519: i64 = 2246822519 |
| 19 | const PI2_MAGIC_16777216: i64 = 16777216 |
| 20 | const PI2_MAGIC_2654435761: i64 = 2654435761 |
| 21 | const PI2_MAGIC_3900: i64 = 3900 |
| 22 | const PI2_MAGIC_9999: i64 = 9999 |
| 23 | const PI2_MAGIC_5734: i64 = 5734 |
| 25 | const W: i64 = 256 |
| 26 | const H: i64 = 192 |
| 27 | const HW: i64 = 128 |
| 28 | const HH: i64 = 96 |
| 29 | const ZFAR: i64 = 1073741824 |
| 30 | const FOCAL: i64 = 200 |
| 31 | const YMAX: i64 = 28 |
| 32 | const WSEED: i64 = 7 |
| 33 | const WWATER: i64 = 4 |
| 34 | const VDIST: i64 = 18 |
| 35 | const WWIN: i64 = 40 |
| 36 | const BIAS: i64 = 1048576 |
| 37 | const EBIAS: i64 = 67108864 |
| 38 | const ECAP: i64 = 4096 |
| 39 | const PI4096: i64 = 12868 // pi in 4096-scale radians (integer trig -- NO JS Math on the game path) |
| 40 | const PI2_4096: i64 = 6434 |
| 41 | const FOG0: i64 = 12 // fog starts (blocks); full at FOG0+8 -> the horizon fades into sky |
| 43 | const O_FB: i64 = 0 |
| 44 | const O_ZB: i64 = 393216 // W*H*8 (256x192) |
| 45 | const O_R: i64 = 786432 |
| 46 | const O_RY: i64 = 786560 |
| 47 | const O_RX: i64 = 786688 |
| 48 | const O_V: i64 = 786816 |
| 49 | const O_RV: i64 = 786848 |
| 50 | const O_SX: i64 = 786880 |
| 51 | const O_SY: i64 = 786944 |
| 52 | const O_SD: i64 = 787008 |
| 53 | const O_SOK: i64 = 787072 |
| 54 | const O_PJ: i64 = 787136 |
| 55 | const O_HCORG: i64 = 787200 // sliding-window origin: [0]=orgx [1]=orgz [2]=valid |
| 56 | const O_HC: i64 = 787224 // height cache, WWIN*WWIN i64 (40x40 covers VDIST 18 + neighbors) |
| 57 | const O_HB: i64 = 800024 // biome cache, WWIN*WWIN i64 |
| 58 | const O_HT: i64 = 812824 // tree-presence cache, WWIN*WWIN i64 (trees are SOLID blocks now) |
| 59 | const O_EDIT: i64 = 825624 // sparse edit table: ECAP * (key,val) i64 pairs |
| 60 | const O_ECNT: i64 = 891160 // live edit count |
| 62 | const MAXPEERS: i64 = 8 |
| 63 | const O_PEERS: i64 = 891224 // MAXPEERS x {active,x256,y256,z256,yaw1000} i64 |
| 64 | const O_NETF: i64 = 891544 // ps_pack/ps_unpack scratch fields f[10] |
| 65 | const O_NETOUT: i64 = 891624 // packed self frame (28B) -- JS memcpy's this to the /pstate POST body |
| 66 | const O_NETIN: i64 = 891656 // roster body in ([len:1][frame] records) -- JS memcpy's /roster here |
| 68 | const 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 |
| 69 | const MW_SENS: i64 = 13 // default mouse gain (rad*4096 per pixel); the client owns it as data (c[11]) |
| 74 | const O_BLK: i64 = 895848 // MAXBLK * 4 i64 block records (starts right after O_CAM's 96 bytes) |
| 75 | const O_STAT: i64 = 896872 // [0] = terrain pixels DRAWN this frame (ground truth for gates; reset per render) |
| 76 | const MAXBLK: i64 = 32 |
| 77 | const ST_PLAIN: i64 = 0 |
| 78 | const ST_GRASS: i64 = 1 |
| 79 | const ST_STONE: i64 = 2 |
| 80 | const ST_WOOD: i64 = 3 |
| 81 | const ST_LEAF: i64 = 4 |
| 82 | const ST_WATER: i64 = 5 |
| 83 | const ST_ORE: i64 = 6 // stone body (side color) with mineral flecks (top color) -- the harvested ores |
| 85 | const K_GRASS: i64 = 1 |
| 86 | const K_DIRT: i64 = 2 |
| 87 | const K_STONE: i64 = 3 |
| 88 | const K_SAND: i64 = 4 |
| 89 | const K_SNOW: i64 = 5 |
| 90 | const K_ROCK: i64 = 6 |
| 91 | const K_WATER: i64 = 7 |
| 92 | const K_WOOD: i64 = 8 |
| 93 | const K_LEAF: i64 = 9 |
| 94 | const K_PLANK: i64 = 10 |
| 97 | const K_COBBLE: i64 = 11 |
| 98 | const K_COAL: i64 = 12 |
| 99 | const K_IRON: i64 = 13 |
| 100 | const K_GOLD: i64 = 14 |
| 101 | const K_EMER: i64 = 15 |
| 102 | const K_DARKWOOD: i64 = 16 |
functions
| 104 | func imin(a: i64, b: i64) -> i64 { if a < b { return a } return b } |
| 105 | func imax(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 106 | func min3(a: i64, b: i64, c: i64) -> i64 { return imin(a, imin(b, c)) } |
| 107 | func max3(a: i64, b: i64, c: i64) -> i64 { return imax(a, imax(b, c)) } |
| 108 | func clamp255(v: i64) -> i64 { if v < 0 { return 0 } if v > 255 { return 255 } return v } called by 1: shade |
| 109 | func fratio(num: i64, den: i64) -> i64 { return f32_div(f32_of(num), f32_of(den)) } |
| 111 | func mw_fd256(v: i64) -> i64 { var q: i64 = v / 256; if v < 0 { if q * 256 != v { q = q - 1 } } return q } |
| 114 | func mw_sin4096(x0: i64) -> i64 |
| 126 | func mw_cos4096(x: i64) -> i64 { return mw_sin4096(x + PI2_4096) } |
| 129 | func mw_h2(ix: i64, iz: i64, s: i64) -> i64 |
| 139 | func mw_o2(bx: i64, bz: i64, lat: i64, s: i64) -> i64 |
| 153 | func biome_of(gx: i64, gz: i64) -> i64 |
| 161 | func terrain_h0(gx: i64, gz: i64) -> i64 |
| 175 | func mw_h3(ix: i64, iy: i64, iz: i64, s: i64) -> i64 |
| 184 | func cave3(gx: i64, gy: i64, gz: i64) -> i64 |
| 213 | func mw_key(gx: i64, gy: i64, gz: i64) -> i64 { return ((gx + EBIAS) << 33) | ((gz + EBIAS) << 6) | gy } |
| 214 | func mw_ehash(k: i64) -> i64 |
| 222 | func mw_eget(base: i64, gx: i64, gy: i64, gz: i64) -> i64 |
| 237 | func mw_eset(base: i64, gx: i64, gy: i64, gz: i64, v: i64) -> i64 |
| 262 | func solid_h(base: i64, gx: i64, gy: i64, gz: i64, hcol: i64) -> i64 |
| 277 | func col_pack(base: i64, gx: i64, gz: i64) -> i64 |
| 295 | func kind_c(base: i64, gx: i64, gy: i64, gz: i64) -> i64 |
| 350 | func solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64 { if kind_c(base, gx, gy, gz) != 0 { return 1 } return 0 } |
| 352 | func phys_solid(base: i64, gx: i64, gy: i64, gz: i64) -> i64 |
| 359 | func floor_y(base: i64, gx: i64, gz: i64, start_gy: i64) -> i64 |
| 368 | func rgb(r: i64, g: i64, b: i64) -> i64 { return r + g * 256 + b * PI2_MAGIC_65536 } |
| 370 | func blk_ptr(base: i64) -> *i64 { return (base + O_BLK) as *i64 } |
| 371 | func blk_set(base: i64, id: i64, top: i64, side: i64, style: i64) -> i64 |
| 379 | func pack_default_at(base: i64) -> i64 |
| 403 | func ensure_pack(base: i64) -> i64 { let b: *i64 = blk_ptr(base); if b[0] == 0 { pack_default_at(base) } return 0 } |
| 405 | func tbr(v: i64) -> i64 { if v > 255 { return 255 } if v < 0 { return 0 } return v } called by 1: tex |
| 409 | func tex(base: i64, kind: i64, fk: i64, tu: i64, tv: i64) -> i64 |
| 445 | func shade(lnx: i64, lny: i64, lnz: i64) -> i64 |
| 450 | func packc(col: i64, bright: i64) -> i64 |
| 456 | 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 |
| 507 | func 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 |
| 571 | func project(base: i64, camx: i64, camy: i64, camz: i64, iwx: i64, iwy: i64, iwz: i64) -> i64 |
| 591 | func corners(base: i64, camx: i64, camy: i64, camz: i64, x0: i64, y0: i64, z0: i64) -> i64 |
| 605 | func face(base: i64, a: i64, b: i64, c: i64, dd: i64, lnx: i64, lny: i64, lnz: i64, col: i64) -> i64 |
| 621 | func ao3(s1: i64, s2: i64, sc: i64) -> i64 called by 1: draw_voxel |
| 628 | func 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 |
| 646 | func draw_voxel(base: i64, camx: i64, camy: i64, camz: i64, gx: i64, gy: i64, gz: i64, kind: i64) -> i64 |
| 730 | func has_tree(gx: i64, gz: i64, h: i64, bio: i64) -> i64 |
| 742 | func render_at(base: i64, camx: i64, camy: i64, camz: i64, cgx: i64, cgz: i64) -> i64 |
| 847 | func build_R(base: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64 |
| 862 | func mem_bytes() -> i64 { return O_STAT + 64 + 64 } |
| 863 | func drawn_px_at(base: i64) -> i64 { let s: *i64 = (base + O_STAT) as *i64; return s[0] } |
| 864 | func drawn_px() -> i64 { return drawn_px_at(0) } calls 1: drawn_px_at |
| 868 | func cam_ptr(base: i64) -> *i64 { return (base + O_CAM) as *i64 } |
| 869 | func start_at(base: i64) -> i64 |
| 885 | func tick_at(base: i64, keys: i64, mdx: i64, mdy: i64) -> i64 |
| 963 | func aim_at(base: i64, out: *i64) -> i64 |
| 974 | func dig_at(base: i64) -> i64 |
| 983 | func put_at(base: i64) -> i64 |
| 992 | func render_cam_at(base: i64) -> i64 |
| 1001 | func net_push_at(base: i64) -> i64 |
| 1006 | func peer_ptr(base: i64, i: i64) -> *i64 { return (base + O_PEERS + i * 40) as *i64 } |
| 1007 | func peers_clear_at(base: i64) -> i64 |
| 1012 | func peer_set_at(base: i64, i: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64) -> i64 |
| 1020 | func projectp(base: i64, camx: i64, camy: i64, camz: i64, wx256: i64, wy256: i64, wz256: i64) -> i64 |
| 1040 | func corners_p(base: i64, camx: i64, camy: i64, camz: i64, x256: i64, y256: i64, z256: i64, w256: i64, h256: i64, l256: i64) -> i64 |
| 1054 | func 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 |
| 1063 | func peer_body_col(idx: i64) -> i64 called by 1: draw_peer |
| 1071 | func draw_peer(base: i64, camx: i64, camy: i64, camz: i64, x256: i64, y256: i64, z256: i64, idx: i64) -> i64 |
| 1078 | func net_pack_self_at(base: i64, x256: i64, y256: i64, z256: i64, yaw1000: i64, pitch1000: i64) -> i64 |
| 1086 | func net_ingest_roster_at(base: i64, total0: i64) -> i64 |
| 1111 | func surface_y(base: i64, gx: i64, gz: i64) -> i64 |
| 1120 | func raycast(base: i64, camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64, out: *i64) -> i64 |
| 1146 | func render(camx256: i64, camy256: i64, camz256: i64, ycos: i64, ysin: i64, pcos: i64, psin: i64) -> i64 |
| 1154 | func terrain_at(gx: i64, gz: i64) -> i64 { return surface_y(0, gx, gz) } calls 1: surface_y |
| 1156 | func break_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64 |
| 1163 | func place_at(camx256: i64, camy256: i64, camz256: i64, dx1000: i64, dy1000: i64, dz1000: i64) -> i64 |
| 1169 | func edit_count_at(base: i64) -> i64 { let c: *i64 = (base + O_ECNT) as *i64; return c[0] } |
| 1170 | func edit_count() -> i64 { return edit_count_at(0) } calls 1: edit_count_at |
| 1172 | func peers_clear() -> i64 { return peers_clear_at(0) } calls 1: peers_clear_at |
| 1173 | func 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 |
| 1174 | func 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) } calls 1: net_pack_self_at |
| 1175 | func net_ingest_roster(total: i64) -> i64 { return net_ingest_roster_at(0, total) } calls 1: net_ingest_roster_at |
| 1176 | func net_out_off() -> i64 { return O_NETOUT } |
| 1177 | func net_in_off() -> i64 { return O_NETIN } called by 1: main |
| 1179 | func start() -> i64 { return start_at(0) } calls 1: start_at |
| 1180 | func tick(keys: i64, mdx: i64, mdy: i64) -> i64 { return tick_at(0, keys, mdx, mdy) } calls 1: tick_at |
| 1181 | func render_cam() -> i64 { return render_cam_at(0) } calls 1: render_cam_at |
| 1182 | func dig() -> i64 { return dig_at(0) } calls 1: dig_at |
| 1183 | func put() -> i64 { return put_at(0) } calls 1: put_at |
| 1184 | func net_push() -> i64 { return net_push_at(0) } calls 1: net_push_at |
| 1186 | func invert_state() -> i64 { let c: *i64 = cam_ptr(0); return c[9] * 10 + c[10] } calls 1: cam_ptr |
| 1189 | func pack_reset() -> i64 { return pack_default_at(0) } calls 1: pack_default_at |
| 1190 | func pack_block(id: i64, top: i64, side: i64, style: i64) -> i64 { ensure_pack(0); return blk_set(0, id, top, side, style) } |
| 1191 | func fb_off() -> i64 { return O_FB } |
| 1192 | func ww() -> i64 { return W } |
| 1193 | func hh() -> i64 { return H } |
| 1194 | func main() -> i64 { return 0 } |