code wiki / (root) / nx_pets3d_wasm.nx

nx_pets3d_wasm.nx

buildroot/runtime/nx_pets3d_wasm.nx

43168 B907 linesdepth 2pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

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

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

functions

77func b_lat(ix: i64, iz: i64) -> i64
called by 1: b_terrain_base
84func b_terrain_base(x: i64, z: i64) -> i64
called by 1: gi_height calls 1: b_lat
104func b_delta_ptr(gx: i64, gz: i64) -> *i64 { return ((O_DELTA + (gz * GN + gx) * 8) as i64) as *i64 }
105func 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
106func 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
109func gi_height(x: i64, z: i64) -> i64
116func b_pack(r: i64, g: i64, b: i64, a: i64) -> i64 { return r + g * 256 + b * O_MAGIC_65536 + a * O_MAGIC_16777216 }
117func b_fb() -> *i64 { return (FBOFF as i64) as *i64 }
118func b_zb() -> *i64 { return (ZBOFF as i64) as *i64 }
119func b_corner_ptr(idx: i64) -> *i64 { return ((O_CORN + idx * 32) as i64) as *i64 }
121func b_project(mvp: *i64, wx: i64, wy: i64, wz: i64, scr: *i64) -> i64
called by 1: b_project_box calls 1: rc_mat4_vec4
138func b_project_box(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64) -> i64
152func b_tri(a: *i64, b: *i64, c: *i64, col: i64) -> i64
called by 1: b_quad calls 3: rc_triangleb_fbb_zb
172func 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
178func b_draw_box(mvp: *i64, x0: i64, y0: i64, z0: i64, hx: i64, hy: i64, hz: i64, r: i64, g: i64, b: i64) -> i64
189func 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
212func b_quad_tex(ia: i64, ib: i64, ic: i64, id: i64, br: i64, bg: i64, bb: i64, bright: i64) -> i64
217func 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
228func 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
230func b_vn2(ax: i64, az: i64) -> i64
called by 1: b_carved calls 1: b_lat255
248func b_carved(x: i64, y: i64, z: i64) -> i64
254func b_column_has_cave(gx: i64, gz: i64, h: i64) -> i64
called by 1: b_draw_column calls 1: b_carved
260func gi_solid(x: i64, y: i64, z: i64) -> i64
268func b_draw_column(mvp: *i64, gx: i64, gz: i64, h: i64, r: i64, g: i64, b: i64) -> i64
297func b_build_mvp(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64) -> i64
328func b_creat(i: i64) -> *i64 { return ((O_CREAT + i * 32) as i64) as *i64 }
329func b_game() -> *i64 { return (O_GAME as i64) as *i64 }
330func gi_creatures() -> i64 { return NC }
331func gi_creature_x(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[0] }
calls 1: b_creat
332func gi_creature_z(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[1] }
calls 1: b_creat
333func gi_creature_species(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[2] }
calls 1: b_creat
334func gi_creature_captured(i: i64) -> i64 { let p: *i64 = b_creat(i); return p[3] }
calls 1: b_creat
335func gi_captured() -> i64 { let g: *i64 = b_game(); return g[1] }
calls 1: b_game
336func 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
337func gi_throws() -> i64 { let g: *i64 = b_game(); return g[3] }
calls 1: b_game
338func gi_last() -> i64 { let g: *i64 = b_game(); return g[5] }
calls 1: b_game
339func gi_won() -> i64 { let g: *i64 = b_game(); if g[1] >= NC { return 1 } return 0 }
calls 1: b_game
340func b_chp(i: i64) -> i64 { let p: *i64 = ((O_CHP + i * 8) as i64) as *i64; return p[0] }
341func b_chp_set(i: i64, v: i64) -> i64 { let p: *i64 = ((O_CHP + i * 8) as i64) as *i64; p[0] = v; return 0 }
342func 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
343func b_creature_color(sp: i64) -> i64
calls 1: b_pack
350func b_marker(sx: i64, sy: i64, depth: i64, col: i64) -> i64
calls 2: b_fbb_zb
371func b_draw_creatures(mvp: *i64) -> i64
398func gi_biome(gx: i64, gz: i64) -> i64
406func gi_has_tree(gx: i64, gz: i64) -> i64
called by 1: gi_render calls 2: gi_heightgi_biome
417func b_draw_tree(mvp: *i64, gx: i64, gz: i64, h: i64) -> i64
called by 1: gi_render calls 1: b_draw_box_tex
423func b_peer(i: i64) -> *i64 { return ((O_PEERS + i * PEER_STRIDE) as i64) as *i64 }
425func b_draw_peers(mvp: *i64) -> i64
453func gi_net_smooth() -> i64
called by 1: gi_tick calls 2: b_peerls_advance
463func gi_render(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64) -> i64
498func gi_ssao() -> i64
called by 1: gi_tick calls 2: b_fbb_zb
530func gi_hud() -> i64
544func gi_want_save() -> i64 { let g: *i64 = b_game(); let s: i64 = g[9]; g[9] = 0; return s }
calls 1: b_game
545func gi_w() -> i64 { return VW }
546func gi_h() -> i64 { return VH }
547func gi_fb_offset() -> i64 { return FBOFF }
548func gi_world() -> i64 { return GN }
552func gi_edit(camxq: i64, camyq: i64, camzq: i64, yaw: i64, pitch: i64, mode: i64) -> i64
581func b_cam() -> *i64 { return (O_CAM as i64) as *i64 }
582func b_keys() -> *i64 { return (O_KEYS as i64) as *i64 }
called by 2: b_keygi_key
583func 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
585func b_audio() -> *u8 { return (O_AUDIO as i64) as *u8 }
called by 1: b_tone
586func gi_audio_offset() -> i64 { return O_AUDIO }
587func gi_audio_rate() -> i64 { return ARATE }
589func b_tone(start: i64, len: i64, freq: i64, amp0: i64) -> i64
called by 1: gi_synth calls 1: b_audio
606func gi_synth(id: i64) -> i64
calls 1: b_tone
618func gi_take_sfx() -> i64 { let g: *i64 = b_game(); let s: i64 = g[7]; g[7] = 0 - 1; return s }
calls 1: b_game
620func gi_init() -> i64
654func gi_save_offset() -> i64 { return O_SAVE }
655func b_sv() -> *i64 { return (O_SAVE as i64) as *i64 }
called by 2: gi_savegi_load
657func gi_save() -> i64
679func b_svget(sv: *i64, k: i64, n: i64, deflt: i64) -> i64 { if k < n { return sv[k] } return deflt }
called by 1: gi_load
683func gi_load(bytelen: i64) -> i64
706func gi_key(code: i64, down: i64) -> i64
calls 1: b_keys
714func gi_click(button: i64) -> i64
727func gi_tick() -> i64
810func gi_net_out_ptr() -> i64 { return O_NET_OUT } // host reads packed snapshot bytes here -> POST
811func gi_net_in_ptr() -> i64 { return O_NET_IN } // host writes a peer's bytes here <- roster, then ingest
812func gi_net_set_self(sp: i64) -> i64 { let p: *i64 = (O_NET_SELF as i64) as *i64; p[0] = sp; return 0 }
813func gi_net_count() -> i64 { let p: *i64 = (O_NET_CNT as i64) as *i64; return p[0] }
815func gi_net_snapshot() -> i64
836func gi_net_clear() -> i64
calls 1: b_peer
843func b_peer_clamp(slot: i64) -> i64
called by 1: b_ingest_frame_at calls 2: b_peerb_cam
858func b_ingest_frame_at(slot: i64, src: *u8) -> i64
878func 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 }
882func gi_net_ingest_roster(total: i64) -> i64
901func gi_peer_x(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[1] }
calls 1: b_peer
902func gi_peer_y(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[2] }
calls 1: b_peer
903func gi_peer_z(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[3] }
calls 1: b_peer
904func gi_peer_yaw(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[4] }
calls 1: b_peer
905func gi_peer_species(i: i64) -> i64 { let s: *i64 = b_peer(i); return s[6] }
calls 1: b_peer
907func main() -> i64 { return 0 }