lay rock strata and show them as an overlay

The surface rock matches the save's TopRockIdMap in all but 14 of
11.7 million columns. Rock tiles keep rock indices and take their
colours from a palette on upload, so highlighting one rock, to find
where it lies, recolours what is drawn instead of regenerating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 19:53:26 +03:00
parent c4c7ab9968
commit 4666188b21
8 changed files with 620 additions and 47 deletions

View File

@@ -13,6 +13,7 @@
(import fastnoise)
(import rivers)
(import terra)
(import strata)
(import img)
(define MAP-KINDS 6)
@@ -179,7 +180,8 @@
;;; with WorldGenTerrainHeightMap. Mismatches are counted by how far off
;;; they are, which tells a missing step (a raise of a few blocks) from
;;; noise that is wrong.
(pub fn verify-heights ((s (* save)) (g (* worldgen)) (config river-config) (dir (* const char))) int
(pub fn verify-heights ((s (* save)) (g (* worldgen)) (config river-config) (rocks (* strata))
(dir (* const char))) int
(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))
@@ -194,6 +196,11 @@
(var by-class [i64 4])
(memset by-class 0 (sizeof by-class))
(var t0 clock-t (clock))
(var rock-columns i64 0)
(var rock-matched i64 0)
(var no-rock i64 0)
(var rock-diff image (image/make w h))
(var column [u8 1024])
(var m chunk-maps)
(for (var cz int (. e z0)) (<= cz (. e z1)) (++ cz)
(for (var cx int (. e x0)) (<= cx (. e x1)) (++ cx)
@@ -219,7 +226,25 @@
(if (> d 0) (= colour 16719904))
(if (< d 0) (= colour 2105599))
(.set (& diff) (+ (* (- cx (. e x0)) 32) (% i 32)) (+ (* (- cz (. e z0)) 32) (/ i 32))
colour))))
colour)
;; The top rock the game recorded is at the top solid block after
;; caves; the dry seabed raise only stacks more of it.
(var top (* const char) (save/block-code s [(. m top-rock) i]))
(if (|| (! (strncmp top "rock-" 5)) (! (strncmp top "rock" 4)))
(do
(strata/column rocks cx cz (% i 32) (/ i 32) got column)
(var y int (if (< want got) want got))
(var ours int [column y])
(var name (* const char) (if (== ours ROCK-MANTLE) "mantle" [(. rocks rock-codes) ours]))
(++ rock-columns)
(var same bool (== (strcmp name top) 0))
(if same (++ rock-matched))
(var rc u32 16719904)
(if same (= rc (palette (cast ours u32))))
(.set (& rock-diff) (+ (* (- cx (. e x0)) 32) (% i 32)) (+ (* (- cz (. e z0)) 32) (/ i 32))
rc))
(++ no-rock)))))
(printf "heights %lld/%lld columns match, %.1f s\n" matched columns
(/ (cast (- (clock) t0) double) CLOCKS-PER-SEC))
(printf " stored - computed: <=-4 %lld, -3 %lld, -2 %lld, -1 %lld, +1 %lld, +2 %lld, +3 %lld, >=+4 %lld\n"
@@ -227,7 +252,12 @@
[by-delta 8])
(printf " stored higher: %lld under water, %lld on land; stored lower: %lld under water, %lld on land\n"
[by-class 0] [by-class 1] [by-class 2] [by-class 3])
(printf "top rock %lld/%lld columns match (%.4f%%); %lld columns have no rock on top\n"
rock-matched rock-columns (/ (* 100.0 rock-matched) rock-columns) no-rock)
(var path [char 1024])
(snprintf path (sizeof path) "%s/diff-toprock.png" dir)
(.write (& rock-diff) path)
(.release (& rock-diff))
(snprintf path (sizeof path) "%s/diff-heights.png" dir)
(.write (& diff) path)
(.release (& diff))
@@ -238,4 +268,7 @@
(var unexplained i64 (+ [by-class 1] [by-class 2]))
(printf " explained by the dry seabed raise and caves: all but %lld (%.3f%%)\n"
unexplained (/ (* 100.0 unexplained) columns))
;; a handful of columns carry structures or boulders placed later
(if (> (* (- rock-columns rock-matched) 100000) rock-columns)
(return 1))
(return (if (< (* unexplained 1000) columns) 0 1)))