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:
172
src/verify.sex
172
src/verify.sex
@@ -165,6 +165,178 @@
|
||||
(.release (& diff))
|
||||
(return (if (|| (!= (. t matched) (. t compared)) (> unknown 0)) 1 0)))
|
||||
|
||||
;;; What a block of the save is, for the strata check.
|
||||
(define BLOCK-OTHER -1)
|
||||
;;; a rock- block whose rock is not a stratum, e.g. a deposit's halite
|
||||
(define BLOCK-OTHER-ROCK -2)
|
||||
|
||||
;;; Kinds of blocks the save has where the strata put rock, by the code
|
||||
;;; up to its first hyphen, e.g. "ore" or "crackedrock".
|
||||
(define MAX-KINDS 64)
|
||||
(record kind-count ((name [char 24]) (count i64)))
|
||||
|
||||
(fn count-kind ((kinds (* kind-count)) (n (* int)) (code (* const char))) void
|
||||
(var len int (cast (strcspn code "-") int))
|
||||
(for (var i int 0) (< i (* n)) (++ i)
|
||||
(if (&& (== (cast (strlen (. [kinds i] name)) int) len)
|
||||
(== (strncmp (. [kinds i] name) code len) 0))
|
||||
(do (++ (. [kinds i] count)) (return))))
|
||||
(if (>= (* n) MAX-KINDS)
|
||||
(return))
|
||||
(snprintf (. [kinds (* n)] name) 24 "%.*s" len code)
|
||||
(= (. [kinds (* n)] count) 1)
|
||||
(++ (* n)))
|
||||
|
||||
(fn by-count ((pa (* const void)) (pb (* const void))) int
|
||||
(var a (* const kind-count) pa)
|
||||
(var b (* const kind-count) pb)
|
||||
(return (- (< (. a count) (. b count)) (> (. a count) (. b count)))))
|
||||
|
||||
;;; Lava in caves sits at y 11 and below and turns the rock around it
|
||||
;;; to basalt, a few blocks further up.
|
||||
(define LAVA-BASALT-TOP 18)
|
||||
|
||||
;;; Compares the rock below the surface with the save's blocks, chunk
|
||||
;;; by chunk: every block from y = 1 up to the lower of our height and
|
||||
;;; the stored one. The strata are laid against our height, as the game
|
||||
;;; laid them against its height before the dry seabed raise.
|
||||
;;;
|
||||
;;; Where the save has a stratum rock, it should be ours. Three things
|
||||
;;; written after the strata explain where it isn't: the column's height
|
||||
;;; differs from ours, so its strata sit differently; basalt around cave
|
||||
;;; lava near the bottom; and the default rock, which cave walls and
|
||||
;;; underground structures are built of. Where the save has anything
|
||||
;;; else, ore, caves, deposits, it is counted by kind.
|
||||
(pub fn verify-strata ((s (* save)) (g (* worldgen)) (config river-config) (rocks (* strata))
|
||||
(dir (* const char))) int
|
||||
(var t (* terra) (terra/make g config))
|
||||
(var heights [u16 1024])
|
||||
(var basalt int -1)
|
||||
(for (var r int 0) (< r (. rocks rock-count)) (++ r)
|
||||
(if (== (strcmp [(. rocks rock-codes) r] "rock-basalt") 0)
|
||||
(= basalt r)))
|
||||
(var e extent (save/extent s "mapchunk"))
|
||||
(var w int (* (+ (- (. e x1) (. e x0)) 1) 32))
|
||||
(var h int (* (+ (- (. e z1) (. e z0)) 1) 32))
|
||||
(var diff image (image/make w h))
|
||||
(var t0 clock-t (clock))
|
||||
;; block id -> strata rock index, or a BLOCK- kind
|
||||
(var rock-of (* int) (malloc (* (+ (. s block-count) 1) (sizeof int))))
|
||||
(for (var id int 0) (< id (. s block-count)) (++ id)
|
||||
(var code (* const char) (save/block-code s id))
|
||||
(= [rock-of id] BLOCK-OTHER)
|
||||
(if (== (strncmp code "rock-" 5) 0)
|
||||
(do
|
||||
(= [rock-of id] BLOCK-OTHER-ROCK)
|
||||
(for (var r int 0) (< r (. rocks rock-count)) (++ r)
|
||||
(if (== (strcmp code [(. rocks rock-codes) r]) 0)
|
||||
(= [rock-of id] r))))))
|
||||
(var size-y int (. s size-y))
|
||||
(var columns (* u8) (malloc (* CHUNK-AREA (+ size-y 1))))
|
||||
(var blocks (* i32) (malloc (* CHUNK-VOLUME (sizeof i32))))
|
||||
;; ours x theirs, for strata rocks that differ
|
||||
(var confusion (* i64) (calloc (* MAX-ROCKS MAX-ROCKS) (sizeof i64)))
|
||||
(var kinds [kind-count MAX-KINDS])
|
||||
(var kind-n int 0)
|
||||
(var compared i64 0)
|
||||
(var matched i64 0)
|
||||
(var other-rock i64 0)
|
||||
(var other i64 0)
|
||||
(var chunks i64 0)
|
||||
(var unreadable i64 0)
|
||||
(var other-height i64 0)
|
||||
(var lava i64 0)
|
||||
(var default-rock i64 0)
|
||||
(var m chunk-maps)
|
||||
(for (var cz int (. e z0)) (<= cz (. e z1)) (++ cz)
|
||||
(for (var cx int (. e x0)) (<= cx (. e x1)) (++ cx)
|
||||
(if (! (save/chunk s cx cz (& m)))
|
||||
(continue))
|
||||
(var top int 0)
|
||||
(terra/chunk-heights t cx cz 1 heights)
|
||||
(for (var i int 0) (< i CHUNK-AREA) (++ i)
|
||||
(var hi int [heights i])
|
||||
(if (> hi top) (= top hi))
|
||||
(strata/column rocks cx cz (% i 32) (/ i 32) hi (+ columns (* i (+ size-y 1)))))
|
||||
(var bad [bool 1024])
|
||||
(memset bad 0 (sizeof bad))
|
||||
(for (var cy int 0) (&& (<= (* cy 32) top) (< (* cy 32) size-y)) (++ cy)
|
||||
(if (! (save/chunk-blocks s cx cy cz blocks))
|
||||
(do
|
||||
(++ unreadable)
|
||||
(continue)))
|
||||
(++ chunks)
|
||||
(for (var i int 0) (< i CHUNK-VOLUME) (++ i)
|
||||
(var y int (+ (* cy 32) (/ i 1024)))
|
||||
(var col int (% i 1024))
|
||||
(if (|| (< y 1) (> y [(. m terrain-height) col]) (> y [heights col]))
|
||||
(continue))
|
||||
(var id i32 [blocks i])
|
||||
(var theirs int (if (&& (>= id 0) (< id (. s block-count))) [rock-of id] BLOCK-OTHER))
|
||||
(var ours int [columns (+ (* col (+ size-y 1)) y)])
|
||||
(if (>= theirs 0)
|
||||
(do
|
||||
(++ compared)
|
||||
(if (== theirs ours)
|
||||
(++ matched)
|
||||
(!= [heights col] [(. m terrain-height) col])
|
||||
(++ other-height)
|
||||
(&& (== theirs basalt) (<= y LAVA-BASALT-TOP))
|
||||
(++ lava)
|
||||
(== theirs (. rocks granite))
|
||||
(++ default-rock)
|
||||
(do
|
||||
(= [bad col] true)
|
||||
(if (< ours MAX-ROCKS)
|
||||
(++ [confusion (+ (* ours MAX-ROCKS) theirs)])))))
|
||||
(== theirs BLOCK-OTHER-ROCK)
|
||||
(do
|
||||
(++ other-rock)
|
||||
(count-kind kinds (& kind-n) (save/block-code s id)))
|
||||
(do
|
||||
(++ other)
|
||||
(count-kind kinds (& kind-n) (if (>= id 0) (save/block-code s id) "?"))))))
|
||||
(for (var i int 0) (< i CHUNK-AREA) (++ i)
|
||||
(var colour u32 (if [bad i] 0xFF2020 (grey 96)))
|
||||
(.set (& diff) (+ (* (- cx (. e x0)) 32) (% i 32)) (+ (* (- cz (. e z0)) 32) (/ i 32))
|
||||
colour))))
|
||||
(var unexplained i64 (- compared matched other-height lava default-rock))
|
||||
(printf "strata %lld/%lld rock blocks below the surface match (%.4f%%), %lld chunks, %.1f s\n"
|
||||
matched compared (if (> compared 0) (/ (* 100.0 matched) compared) 0.0) chunks
|
||||
(/ (cast (- (clock) t0) double) CLOCKS-PER-SEC))
|
||||
(printf " explained: %lld where the height differs, %lld lava basalt, %lld default rock; %lld others (%.4f%%):\n"
|
||||
other-height lava default-rock unexplained
|
||||
(if (> compared 0) (/ (* 100.0 unexplained) compared) 0.0))
|
||||
(if (> unreadable 0)
|
||||
(printf " %lld chunks missing or unreadable\n" unreadable))
|
||||
;; the commonest confusions
|
||||
(for (var shown int 0) (< shown 8) (++ shown)
|
||||
(var best int -1)
|
||||
(for (var k int 0) (< k (* MAX-ROCKS MAX-ROCKS)) (++ k)
|
||||
(if (&& (> [confusion k] 0) (|| (< best 0) (> [confusion k] [confusion best])))
|
||||
(= best k)))
|
||||
(if (< best 0)
|
||||
(break))
|
||||
(printf " ours %-16s save %-16s %lld\n" [(. rocks rock-codes) (/ best MAX-ROCKS)]
|
||||
[(. rocks rock-codes) (% best MAX-ROCKS)] [confusion best])
|
||||
(= [confusion best] 0))
|
||||
(qsort kinds kind-n (sizeof kind-count) by-count)
|
||||
(printf " where the save has no stratum rock: %lld blocks, %lld of them other rock;" (+ other other-rock)
|
||||
other-rock)
|
||||
(for (var k int 0) (&& (< k kind-n) (< k 12)) (++ k)
|
||||
(printf " %s %lld" (. [kinds k] name) (. [kinds k] count)))
|
||||
(printf "\n")
|
||||
(var path [char 1024])
|
||||
(snprintf path (sizeof path) "%s/diff-strata.png" dir)
|
||||
(.write (& diff) path)
|
||||
(.release (& diff))
|
||||
(free columns)
|
||||
(free blocks)
|
||||
(free confusion)
|
||||
(free rock-of)
|
||||
(terra/free t)
|
||||
(return (if (< (* unexplained 10000) compared) 0 1)))
|
||||
|
||||
;;; Recomputes the prospecting pick readings players took in the save
|
||||
;;; and compares each mineral's TotalFactor: per reading, every
|
||||
;;; mineral the save has or this reads above nothing.
|
||||
|
||||
Reference in New Issue
Block a user