code wiki / (root) / nx_pets3d_wasm.nx

nx_pets3d_wasm.nx

buildroot/runtime/nx_pets3d_wasm.nx

43464 B910 linesdepth 3pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

EXPORTED-ENTRYPOINTS: a wasm module. Its exports are invoked by the browser host, not by any .nx call site, so the reachability census cannot see their caller. Declared so invisibly-wired entry points are bucketed rather than ratcheted as debt -- deleting one would break the live page. 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

nx_render_core.nx nx_netquant.nx nx_lerp_smooth.nx nx_pets3d_wasm.nx

imports: nx_render_core.nxnx_netquant.nxnx_lerp_smooth.nx

imported by: nobody (leaf or entry point)

structs

none

consts

13const O_MAGIC_60000: i64 = 60000
14const O_MAGIC_65536: i64 = 65536
15const O_MAGIC_16777216: i64 = 16777216
16const O_MAGIC_4096: i64 = 4096
17const O_MAGIC_80000: i64 = 80000
18const O_MAGIC_13418: i64 = 13418
19const O_MAGIC_9402: i64 = 9402
20const O_MAGIC_16000000: i64 = 16000000
21const O_MAGIC_6000: i64 = 6000
22const O_MAGIC_16384: i64 = 16384
23const O_MAGIC_8192: i64 = 8192
24const O_MAGIC_1200: i64 = 1200
25const O_MAGIC_1047: i64 = 1047
26const O_MAGIC_1320: i64 = 1320
27const O_MAGIC_12345: i64 = 12345
28const O_MAGIC_6554: i64 = 6554
29const O_MAGIC_1103515: i64 = 1103515
30const O_MAGIC_2147483647: i64 = 2147483647
32const VW: i64 = 192 // internal render res (4:3, ~2.25x sharper than the old 128x96)
33const VH: i64 = 144
34const HW: i64 = 96
35const HH: i64 = 72
36const VQ: i64 = 16384
37const GN: i64 = 24 // world is GN x GN columns
38const FBOFF: i64 = 240000 // i64 framebuffer (192*144*8 = 221184 B -> ends 461184), above the save region
39const ZBOFF: i64 = 461184 // i64 z-buffer (-> ends 682368); both inside the 16-page (1 MB) default
40const O_MVP: i64 = 1024
41const O_T: i64 = 1168
42const O_P: i64 = 1312
43const O_RY: i64 = 1456
44const O_RX: i64 = 1600
45const O_T1: i64 = 1744
46const O_V: i64 = 1888
47const O_VS: i64 = 2048
48const O_CS: i64 = 2080
49const O_TRI: i64 = 2112 // triangle scratch (15 i64 for textured verts -> ends 2232)
50const O_CORN: i64 = 2240 // 8 corners * 4 i64 = 256 -> ends 2496
51const TN: i64 = 8 // texels per face edge (UV runs 0..TN across a face)
52const O_DELTA: i64 = 2496 // GN*GN i64 per-column height edits (24*24*8=4608 -> ends 7104, < FBOFF)
53const RENDER_R: i64 = 12 // render a (2R+1)^2 window of columns AROUND the camera (infinite streaming)
54const O_CAM: i64 = 212992 // camera state in wasm: [camxq, camyq, camzq, yaw, pitch] (above the z-buffer)
55const O_KEYS: i64 = 213056 // held-key flags by keyCode 0..127 (128 i64)
56const NC: i64 = 8 // number of creatures in the world
57const O_CREAT: i64 = 214080 // NC creatures, stride 4 i64: [x, z, species, captured]
58const O_GAME: i64 = 214336 // game state: [encounter_idx (-1 none), captured_count]
59const ENC_R2: i64 = 9 // encounter radius^2 in voxels (walk within 3 of a creature)
60const O_AUDIO: i64 = 220000 // u8 PCM SFX buffer (8-bit, 128=silence) synthesized in wasm
61const ARATE: i64 = 8000 // audio sample rate
62const O_CHP: i64 = 228000 // per-creature battle HP (NC i64)
63const MAXHP: i64 = 5 // creature starting HP (weaken it to raise catch chance)
64const O_SAVE: i64 = 230000 // save record scratch (versioned, i64 fields)
65const SAVE_MAGIC: i64 = 1346458963 // "PETS" -- rejects non-Nishi saves
66const SAVE_VER: i64 = 1 // bump when the layout grows; gi_load stays forward-compatible
69const O_NET_OUT: i64 = 688128 // 64 B: local snapshot bytes (host reads -> POSTs to relay)
70const O_NET_IN: i64 = 688192 // 256 B: the WHOLE /roster body (host writes <- daemon, then gi_net_ingest_roster)
71const O_NET_F: i64 = 688448 // 10 i64 field scratch for pack/unpack
72const O_NET_CNT: i64 = 688528 // live peer count
73const O_NET_SELF: i64 = 688536 // this player's avatar tag (species/colour)
74const O_PEERS: i64 = 688576 // MAXP peers, stride 128 B -> ends 690624 (< 1 MB / 16 pages)
75const MAXP: i64 = 16
76const PEER_STRIDE: i64 = 128

