Every map in all 118 stored regions matches the save to the pixel, so the port is checked against ground truth rather than eyeballed. Getting there meant reproducing .NET quirks the output depends on: LCGRandom reseeding from its previous seed, Dictionary slot order in NaturalShape, and C#'s left-to-right evaluation of RNG draws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.6 KiB
Scheme
120 lines
4.6 KiB
Scheme
;;; vsmv: the command-line side of the viewer. It checks the generator
|
|
;;; against a saved world and dumps what either side produced.
|
|
|
|
(include stdio.h string.h)
|
|
;; An import brings in a module's own public forms but not the types
|
|
;; they mention, so dependencies come first.
|
|
(import cs)
|
|
(import json)
|
|
(import maps)
|
|
(import lcg)
|
|
(import noise)
|
|
(import shape)
|
|
(import save)
|
|
(import dump)
|
|
(import worldgen)
|
|
(import verify)
|
|
|
|
(var worldgen-assets [(* const char) 6]
|
|
#("landforms" "geologicprovinces" "rockstrata" "storystructures"
|
|
"blocklayers" "deposits"))
|
|
|
|
(fn usage () int
|
|
(fputs "usage: vsmv info SAVE.vcdbs\n vsmv seed TEXT...\n vsmv assets ASSETS-DIR\n vsmv dump SAVE.vcdbs OUT-DIR\n vsmv verify SAVE.vcdbs ASSETS-DIR OUT-DIR\n"
|
|
stderr)
|
|
(return 2))
|
|
|
|
(fn info ((path (* const char))) int
|
|
(var s (* save) (save/open path))
|
|
(if (! s)
|
|
(return 1))
|
|
(printf "seed %d\n" (. s seed))
|
|
(printf "size %d x %d x %d\n" (. s size-x) (. s size-y) (. s size-z))
|
|
(printf "block ids %d\n" (. s block-count))
|
|
(printf "world config, %d values:\n" (. s config-count))
|
|
(for (var i int 0) (< i (. s config-count)) (++ i)
|
|
(printf " %-28s %s\n" [(. s config-keys) i] [(. s config-values) i]))
|
|
(printf "story locations:\n")
|
|
(for (var i int 0) (< i (. s story-count)) (++ i)
|
|
(var l (* story-location) (& [(. s stories) i]))
|
|
(printf " %-24s %8d %4d %6d\n" (. l code) (. l x) (. l y) (. l z)))
|
|
(var regions extent (save/extent s "mapregion"))
|
|
(var chunks extent (save/extent s "mapchunk"))
|
|
(printf "map regions %lld, x %d..%d z %d..%d\n" (. regions count)
|
|
(. regions x0) (. regions x1) (. regions z0) (. regions z1))
|
|
(printf "map chunks %lld, x %d..%d z %d..%d\n" (. chunks count)
|
|
(. chunks x0) (. chunks x1) (. chunks z0) (. chunks z1))
|
|
(save/close s)
|
|
(return 0))
|
|
|
|
;;; vsmv assets assets -> each worldgen file's top-level arrays and
|
|
;;; the rock strata in generation order, which the result depends on.
|
|
(fn assets ((dir (* const char))) int
|
|
(var bad int 0)
|
|
(for (var i int 0) (< i 6) (++ i)
|
|
(var path [char 1024])
|
|
(snprintf path (sizeof path) "%s/survival/worldgen/%s.json" dir [worldgen-assets i])
|
|
(var j (* cJSON) (json-load path))
|
|
(if (! j)
|
|
(do (++ bad) (continue)))
|
|
(printf "%s:" [worldgen-assets i])
|
|
(for (var item (* cJSON) (. j child)) item (= item (. item next))
|
|
(if (cJSON-IsArray item)
|
|
(printf " %s[%d]" (. item string) (cJSON-GetArraySize item))))
|
|
(printf "\n")
|
|
(if (== (strcmp [worldgen-assets i] "rockstrata") 0)
|
|
(do
|
|
(var variants (* cJSON) (cJSON-GetObjectItemCaseSensitive j "variants"))
|
|
(for (var v (* cJSON) (. variants child)) v (= v (. v next))
|
|
(printf " %-20s %-12s %s\n"
|
|
(cJSON-GetStringValue (cJSON-GetObjectItemCaseSensitive v "blockcode"))
|
|
(cJSON-GetStringValue (cJSON-GetObjectItemCaseSensitive v "rockGroup"))
|
|
(cJSON-GetStringValue (cJSON-GetObjectItemCaseSensitive v "genDir"))))))
|
|
(cJSON-Delete j))
|
|
(return bad))
|
|
|
|
;;; Generates every region the save stored, with the save's own world
|
|
;;; settings, and diffs the maps.
|
|
(fn verify ((save-path (* const char)) (assets-dir (* const char)) (out (* const char))) int
|
|
(var s (* save) (save/open save-path))
|
|
(if (! s)
|
|
(return 1))
|
|
(var settings world-settings (world-settings/defaults))
|
|
(= (. settings seed) (. s seed))
|
|
(= (. settings size-x) (. s size-x))
|
|
(= (. settings size-y) (. s size-y))
|
|
(= (. settings size-z) (. s size-z))
|
|
(for (var i int 0) (< i (. s config-count)) (++ i)
|
|
(.set (& settings) [(. s config-keys) i] [(. s config-values) i]))
|
|
(var g (* worldgen) (worldgen/make settings assets-dir))
|
|
(if (! g)
|
|
(return 1))
|
|
(var failed int (+ (verify-stories s g) (verify-regions s g out)))
|
|
(save/close s)
|
|
(return failed))
|
|
|
|
(pub fn main ((argc int) (argv [* char])) int
|
|
(if (< argc 2)
|
|
(return (usage)))
|
|
(var cmd (* const char) [argv 1])
|
|
(if (&& (== (strcmp cmd "info") 0) (== argc 3))
|
|
(return (info [argv 2])))
|
|
(if (&& (== (strcmp cmd "seed") 0) (>= argc 3))
|
|
(do
|
|
(for (var i int 2) (< i argc) (++ i)
|
|
(printf "%d\t%s\n" (world-seed [argv i]) [argv i]))
|
|
(return 0)))
|
|
(if (&& (== (strcmp cmd "assets") 0) (== argc 3))
|
|
(return (assets [argv 2])))
|
|
(if (&& (== (strcmp cmd "dump") 0) (== argc 4))
|
|
(do
|
|
(var s (* save) (save/open [argv 2]))
|
|
(if (! s)
|
|
(return 1))
|
|
(dump s [argv 3])
|
|
(save/close s)
|
|
(return 0)))
|
|
(if (&& (== (strcmp cmd "verify") 0) (== argc 5))
|
|
(return (verify [argv 2] [argv 3] [argv 4])))
|
|
(return (usage)))
|