generate the region maps as the game does

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>
This commit is contained in:
2026-10-08 18:12:40 +03:00
parent 90b5d50fa5
commit 63fd30a189
12 changed files with 1843 additions and 36 deletions

View File

@@ -9,23 +9,14 @@
(pub include sqlite3.h)
(include stdio.h stdlib.h string.h)
(import pb)
(import maps)
;;; RegionSize is the closed engine's; Rivers hardcodes the same 512.
(pub define REGION-SIZE 512)
(pub define CHUNK-SIZE 32)
(pub define CHUNK-AREA 1024)
(pub define MAX-STRATA 32)
(pub define MAX-STORIES 32)
;;; IntDataMap2D: a square map whose border pixels only feed lerps
;;; and blurs. The region's own pixels are the inner
;;; (size - pad-tl - pad-br) square.
(pub record int-map ((data (* i32)) (size i32) (pad-tl i32) (pad-br i32)))
(pub record region-maps
((landform int-map) (climate int-map) (geoprov int-map) (upheaval int-map)
(ocean int-map) (strata [int-map MAX_STRATA]) (strata-count int)))
(pub record chunk-maps
((terrain-height [u16 CHUNK_AREA]) (rain-height [u16 CHUNK_AREA])
(top-rock [i32 CHUNK_AREA]) (river-distance [u16 CHUNK_AREA])
@@ -290,15 +281,6 @@
(++ (. m strata-count)))
(.skip (& r) wire))))
(pub fn region-maps/free ((m (* region-maps))) void
(free (. m landform data))
(free (. m climate data))
(free (. m geoprov data))
(free (. m upheaval data))
(free (. m ocean data))
(for (var i int 0) (< i (. m strata-count)) (++ i)
(free (. [(. m strata) i] data))))
(pub fn save/region ((s (* const save)) (rx i32) (rz i32) (out (* region-maps))) bool
(var stmt (* sqlite3-stmt) NULL)
(var r pb (query-blob s "select data from mapregion where position = ?1"