nx_pets3d_wasm.nx
buildroot/runtime/nx_pets3d_wasm.nx
about
nx_pets3d_wasm.nx -- KEYSTONE sub-rung B4: a REAL orbitable voxel TERRAIN in-browser wasm (not a toy
cube). Composes the HAL-free nx_render_core to render a 12x12 procedural voxel world: per-column
height, height-coloured (water/grass/rock/snow), directional face light, solid columns drawn as boxes,
z-buffered. gi_render(frame) orbits the camera around the world centre on a 16-step ring (the native
renderer's proven turntable framing), so JS can drive it from input -> interactive. NO syscalls: i64
packed-u32-RGBA fb + zb at fixed offsets; sovereign Q14 sin/cos angle table (no JS trig). license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_render_core.nxnx_netquant.nxnx_lerp_smooth.nx
imported by: nobody (leaf or entry point)
structs
| none |
consts
| 10 | const O_MAGIC_60000: i64 = 60000 |
| 11 | const O_MAGIC_65536: i64 = 65536 |
| 12 | const O_MAGIC_16777216: i64 = 16777216 |
| 13 | const O_MAGIC_4096: i64 = 4096 |
| 14 | const O_MAGIC_80000: i64 = 80000 |
| 15 | const O_MAGIC_13418: i64 = 13418 |
| 16 | const O_MAGIC_9402: i64 = 9402 |
| 17 | const O_MAGIC_16000000: i64 = 16000000 |
| 18 | const O_MAGIC_6000: i64 = 6000 |
| 19 | const O_MAGIC_16384: i64 = 16384 |
| 20 | const O_MAGIC_8192: i64 = 8192 |
| 21 | const O_MAGIC_1200: i64 = 1200 |
| 22 | const O_MAGIC_1047: i64 = 1047 |
| 23 | const O_MAGIC_1320: i64 = 1320 |
| 24 | const O_MAGIC_12345: i64 = 12345 |
| 25 | const O_MAGIC_6554: i64 = 6554 |
| 26 | const O_MAGIC_1103515: i64 = 1103515 |
| 27 | const O_MAGIC_2147483647: i64 = 2147483647 |
| 29 | const VW: i64 = 192 // internal render res (4:3, ~2.25x sharper than the old 128x96) |
| 30 | const VH: i64 = 144 |
| 31 | const HW: i64 = 96 |
| 32 | const HH: i64 = 72 |
| 33 | const VQ: i64 = 16384 |
| 34 | const GN: i64 = 24 // world is GN x GN columns |
| 35 | const FBOFF: i64 = 240000 // i64 framebuffer (192*144*8 = 221184 B -> ends 461184), above the save region |
| 36 | const ZBOFF: i64 = 461184 // i64 z-buffer (-> ends 682368); both inside the 16-page (1 MB) default |
| 37 | const O_MVP: i64 = 1024 |
| 38 | const O_T: i64 = 1168 |
| 39 | const O_P: i64 = 1312 |
| 40 | const O_RY: i64 = 1456 |
| 41 | const O_RX: i64 = 1600 |
| 42 | const O_T1: i64 = 1744 |
| 43 | const O_V: i64 = 1888 |
| 44 | const O_VS: i64 = 2048 |
| 45 | const O_CS: i64 = 2080 |
| 46 | const O_TRI: i64 = 2112 // triangle scratch (15 i64 for textured verts -> ends 2232) |
| 47 | const O_CORN: i64 = 2240 // 8 corners * 4 i64 = 256 -> ends 2496 |
| 48 | const TN: i64 = 8 // texels per face edge (UV runs 0..TN across a face) |
| 49 | const O_DELTA: i64 = 2496 // GN*GN i64 per-column height edits (24*24*8=4608 -> ends 7104, < FBOFF) |
| 50 | const RENDER_R: i64 = 12 // render a (2R+1)^2 window of columns AROUND the camera (infinite streaming) |
| 51 | const O_CAM: i64 = 212992 // camera state in wasm: [camxq, camyq, camzq, yaw, pitch] (above the z-buffer) |
| 52 | const O_KEYS: i64 = 213056 // held-key flags by keyCode 0..127 (128 i64) |
| 53 | const NC: i64 = 8 // number of creatures in the world |
| 54 | const O_CREAT: i64 = 214080 // NC creatures, stride 4 i64: [x, z, species, captured] |
| 55 | const O_GAME: i64 = 214336 // game state: [encounter_idx (-1 none), captured_count] |
| 56 | const ENC_R2: i64 = 9 // encounter radius^2 in voxels (walk within 3 of a creature) |
| 57 | const O_AUDIO: i64 = 220000 // u8 PCM SFX buffer (8-bit, 128=silence) synthesized in wasm |
| 58 | const ARATE: i64 = 8000 // audio sample rate |
| 59 | const O_CHP: i64 = 228000 // per-creature battle HP (NC i64) |
| 60 | const MAXHP: i64 = 5 // creature starting HP (weaken it to raise catch chance) |
| 61 | const O_SAVE: i64 = 230000 // save record scratch (versioned, i64 fields) |
| 62 | const SAVE_MAGIC: i64 = 1346458963 // "PETS" -- rejects non-Nishi saves |
| 63 | const SAVE_VER: i64 = 1 // bump when the layout grows; gi_load stays forward-compatible |
| 66 | const O_NET_OUT: i64 = 688128 // 64 B: local snapshot bytes (host reads -> POSTs to relay) |
| 67 | const O_NET_IN: i64 = 688192 // 256 B: the WHOLE /roster body (host writes <- daemon, then gi_net_ingest_roster) |
| 68 | const O_NET_F: i64 = 688448 // 10 i64 field scratch for pack/unpack |
| 69 | const O_NET_CNT: i64 = 688528 // live peer count |
| 70 | const O_NET_SELF: i64 = 688536 // this player's avatar tag (species/colour) |
| 71 | const O_PEERS: i64 = 688576 // MAXP peers, stride 128 B -> ends 690624 (< 1 MB / 16 pages) |
| 72 | const MAXP: i64 = 16 |
| 73 | const PEER_STRIDE: i64 = 128 |
functions
| 77 | func b_lat(ix: i64, iz: i64) -> i64 called by 1: b_terrain_base |
| 84 | func b_terrain_base(x: i64, z: i64) -> i64 |
| 104 | func b_delta_ptr(gx: i64, gz: i64) -> *i64 { return ((O_DELTA + (gz * GN + gx) * 8) as i64) as *i64 } |
| 105 | func b_get_delta(gx: i64, gz: i64) -> i64 { let p: *i64 = b_delta_ptr(gx, gz); return p[0] } |
| 106 | func b_set_delta(gx: i64, gz: i64, v: i64) -> i64 { let p: *i64 = b_delta_ptr(gx, gz); p[0] = v; return 0 } |
| 109 | func gi_height(x: i64, z: i64) -> i64 called by 6: gi_solidb_draw_columnb_draw_creaturesgi_has_treegi_rendergi_edit calls 2: b_terrain_baseb_get_delta |
| 116 | func b_pack(r: i64, g: i64, b: i64, a: i64) -> i64 { return r + g * 256 + b * O_MAGIC_65536 + a * O_MAGIC_16777216 } |
| 117 | func b_fb() -> *i64 { return (FBOFF as i64) as *i64 } |
| 118 | func b_zb() -> *i64 { return (ZBOFF as i64) as *i64 } |
| 119 | func b_corner_ptr(idx: i64) -> *i64 { return ((O_CORN + idx * 32) as i64) as *i64 } |
| 121 | func b_project(mvp: *i64, wx: i64, wy: i64, wz: i64, scr: *i64) -> i64 |
| 138 | func b_project_box(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64) -> i64 |
| 152 | func b_tri(a: *i64, b: *i64, c: *i64, col: i64) -> i64 |
| 172 | func b_quad(ia: i64, ib: i64, ic: i64, id: i64, col: i64) -> i64 |
| 178 | func b_draw_box(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, r: i64, g: i64, b: i64) -> i64 |
| 189 | func b_tri_tex(a: *i64, b: *i64, c: *i64, ua: i64, va: i64, ub: i64, vb: i64, uc: i64, vc: i64, br: i64, bg: i64, bb: i64, bright: i64) -> i64 |
| 212 | func b_quad_tex(ia: i64, ib: i64, ic: i64, id: i64, br: i64, bg: i64, bb: i64, bright: i64) -> i64 |
| 217 | func b_draw_box_tex(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, r: i64, g: i64, b: i64) -> i64 |
| 228 | func b_lat255(ix: i64, iz: i64) -> i64 { var n: i64 = (ix * 73 + iz * 179 + ix * iz * 13) % 256; if n < 0 { n = n + 256 } return n } called by 1: b_vn2 |
| 230 | func b_vn2(ax: i64, az: i64) -> i64 |
| 248 | func b_carved(x: i64, y: i64, z: i64) -> i64 |
| 254 | func b_column_has_cave(gx: i64, gz: i64, h: i64) -> i64 |
| 260 | func gi_solid(x: i64, y: i64, z: i64) -> i64 |
| 268 | func b_draw_column(mvp: *i64, gx: i64, gz: i64, h: i64, r: i64, g: i64, b: i64) -> i64 called by 1: gi_render calls 6: b_column_has_caveb_carvedb_draw_box_texb_project_boxb_quad_texgi_height |
| 297 | func b_build_mvp(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64) -> i64 called by 1: gi_render calls 6: rc_translation_4x4rc_cos_q14rc_sin_q14rc_identity_4x4rc_mat4_mulrc_perspective_cs |
| 328 | func b_creat(i: i64) -> *i64 { return ((O_CREAT + i * 32) as i64) as *i64 } |
| 329 | func b_game() -> *i64 { return (O_GAME as i64) as *i64 } |
| 330 | func gi_creatures() -> i64 { return NC } |
| 331 | func gi_creature_x(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[0] } calls 1: b_creat |
| 332 | func gi_creature_z(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[1] } calls 1: b_creat |
| 333 | func gi_creature_species(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[2] } calls 1: b_creat |
| 334 | func gi_creature_captured(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[3] } calls 1: b_creat |
| 335 | func gi_captured() -> i64 { let g: *i64 = b_game(); return g[1] } calls 1: b_game |
| 336 | func gi_encounter() -> i64 { let g: *i64 = b_game(); if g[0] < 0 { return 0 - 1 } let p: *i64 = b_creat(g[0]); return p[2] } |
| 337 | func gi_throws() -> i64 { let g: *i64 = b_game(); return g[3] } calls 1: b_game |
| 338 | func gi_last() -> i64 { let g: *i64 = b_game(); return g[5] } calls 1: b_game |
| 339 | func gi_won() -> i64 { let g: *i64 = b_game(); if g[1] >= NC { return 1 } return 0 } calls 1: b_game |
| 340 | func b_chp(i: i64) -> i64 { let p: *i64 = ((O_CHP + i * 8) as i64) as *i64; return p[0] } |
| 341 | func b_chp_set(i: i64, v: i64) -> i64 { let p: *i64 = ((O_CHP + i * 8) as i64) as *i64; p[0] = v; return 0 } |
| 342 | func gi_enc_hp() -> i64 { let g: *i64 = b_game(); if g[0] < 0 { return 0 - 1 } return b_chp(g[0]) } |
| 343 | func b_creature_color(sp: i64) -> i64 calls 1: b_pack |
| 350 | func b_marker(sx: i64, sy: i64, depth: i64, col: i64) -> i64 |
| 371 | func b_draw_creatures(mvp: *i64) -> i64 |
| 398 | func gi_biome(gx: i64, gz: i64) -> i64 |
| 406 | func gi_has_tree(gx: i64, gz: i64) -> i64 |
| 417 | func b_draw_tree(mvp: *i64, gx: i64, gz: i64, h: i64) -> i64 |
| 423 | func b_peer(i: i64) -> *i64 { return ((O_PEERS + i * PEER_STRIDE) as i64) as *i64 } |
| 425 | func b_draw_peers(mvp: *i64) -> i64 |
| 453 | func gi_net_smooth() -> i64 |
| 463 | func gi_render(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64) -> i64 |
| 498 | func gi_ssao() -> i64 |
| 530 | func gi_hud() -> i64 |
| 544 | func gi_want_save() -> i64 { let g: *i64 = b_game(); let s: i64 = g[9]; g[9] = 0; return s } calls 1: b_game |
| 545 | func gi_w() -> i64 { return VW } |
| 546 | func gi_h() -> i64 { return VH } |
| 547 | func gi_fb_offset() -> i64 { return FBOFF } |
| 548 | func gi_world() -> i64 { return GN } |
| 552 | func gi_edit(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64, mode: i64) -> i64 |
| 581 | func b_cam() -> *i64 { return (O_CAM as i64) as *i64 } |
| 582 | func b_keys() -> *i64 { return (O_KEYS as i64) as *i64 } |
| 583 | func b_key(code: i64) -> i64 { if code < 0 { return 0 } if code > 127 { return 0 } let k: *i64 = b_keys(); return k[code] } |
| 585 | func b_audio() -> *u8 { return (O_AUDIO as i64) as *u8 } called by 1: b_tone |
| 586 | func gi_audio_offset() -> i64 { return O_AUDIO } |
| 587 | func gi_audio_rate() -> i64 { return ARATE } |
| 589 | func b_tone(start: i64, len: i64, freq: i64, amp0: i64) -> i64 |
| 606 | func gi_synth(id: i64) -> i64 calls 1: b_tone |
| 618 | func gi_take_sfx() -> i64 { let g: *i64 = b_game(); let s: i64 = g[7]; g[7] = 0 - 1; return s } calls 1: b_game |
| 620 | func gi_init() -> i64 |
| 654 | func gi_save_offset() -> i64 { return O_SAVE } |
| 655 | func b_sv() -> *i64 { return (O_SAVE as i64) as *i64 } |
| 657 | func gi_save() -> i64 |
| 679 | func b_svget(sv: *i64, k: i64, n: i64, deflt: i64) -> i64 { if k < n { return sv[k] } return deflt } called by 1: gi_load |
| 683 | func gi_load(bytelen: i64) -> i64 |
| 706 | func gi_key(code: i64, down: i64) -> i64 calls 1: b_keys |
| 714 | func gi_click(button: i64) -> i64 |
| 727 | func gi_tick() -> i64 |
| 810 | func gi_net_out_ptr() -> i64 { return O_NET_OUT } // host reads packed snapshot bytes here -> POST |
| 811 | func gi_net_in_ptr() -> i64 { return O_NET_IN } // host writes a peer's bytes here <- roster, then ingest |
| 812 | func gi_net_set_self(sp: i64) -> i64 { let p: *i64 = (O_NET_SELF as i64) as *i64; p[0] = sp; return 0 } |
| 813 | func gi_net_count() -> i64 { let p: *i64 = (O_NET_CNT as i64) as *i64; return p[0] } |
| 815 | func gi_net_snapshot() -> i64 |
| 836 | func gi_net_clear() -> i64 calls 1: b_peer |
| 843 | func b_peer_clamp(slot: i64) -> i64 |
| 858 | func b_ingest_frame_at(slot: i64, src: *u8) -> i64 |
| 878 | func gi_net_ingest(len: i64) -> i64 { let r: i64 = b_ingest_frame_at(0, (O_NET_IN as i64) as *u8); let cnt: *i64 = (O_NET_CNT as i64) as *i64; cnt[0] = 1; return r } calls 1: b_ingest_frame_at |
| 882 | func gi_net_ingest_roster(total: i64) -> i64 |
| 901 | func gi_peer_x(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[1] } calls 1: b_peer |
| 902 | func gi_peer_y(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[2] } calls 1: b_peer |
| 903 | func gi_peer_z(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[3] } calls 1: b_peer |
| 904 | func gi_peer_yaw(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[4] } calls 1: b_peer |
| 905 | func gi_peer_species(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[6] } calls 1: b_peer |
| 907 | func main() -> i64 { return 0 } |