read the save, the seed and the worldgen assets
The engine's save classes are closed, so the protobuf field numbers were read off the data and matched to the map sizes TerraGenConfig gives. vsmv dump renders what the save stored, as the reference the generator will be diffed against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
104
src/vsmv.sex
104
src/vsmv.sex
@@ -1,43 +1,89 @@
|
||||
;;; 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 sqlite3.h)
|
||||
(include stdio.h string.h)
|
||||
(import cs)
|
||||
(import json)
|
||||
(import save)
|
||||
(import dump)
|
||||
|
||||
(var save-tables [(* const char) 4] #("gamedata" "mapregion" "mapchunk" "chunk"))
|
||||
(var worldgen-assets [(* const char) 6]
|
||||
#("landforms" "geologicprovinces" "rockstrata" "storystructures"
|
||||
"blocklayers" "deposits"))
|
||||
|
||||
(fn usage () int
|
||||
(fputs "usage: vsmv info SAVE.vcdbs\n" stderr)
|
||||
(fputs "usage: vsmv info SAVE.vcdbs\n vsmv seed TEXT...\n vsmv assets ASSETS-DIR\n vsmv dump SAVE.vcdbs OUT-DIR\n"
|
||||
stderr)
|
||||
(return 2))
|
||||
|
||||
(fn count-rows ((db (* sqlite3)) (table (* const char))) i64
|
||||
(var sql [char 64])
|
||||
(snprintf sql (sizeof sql) "select count(*) from %s" table)
|
||||
(var stmt (* sqlite3-stmt) NULL)
|
||||
(if (!= (sqlite3-prepare-v2 db sql -1 (& stmt) NULL) SQLITE-OK)
|
||||
(return -1))
|
||||
(var n i64 -1)
|
||||
(if (== (sqlite3-step stmt) SQLITE-ROW)
|
||||
(= n (sqlite3-column-int64 stmt 0)))
|
||||
(sqlite3-finalize stmt)
|
||||
(return n))
|
||||
|
||||
;;; vsmv info world.vcdbs
|
||||
;;; gamedata 1
|
||||
;;; mapregion 118
|
||||
;;; ...
|
||||
(fn info ((path (* const char))) int
|
||||
(var db (* sqlite3) NULL)
|
||||
(if (!= (sqlite3-open-v2 path (& db) SQLITE-OPEN-READONLY NULL) SQLITE-OK)
|
||||
(do
|
||||
(fprintf stderr "%s: %s\n" path (sqlite3-errmsg db))
|
||||
(sqlite3-close db)
|
||||
(return 1)))
|
||||
(for (var i int 0) (< i 4) (++ i)
|
||||
(printf "%-10s %8lld\n" [save-tables i] (count-rows db [save-tables i])))
|
||||
(sqlite3-close db)
|
||||
(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))
|
||||
|
||||
(pub fn main ((argc int) (argv [* char])) int
|
||||
(if (&& (== argc 3) (== (strcmp [argv 1] "info") 0))
|
||||
(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)))
|
||||
(return (usage)))
|
||||
|
||||
Reference in New Issue
Block a user