read the save's chunk blocks, and check the rock below the surface
A chunk's solid blocks are a palette of block ids, raw or zstd, and a zstd frame of bit planes; a layer of a lone 0 is all air. With them, vsmv verify compares the rock of every stored block below the surface with the strata laid against our own heights, which predate the dry seabed raise: 99.91% of 1.38 billion blocks match. Lava basalt near the bottom, the granite of cave walls and structures, and columns whose height differs explain all but 0.0011%, nearly all of that in one area at the explored edge whose layer boundaries are not explained yet. What the save has instead of stratum rock is tallied too, as the ground truth the deposits phase can be checked against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
89
src/save.sex
89
src/save.sex
@@ -7,7 +7,7 @@
|
||||
;;; data itself, matched against the map sizes in TerraGenConfig.
|
||||
|
||||
(pub include sqlite3.h)
|
||||
(include stdio.h stdlib.h string.h)
|
||||
(include stdio.h stdlib.h string.h zstd.h)
|
||||
(import pb)
|
||||
(import maps)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
(pub define REGION-SIZE 512)
|
||||
(pub define CHUNK-SIZE 32)
|
||||
(pub define CHUNK-AREA 1024)
|
||||
(pub define CHUNK-VOLUME 32768)
|
||||
(pub define MAX-STORIES 32)
|
||||
|
||||
(pub record chunk-maps
|
||||
@@ -443,6 +444,92 @@
|
||||
(sqlite3-finalize stmt)
|
||||
(return found))
|
||||
|
||||
;;; Chunks ------------------------------------------------------------
|
||||
|
||||
;;; A zstd frame, whole, into a fresh buffer; NULL if it isn't one.
|
||||
(fn unzstd ((p (* const u8)) (len size-t) (out-len (* size-t))) (* u8)
|
||||
(var size u64 (ZSTD-getFrameContentSize p len))
|
||||
(if (>= size ZSTD-CONTENTSIZE-ERROR)
|
||||
(return NULL))
|
||||
(var out (* u8) (malloc (+ size 1)))
|
||||
(var got size-t (ZSTD-decompress out size p len))
|
||||
(if (ZSTD-isError got)
|
||||
(do (free out) (return NULL)))
|
||||
(= (* out-len) got)
|
||||
(return out))
|
||||
|
||||
;;; A chunk's block layer: an int32, then the palette of block ids,
|
||||
;;; raw in -n bytes if it is negative and zstd in n if not; then a zstd
|
||||
;;; frame of bit planes, 4096 bytes each, plane k holding bit k of each
|
||||
;;; block's palette index, block i at bit i % 8 of byte i / 8. A layer
|
||||
;;; of 0 alone holds no blocks: all air.
|
||||
(fn read-blocks ((p (* const u8)) (len size-t) (out (* i32))) bool
|
||||
(if (< len 4)
|
||||
(return false))
|
||||
(var n i32 (cast (c-bit-or [p 0] (<< [p 1] 8) (<< [p 2] 16) (<< (cast [p 3] u32) 24)) i32))
|
||||
(if (&& (== n 0) (== len 4))
|
||||
(do
|
||||
(memset out 0 (* CHUNK-VOLUME (sizeof i32)))
|
||||
(return true)))
|
||||
(var palette (* u8) NULL)
|
||||
(var palette-len size-t 0)
|
||||
(var rest (* const u8) NULL)
|
||||
(if (< n 0)
|
||||
(do
|
||||
(= palette-len (cast (- n) size-t))
|
||||
(if (> (+ 4 palette-len) len) (return false))
|
||||
(= palette (malloc palette-len))
|
||||
(memcpy palette (+ p 4) palette-len)
|
||||
(= rest (+ p 4 palette-len)))
|
||||
(do
|
||||
(if (> (+ 4 (cast n size-t)) len) (return false))
|
||||
(= palette (unzstd (+ p 4) (cast n size-t) (& palette-len)))
|
||||
(= rest (+ p 4 n))))
|
||||
(var planes-len size-t 0)
|
||||
(var planes (* u8) (if palette (unzstd rest (cast (- (+ p len) rest) size-t) (& planes-len)) NULL))
|
||||
(var count int (cast (/ palette-len 4) int))
|
||||
(var bits int (cast (/ planes-len 4096) int))
|
||||
(var ok bool (&& palette planes (> count 0)))
|
||||
(if ok
|
||||
(do
|
||||
(var index (* i32) (calloc CHUNK-VOLUME (sizeof i32)))
|
||||
(for (var k int 0) (< k bits) (++ k)
|
||||
(var plane (* const u8) (+ planes (* k 4096)))
|
||||
(for (var i int 0) (< i CHUNK-VOLUME) (++ i)
|
||||
(if (& (>> [plane (/ i 8)] (% i 8)) 1)
|
||||
(c-bit-or= [index i] (<< 1 k)))))
|
||||
(for (var i int 0) (< i CHUNK-VOLUME) (++ i)
|
||||
(var k int [index i])
|
||||
(var id i32 -1)
|
||||
(if (< k count)
|
||||
(memcpy (& id) (+ palette (* k 4)) 4))
|
||||
(= [out i] id))
|
||||
(free index)))
|
||||
(free palette)
|
||||
(free planes)
|
||||
(return ok))
|
||||
|
||||
;;; The blocks of stored chunk (cx, cy, cz), by (y * 32 + z) * 32 + x,
|
||||
;;; as block ids (see save/block-code). False when the save has no such
|
||||
;;; chunk or its blocks don't read.
|
||||
(pub fn save/chunk-blocks ((s (* const save)) (cx i32) (cy i32) (cz i32) (out (* i32))) bool
|
||||
(var stmt (* sqlite3-stmt) NULL)
|
||||
(var key i64 (c-bit-or (position cx cz) (<< (cast cy i64) 54)))
|
||||
(var r pb (query-blob s "select data from chunk where position = ?1" key (& stmt)))
|
||||
(var ok bool false)
|
||||
(if (! (. r err))
|
||||
(do
|
||||
(var wire int)
|
||||
(var f u32)
|
||||
(while (> (= f (.field (& r) (& wire))) 0)
|
||||
(if (== f 1)
|
||||
(do
|
||||
(var blocks pb (.bytes (& r)))
|
||||
(= ok (read-blocks (. blocks p) (.len blocks) out)))
|
||||
(.skip (& r) wire)))))
|
||||
(sqlite3-finalize stmt)
|
||||
(return ok))
|
||||
|
||||
;;; The stored extent of a table, in its own units (regions or chunks):
|
||||
;;; inclusive bounds and the row count.
|
||||
(pub record extent ((x0 i32) (z0 i32) (x1 i32) (z1 i32) (count i64)))
|
||||
|
||||
Reference in New Issue
Block a user