code wiki / _hdl_build / nx_voxchunk.nx

nx_voxchunk.nx

buildroot/runtime/_hdl_build/nx_voxchunk.nx

11657 B313 linesdepth 3pulls 4 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_voxchunk.nx -- the SOVEREIGN CHUNKED VOXEL WORLD PART. nx_gamebench gap-queue rank 1 (voxel-world-chunked, PARTIAL): the craft organ's world is a FIXED 64x32x64 volume -- honest evidence for rendering and editing, but NOT for the Minecraft-class bar the capability names: an unbounded world streamed through a BOUNDED resident set of chunks. This part is that bar, built on the certified parts (persistence = nx_gamesave, so a dirty chunk survives eviction with atomicity/corruption-refusal/additive-only inherited, not re-derived). THE INVARIANTS THIS PART EXISTS TO HOLD (each a gate tooth in nx_voxchunk_gate): 1. DETERMINISTIC GENERATION. A virgin chunk is a pure function of (world_seed, cx, cz): load -> evict -> reload is bit-identical. No stored world is needed for unvisited land. 2. BOUNDED RESIDENCY BY CONSTRUCTION. At most `cap` chunks are ever resident; walking 10,000 chunks costs the same memory as walking 10. The eviction is the design, not an afterthought. 3. EDITS SURVIVE EVICTION. A modified (dirty) chunk is flushed through gs_save before its slot is reused, and reload prefers the saved file over regeneration -- the Minecraft law: virgin land from the seed, touched land from disk. Losing edits on eviction is the classic chunk-corruption bug class; here it is structurally impossible while the flush path holds. 4. SEAM-CONSISTENT WORLD ACCESS. Callers address blocks in WORLD coordinates; chunk math is internal. A query at a chunk border resolves identically whether the neighbour is resident, evicted, or never visited. 5. WHOLE-SESSION DURABILITY. The session arena is flat i64 words -> gs_save; dirty state is flushed first, so a saved world reopens exactly where it left off. Chunk geometry: 16 x 32 x 16 blocks (8192 bytes), packed 8 blocks/word in the arena tail. license_tier: ORIGINAL expect_exit: 0

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_gamesave.nx nx_voxchunk.nx nx_voxchunk_gate.nx

imports: nx_syscalls.nxnx_gamesave.nx

imported by: nx_voxchunk_gate.nx

structs

none

consts

27const VXC_MAGIC_374761393: i64 = 374761393
28const VXC_MAGIC_668265263: i64 = 668265263
29const VXC_MAGIC_2246822519: i64 = 2246822519
30const VXC_MAGIC_1274126177: i64 = 1274126177
31const VXC_MAGIC_60630: i64 = 60630
32const VXC_MAGIC_1785430000: i64 = 1785430000
33const VXC_MAGIC_52711: i64 = 52711
34const VXC_MAGIC_8191: i64 = 8191
36const VXC_CW: i64 = 16
37const VXC_CH: i64 = 32
38const VXC_CD: i64 = 16
39const VXC_CBYTES: i64 = 8192
40const VXC_CWORDS: i64 = 1024
41const VXC_HDR: i64 = 8
42const VXC_SLOTW: i64 = 4
43const VXC_SEA: i64 = 12
46const VXC_S_EMPTY: i64 = 0
47const VXC_S_CLEAN: i64 = 1
48const VXC_S_DIRTY: i64 = 2
51const VXC_E_RANGE: i64 = 0-1
52const VXC_E_FLUSH: i64 = 0-2

functions

55func vxc_cap(a: *i64) -> i64 { return a[0] }
56func vxc_seed(a: *i64) -> i64 { return a[1] }
called by 1: vxc_ensure
57func vxc_resident(a: *i64) -> i64 { return a[3] }
called by 1: main
58func vxc_loads(a: *i64) -> i64 { return a[4] }
59func vxc_evictions(a: *i64) -> i64 { return a[5] }
called by 1: main
60func vxc_flushes(a: *i64) -> i64 { return a[6] }
called by 1: main
61func vxc_diskloads(a: *i64) -> i64 { return a[7] }
called by 1: main
63func vxc_words(cap: i64) -> i64 { return VXC_HDR + cap*VXC_SLOTW + cap*VXC_CWORDS }
called by 2: vxc_bytesmain
64func vxc_bytes(cap: i64) -> i64 { return vxc_words(cap) * 8 }
calls 1: vxc_words
65func vxc_o_slot(a: *i64, s: i64) -> i64 { return VXC_HDR + s*VXC_SLOTW }
67func vxc_blocks(a: *i64, s: i64) -> *u8
71func vxc_init(a: *i64, cap: i64, seed: i64) -> i64
called by 1: main calls 1: vxc_o_slot
94func vxc_hash(x: i64, z: i64, seed: i64) -> i64
called by 2: vxc_heightvxc_gen
102func vxc_height(wx: i64, wz: i64, seed: i64) -> i64
called by 2: vxc_genmain calls 1: vxc_hash
116func vxc_gen(blocks: *u8, cx: i64, cz: i64, seed: i64) -> i64
called by 1: vxc_ensure calls 2: vxc_heightvxc_hash
143func vxc_itoa_at(p: *u8, at: i64, v: i64) -> i64
called by 1: vxc_path calls 1: sys_mmap
155func vxc_path(p: *u8, cx: i64, cz: i64) -> i64
166func vxc_flush_slot(a: *i64, s: i64) -> i64
176func vxc_disk_load(a: *i64, s: i64, cx: i64, cz: i64) -> i64
186func vxc_find(a: *i64, cx: i64, cz: i64) -> i64
called by 1: vxc_ensure calls 2: vxc_capvxc_o_slot
198func vxc_victim(a: *i64) -> i64
219func vxc_ensure(a: *i64, cx: i64, cz: i64) -> i64
242func vxc_cdiv(v: i64, d: i64) -> i64
called by 2: vxc_getvxc_set
247func vxc_get(a: *i64, wx: i64, wy: i64, wz: i64) -> i64
259func vxc_set(a: *i64, wx: i64, wy: i64, wz: i64, b: i64) -> i64
277func vxc_flush_all(a: *i64) -> i64
294func vxc_checksum(a: *i64) -> i64
called by 1: main calls 3: vxc_capvxc_o_slotvxc_blocks