functions

80func b_lat(ix: i64, iz: i64) -> i64
called by 1: b_terrain_base
87func b_terrain_base(x: i64, z: i64) -> i64
called by 1: gi_height calls 1: b_lat
107func b_delta_ptr(gx: i64, gz: i64) -> *i64 { return ((O_DELTA + (gz * GN + gx) * 8) as i64) as *i64 }
108func b_get_delta(gx: i64, gz: i64) -> i64 { let p: *i64 = b_delta_ptr(gx, gz); return p[0] }
called by 2: gi_heightgi_edit calls 1: b_delta_ptr
109func b_set_delta(gx: i64, gz: i64, v: i64) -> i64 { let p: *i64 = b_delta_ptr(gx, gz); p[0] = v; return 0 }
called by 1: gi_edit calls 1: b_delta_ptr
112func gi_height(x: i64, z: i64) -> i64
119func b_pack(r: i64, g: i64, b: i64, a: i64) -> i64 { return r + g * 256 + b * O_MAGIC_65536 + a * O_MAGIC_16777216 }
120func b_fb() -> *i64 { return (FBOFF as i64) as *i64 }
121func b_zb() -> *i64 { return (ZBOFF as i64) as *i64 }
122func b_corner_ptr(idx: i64) -> *i64 { return ((O_CORN + idx * 32) as i64) as *i64 }
124func b_project(mvp: *i64, wx: i64, wy: i64, wz: i64, scr: *i64) -> i64
called by 1: b_project_box calls 1: rc_mat4_vec4
141func b_project_box(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64) -> i64
155func b_tri(a: *i64, b: *i64, c: *i64, col: i64) -> i64
called by 1: b_quad calls 3: rc_triangleb_fbb_zb
175func b_quad(ia: i64, ib: i64, ic: i64, id: i64, col: i64) -> i64
called by 1: b_draw_box calls 2: b_trib_corner_ptr
181func b_draw_box(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, r: i64, g: i64, b: i64) -> i64
192func 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
called by 1: b_quad_tex calls 3: rc_triangle_texb_fbb_zb
215func b_quad_tex(ia: i64, ib: i64, ic: i64, id: i64, br: i64, bg: i64, bb: i64, bright: i64) -> i64
220func 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
231func 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
233func b_vn2(ax: i64, az: i64) -> i64
called by 1: b_carved calls 1: b_lat255
251func b_carved(x: i64, y: i64, z: i64) -> i64
257func b_column_has_cave(gx: i64, gz: i64, h: i64) -> i64
called by 1: b_draw_column calls 1: b_carved
263func gi_solid(x: i64, y: i64, z: i64) -> i64
271func b_draw_column(mvp: *i64, gx: i64, gz: i64, h: i64, r: i64, g: i64, b: i64) -> i64
300func b_build_mvp(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64) -> i64
331func b_creat(i: i64) -> *i64 { return ((O_CREAT + i * 32) as i64) as *i64 }
332func b_game() -> *i64 { return (O_GAME as i64) as *i64 }
333func gi_creatures() -> i64 { return NC }
334func gi_creature_x(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[0] }
calls 1: b_creat
335func gi_creature_z(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[1] }
calls 1: b_creat
336func gi_creature_species(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[2] }
calls 1: b_creat
337func gi_creature_captured(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[3] }
calls 1: b_creat
338func gi_captured() -> i64 { let g: *i64 = b_game(); return g[1] }
calls 1: b_game
339func 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] }
calls 2: b_gameb_creat
340func gi_throws() -> i64 { let g: *i64 = b_game(); return g[3] }
calls 1: b_game
341func gi_last() -> i64 { let g: *i64 = b_game(); return g[5] }
calls 1: b_game
342func gi_won() -> i64 { let g: *i64 = b_game(); if g[1] >= NC { return 1 } return 0 }
calls 1: b_game
343func b_chp(i: i64) -> i64 { let p: *i64 = ((O_CHP + i * 8) as i64) as *i64; return p[0] }
344func b_chp_set(i: i64, v: i64) -> i64 { let p: *i64 = ((O_CHP + i * 8) as i64) as *i64; p[0] = v; return 0 }
345func gi_enc_hp() -> i64 { let g: *i64 = b_game(); if g[0] < 0 { return 0 - 1 } return b_chp(g[0]) }
calls 2: b_gameb_chp
346func b_creature_color(sp: i64) -> i64
calls 1: b_pack
353func b_marker(sx: i64, sy: i64, depth: i64, col: i64) -> i64
calls 2: b_fbb_zb
374func b_draw_creatures(mvp: *i64) -> i64
401func gi_biome(gx: i64, gz: i64) -> i64
409func gi_has_tree(gx: i64, gz: i64) -> i64
called by 1: gi_render calls 2: gi_heightgi_biome
420func b_draw_tree(mvp: *i64, gx: i64, gz: i64, h: i64) -> i64
called by 1: gi_render calls 1: b_draw_box_tex
426func b_peer(i: i64) -> *i64 { return ((O_PEERS + i * PEER_STRIDE) as i64) as *i64 }
428func b_draw_peers(mvp: *i64) -> i64
456func gi_net_smooth() -> i64
called by 1: gi_tick calls 2: b_peerls_advance
466func gi_render(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64) -> i64
501func gi_ssao() -> i64
called by 1: gi_tick calls 2: b_fbb_zb
533func gi_hud() -> i64
547func gi_want_save() -> i64 { let g: *i64 = b_game(); let s: i64 = g[9]; g[9] = 0; return s }
calls 1: b_game
548func gi_w() -> i64 { return VW }
549func gi_h() -> i64 { return VH }
550func gi_fb_offset() -> i64 { return FBOFF }
551func gi_world() -> i64 { return GN }
555func gi_edit(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64, mode: i64) -> i64
584func b_cam() -> *i64 { return (O_CAM as i64) as *i64 }
585func b_keys() -> *i64 { return (O_KEYS as i64) as *i64 }
called by 2: b_keygi_key
586func b_key(code: i64) -> i64 { if code < 0 { return 0 } if code > 127 { return 0 } let k: *i64 = b_keys(); return k[code] }
called by 1: gi_tick calls 1: b_keys
588func b_audio() -> *u8 { return (O_AUDIO as i64) as *u8 }
called by 1: b_tone
589func gi_audio_offset() -> i64 { return O_AUDIO }
590func gi_audio_rate() -> i64 { return ARATE }
592func b_tone(start: i64, len: i64, freq: i64, amp0: i64) -> i64
called by 1: gi_synth calls 1: b_audio
609func gi_synth(id: i64) -> i64
calls 1: b_tone
621func gi_take_sfx() -> i64 { let g: *i64 = b_game(); let s: i64 = g[7]; g[7] = 0 - 1; return s }
calls 1: b_game
623func gi_init() -> i64
657func gi_save_offset() -> i64 { return O_SAVE }
658func b_sv() -> *i64 { return (O_SAVE as i64) as *i64 }
called by 2: gi_savegi_load
660func gi_save() -> i64
682func b_svget(sv: *i64, k: i64, n: i64, deflt: i64) -> i64 { if k < n { return sv[k] } return deflt }
called by 1: gi_load
686func gi_load(bytelen: i64) -> i64
709func gi_key(code: i64, down: i64) -> i64
calls 1: b_keys
717func gi_click(button: i64) -> i64
730func gi_tick() -> i64
813func gi_net_out_ptr() -> i64 { return O_NET_OUT } // host reads packed snapshot bytes here -> POST
814func gi_net_in_ptr() -> i64 { return O_NET_IN } // host writes a peer's bytes here <- roster, then ingest
815func gi_net_set_self(sp: i64) -> i64 { let p: *i64 = (O_NET_SELF as i64) as *i64; p[0] = sp; return 0 }
816func gi_net_count() -> i64 { let p: *i64 = (O_NET_CNT as i64) as *i64; return p[0] }
818func gi_net_snapshot() -> i64
839func gi_net_clear() -> i64
calls 1: b_peer
846func b_peer_clamp(slot: i64) -> i64
called by 1: b_ingest_frame_at calls 2: b_peerb_cam
861func b_ingest_frame_at(slot: i64, src: *u8) -> i64
881func 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 }
885func gi_net_ingest_roster(total: i64) -> i64
904func gi_peer_x(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[1] }
calls 1: b_peer
905func gi_peer_y(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[2] }
calls 1: b_peer
906func gi_peer_z(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[3] }
calls 1: b_peer
907func gi_peer_yaw(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[4] }
calls 1: b_peer
908func gi_peer_species(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[6] }
calls 1: b_peer
910func main() -> i64 { return 0 }