lay out rivers as the Rivers mod does
Every stored riverDistance column matches. Plates are built from 25 ocean samples per zone rather than a region map per zone, and the ocean distance from a ring search that finds what the mod's BFS does, so a plate costs 0.08 s; workers cache a few, as a wide view spans several. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
;;; region over everything the save has. A port is right when every
|
||||
;;; map matches to the pixel, padding included.
|
||||
|
||||
(include stdio.h stdlib.h string.h)
|
||||
(include stdio.h stdlib.h string.h time.h)
|
||||
(import maps)
|
||||
(import lcg)
|
||||
(import noise)
|
||||
@@ -10,6 +10,8 @@
|
||||
(import shape)
|
||||
(import save)
|
||||
(import worldgen)
|
||||
(import fastnoise)
|
||||
(import rivers)
|
||||
(import img)
|
||||
|
||||
(define MAP-KINDS 6)
|
||||
@@ -108,3 +110,66 @@
|
||||
(.write (& [diffs k]) path)
|
||||
(.release (& [diffs k])))
|
||||
(return failed))
|
||||
|
||||
;;; Recomputes Rivers' per-column riverDistance for every map chunk the
|
||||
;;; save stored and compares it with the moddata Rivers saved: exactly
|
||||
;;; where it saved some, and "nothing within 300 blocks" where it saved
|
||||
;;; none.
|
||||
(pub fn verify-rivers ((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 sampler river-sampler (river-sampler/make (& config) (. g settings size-y)))
|
||||
(var plate (* river-plate) NULL)
|
||||
(var chunks-per-plate int (/ (* (. config zone-size) (. config zones-in-region)) 32))
|
||||
(var segments (* int) NULL)
|
||||
(var stored-columns i64 0)
|
||||
(var stored-matched i64 0)
|
||||
(var unstored-chunks int 0)
|
||||
(var unstored-wrong int 0)
|
||||
(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))
|
||||
(var px int (/ cx chunks-per-plate))
|
||||
(var pz int (/ cz chunks-per-plate))
|
||||
(if (|| (! plate) (!= (. plate px) px) (!= (. plate pz) pz))
|
||||
(do
|
||||
(if plate (river-plate/free plate))
|
||||
(var t0 clock-t (clock))
|
||||
(= plate (river-plate/make config (& (. g oceans)) (. g settings size-y) px pz))
|
||||
(printf "river plate %d,%d: %d nodes, %d segments, %.2f s\n" px pz (. plate node-count)
|
||||
(. plate segment-count) (/ (cast (- (clock) t0) double) CLOCKS-PER-SEC))
|
||||
(= segments (realloc segments (* (+ (. plate segment-count) 1) (sizeof int))))))
|
||||
(var count int (river-plate/chunk-segments plate cx cz segments))
|
||||
(var in-range bool false)
|
||||
(for (var i int 0) (< i 1024) (++ i)
|
||||
(var bx int (+ (* cx 32) (% i 32)))
|
||||
(var bz int (+ (* cz 32) (/ i 32)))
|
||||
(var sample river-sample (river-sampler/sample (& sampler) plate segments count bx bz))
|
||||
(var d int (cast (cast (. sample distance) u16) int))
|
||||
(if (<= d 300) (= in-range true))
|
||||
(var ok bool true)
|
||||
(if (. m has-river-distance)
|
||||
(do
|
||||
(++ stored-columns)
|
||||
(= ok (== d [(. m river-distance) i]))
|
||||
(if ok (++ stored-matched))))
|
||||
(var shade int (if (> d 255) 0 (- 255 d)))
|
||||
(.set (& diff) (+ (* (- cx (. e x0)) 32) (% i 32)) (+ (* (- cz (. e z0)) 32) (/ i 32))
|
||||
(if ok (grey shade) 16719904)))
|
||||
(if (! (. m has-river-distance))
|
||||
(do
|
||||
(++ unstored-chunks)
|
||||
(if in-range (++ unstored-wrong))))))
|
||||
(printf "rivers %lld/%lld columns with stored riverDistance match; %d/%d chunks without it rightly have no river within 300\n"
|
||||
stored-matched stored-columns (- unstored-chunks unstored-wrong) unstored-chunks)
|
||||
(var path [char 1024])
|
||||
(snprintf path (sizeof path) "%s/diff-rivers.png" dir)
|
||||
(.write (& diff) path)
|
||||
(.release (& diff))
|
||||
(if plate (river-plate/free plate))
|
||||
(free segments)
|
||||
(return (if (&& (== stored-matched stored-columns) (== unstored-wrong 0)) 0 1)))
|
||||
|
||||
Reference in New Issue
Block a user