generate terrain height as Rivers' GenTerra does
98.2% of stored columns match exactly; the rest is the dry seabed raise and surface caves, both later passes that the strata never see. GenTerra thresholds the new terrain noise through the old tanh curve's inverse, and matching that quirk is what moved it from 87%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
(import worldgen)
|
||||
(import fastnoise)
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import img)
|
||||
|
||||
(define MAP-KINDS 6)
|
||||
@@ -173,3 +174,68 @@
|
||||
(if plate (river-plate/free plate))
|
||||
(free segments)
|
||||
(return (if (&& (== stored-matched stored-columns) (== unstored-wrong 0)) 0 1)))
|
||||
|
||||
;;; Recomputes every stored map chunk's terrain height and compares it
|
||||
;;; 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
|
||||
(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 t (* terra) (terra/make g config))
|
||||
(var heights [u16 1024])
|
||||
(var columns i64 0)
|
||||
(var matched i64 0)
|
||||
(var by-delta [i64 9])
|
||||
(memset by-delta 0 (sizeof by-delta))
|
||||
;; stored higher / lower, computed top below / at or above sea level
|
||||
(var by-class [i64 4])
|
||||
(memset by-class 0 (sizeof by-class))
|
||||
(var t0 clock-t (clock))
|
||||
(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))
|
||||
(terra/chunk-heights t cx cz 1 heights)
|
||||
(for (var i int 0) (< i 1024) (++ i)
|
||||
(var want int [(. m terrain-height) i])
|
||||
(var got int [heights i])
|
||||
(++ columns)
|
||||
(var d int (- want got))
|
||||
(if (== d 0) (++ matched))
|
||||
(if (!= d 0)
|
||||
(do
|
||||
(var cls int 0)
|
||||
(if (< d 0) (+= cls 2))
|
||||
(if (>= got (. t sea-level)) (+= cls 1))
|
||||
(++ [by-class cls])))
|
||||
;; -4..+4, the ends counting everything beyond
|
||||
(var bucket int (+ (if (< d -4) -4 (if (> d 4) 4 d)) 4))
|
||||
(++ [by-delta bucket])
|
||||
(var colour u32 (grey (/ (* got 255) (. g settings size-y))))
|
||||
(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))))
|
||||
(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"
|
||||
[by-delta 0] [by-delta 1] [by-delta 2] [by-delta 3] [by-delta 5] [by-delta 6] [by-delta 7]
|
||||
[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])
|
||||
(var path [char 1024])
|
||||
(snprintf path (sizeof path) "%s/diff-heights.png" dir)
|
||||
(.write (& diff) path)
|
||||
(.release (& diff))
|
||||
(terra/free t)
|
||||
;; Two later passes change the stored height after strata are laid:
|
||||
;; GenBlockLayers raises dry seabeds, GenCaves lowers where a cave
|
||||
;; opens the surface. Anything else is ours.
|
||||
(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))
|
||||
(return (if (< (* unexplained 1000) columns) 0 1)))
|
||||
|
||||
Reference in New Issue
Block a user