Compare commits
2 Commits
df0b8d815a
...
e174bff7e2
| Author | SHA1 | Date | |
|---|---|---|---|
| e174bff7e2 | |||
| 75d734c2d6 |
4
Makefile
4
Makefile
@@ -36,12 +36,12 @@ $(B)/cJSON.o: cJSON/cJSON.c cJSON/cJSON.h | $(B)
|
||||
$(B)/stb.o: src/stb.c third_party/stb/stb_image_write.h | $(B)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
VSMV_OBJ = vsmv cs pb json maps save img dump lcg noise shape worldgen fastnoise rivers terra strata settings verify cJSON stb
|
||||
VSMV_OBJ = vsmv cs pb json maps save img dump lcg noise shape worldgen fastnoise rivers terra strata ores settings verify cJSON stb
|
||||
|
||||
$(B)/vsmv: $(VSMV_OBJ:%=$(B)/%.o)
|
||||
$(CC) $^ -o $@ -lsqlite3
|
||||
|
||||
VIEWER_OBJ = viewer tiles search hover settings worldgen fastnoise rivers terra strata shape noise lcg maps save pb json cs nk cJSON stb
|
||||
VIEWER_OBJ = viewer tiles search hover settings worldgen fastnoise rivers terra strata ores shape noise lcg maps save pb json cs nk cJSON stb
|
||||
|
||||
$(B)/vs-map-viewer: $(VIEWER_OBJ:%=$(B)/%.o)
|
||||
$(CC) $^ -o $@ $(SDL_LIBS) -lsqlite3
|
||||
|
||||
85
Plan.org
85
Plan.org
@@ -50,6 +50,8 @@ redistribute their code verbatim.
|
||||
| Strata for one column | =vssurvivalmod/Systems/Prospecting/ProPickWorkSpace.cs= =GetRockColumn= |
|
||||
| Dry-climate height raise | =.../GenBlockLayers.cs:185=, patched by =Rivers/src/Patches/BlockLayersPatches.cs= |
|
||||
| Forced story landforms | =vssurvivalmod= =GenStoryStructures=, plus =GenMaps.ForceLandformAt= / =ForceClimateAt= |
|
||||
| Ore maps | =.../ChunkGen/5.GenDeposits/GenDeposits.cs= (=initWorldGen=, =getOrCreateMapLayer=), =DepositVariant.cs=, =GenMaps.GetOreMap=, =NoiseOre=, =MapLayerOre=, =MapLayerPerlinWobble= |
|
||||
| Prospecting readings | =vssurvivalmod/Systems/Prospecting/ItemProspectingPick.cs= (=GenProbeResults=), =ProPickWorkSpace.cs=, =DiscGenerator.cs= (=GetPropickReading=, =GetAbsAvgQuantity=), each disc generator's =GetYMinMax=, =PropickReading.cs= |
|
||||
|
||||
Assets come from =assets/survival/worldgen/=: =landforms.json=,
|
||||
=geologicprovinces.json=, =rockstrata.json=, =storystructures.json=,
|
||||
@@ -215,6 +217,7 @@ Modules. Each is a Sex module; the =vsmv= CLI and the GUI share them.
|
||||
the dry-climate raise for validation.
|
||||
- =strata=: =genBlockColumn=, plus queries for "rock at depth d" and
|
||||
"rock at Y".
|
||||
- =ores=: ore maps and the prospecting pick's density reading.
|
||||
- =assets=: lenient JSON loading and asset structs, plus a rock color
|
||||
palette. Hardcode the palette at first; take block texture averages
|
||||
later.
|
||||
@@ -274,9 +277,11 @@ What the save turned out to be:
|
||||
=landformScale=, which only scales the noise inside
|
||||
=MapLayerLandforms=.
|
||||
|
||||
Not used: forest, shrub, flower and beach (2, 5, 6, 15), ore maps
|
||||
(8), mod data (9), ore distortion (13, 14), block patch maps (16),
|
||||
animal spawn maps (21).
|
||||
| 8 | ore maps: entries {1: mineral code, 2: map}, 33 (0 top-left, 1 bottom-right) |
|
||||
|
||||
Not used: forest, shrub, flower and beach (2, 5, 6, 15), mod data
|
||||
(9), ore distortion (13, 14), block patch maps (16), animal spawn
|
||||
maps (21).
|
||||
- *=mapchunk=* (=ServerMapChunk=). All ushort arrays are repeated, not
|
||||
packed.
|
||||
|
||||
@@ -565,6 +570,73 @@ Viewer:
|
||||
11 us). Probes on the main thread use it too.
|
||||
- *Test flag.* =--mouse X Y= places the cursor for screenshot tests.
|
||||
|
||||
** Minerals: prospecting density
|
||||
What the prospecting pick's density mode reads, per column and mineral
|
||||
(=src/ores.sex=). Exact deposit placement is a later phase.
|
||||
- *Ore maps.* One per mineral code: =NoiseOre= cells every 16 pixels,
|
||||
smoothstep-lerped, then =MapLayerPerlinWobble= (5 octaves, scale 110,
|
||||
intensity 16.5). Region maps are 32 pixels plus one of bottom-right
|
||||
padding.
|
||||
- *Seeds.* World seed plus the code's =GetNonRandomizedHashCode=, the
|
||||
newer .NET hash. It rotates instead of shifting and reads the string's
|
||||
terminator, so it differs from =DotNetStringHash=. The sums wrap as
|
||||
C# ints.
|
||||
- *Which deposit counts.* Deposit files load in path order, and their
|
||||
variants in file order with children after their parent.
|
||||
- The map of a code takes the parameters of the first deposit that
|
||||
asks for it. A child's map takes its parent's scale, contrast and
|
||||
sub.
|
||||
- The reading of a code comes from the last deposit with it (the
|
||||
pick's =depositsByCode=). So cassiterite reads with its second,
|
||||
rare variant, silver with quartz's child, and peridot with
|
||||
olivine's child.
|
||||
- *Reading.* The ore map's low byte over 255, times the share of the
|
||||
column (y below the surface, with the default rock at y = 0) that is
|
||||
host rock inside the deposit's Y range. The Y range depends on the
|
||||
generator:
|
||||
- follow surface: =yPosRel= times the height;
|
||||
- follow sea level: =yPosRel= times the sea level;
|
||||
- follow surface below: the height minus =depth=.
|
||||
ppt is the total times =GetAbsAvgQuantity= (100 radius and thickness
|
||||
draws from a fresh =LCGRandom= of the world seed), over height x
|
||||
1024, x 1000. Categories: over 0.025, =(int)(total x 7.5)= from very
|
||||
poor up to ultra high; over 0.002, miniscule.
|
||||
- *Not reproduced.*
|
||||
- The game takes the Y range from 100 draws of the shared deposit
|
||||
RNG, whose state depends on what ran before; we take the
|
||||
distribution's limits.
|
||||
- The pick's column already holds the ore of the deposits generated
|
||||
in its chunk.
|
||||
- Children (silver, gold, peridot) are hosted by their parent's ore,
|
||||
so they need the deposits themselves.
|
||||
|
||||
Validation:
|
||||
- *Ore maps.* =vsmv verify= compares every mineral's map in every
|
||||
stored region: 3,658 maps, 3,983,562 / 3,983,562 pixels including
|
||||
padding.
|
||||
- *Readings.* The save keeps the pick readings players took
|
||||
(=oreMapMarkers-PLAYER= in game mod data: position, then code,
|
||||
TotalFactor, PartsPerThousand per mineral). Thirteen are stored. Both
|
||||
gaps above only lower the game's reading, so the check is that ours
|
||||
is never below the game's and at most 15% above it. 42 of 42 pass;
|
||||
the game's is 0.875 to 1.00 of ours. 38 of 42 fall in the same
|
||||
category, and the 4 others sit at a category edge.
|
||||
|
||||
Viewer:
|
||||
- *Minerals overlay.* Tiles keep =64 + category= per sample and share
|
||||
the rock palette, so they cost one more palette range, not a new
|
||||
tile kind.
|
||||
- *Minerals panel.* Picks the mineral from a list of the readable ones.
|
||||
Its legend gives each category's share of the view. Find nearest
|
||||
takes a least category (decent by default) and runs as search mode
|
||||
4.
|
||||
- *Cursor and Info.* A second label line gives the reading under the
|
||||
cursor while the Minerals overlay is on.
|
||||
- *Probe.* Lists the pick's full reading for the column, highest first,
|
||||
then the miniscule amounts, as the pick words it.
|
||||
- *Command line.* =--overlay mineral=, =--mineral CODE=,
|
||||
=--min-reading NAME= and =--find-mineral=.
|
||||
|
||||
** 7. Performance + polish
|
||||
- Level of detail:
|
||||
- zoomed out: one column per N blocks;
|
||||
@@ -575,8 +647,11 @@ Viewer:
|
||||
- Optional disk cache of tiles and plates, keyed by a hash of the
|
||||
settings.
|
||||
- Go-to-coordinates, PNG export of the current view.
|
||||
- Later: gravel-beach layer; ore deposits (=GenDeposits.GeneratePartial=
|
||||
is already on the =ProPickWorkSpace= path).
|
||||
- Later: gravel-beach layer; exact ore deposits
|
||||
(=GenDeposits.GeneratePartial= and the disc generators). That would
|
||||
place real ore blocks, make the pick readings exact, and read
|
||||
silver, gold and peridot. Checking it needs the save's chunk
|
||||
blocks decoded.
|
||||
|
||||
* Risks
|
||||
- *Bit-exactness* of the noise and the Rivers trigonometry. The
|
||||
|
||||
56
Readme.org
56
Readme.org
@@ -5,7 +5,8 @@ settings, and it generates the world the way the game would and shows
|
||||
it as a zoomable top-down map: terrain, rivers, oceans, climate,
|
||||
landforms, geologic provinces, and rock strata at any depth. It is
|
||||
mostly for finding rock: where chalk, bauxite or limestone lie, at the
|
||||
surface or 20 blocks down, and which one is nearest.
|
||||
surface or 20 blocks down, and which one is nearest. It also shows
|
||||
what the prospecting pick would read for an ore, anywhere on the map.
|
||||
|
||||
[[file:doc/screenshot.png]]
|
||||
|
||||
@@ -20,6 +21,8 @@ against a real save, and matches it:
|
||||
| Rivers' distance to the nearest river | 100% of 6.5 million columns |
|
||||
| Terrain height | 98.2% of 11.7 million columns |
|
||||
| Rock at the surface | all but 14 of 11.7 million columns |
|
||||
| Ore maps, 31 minerals | every pixel of 118 regions |
|
||||
| Prospecting pick readings | 38 of 42 in the game's category; see Limits |
|
||||
|
||||
All but 0.02% of the other heights come from two passes that run after
|
||||
the strata are laid: caves that open the surface, and the raise of dry
|
||||
@@ -68,11 +71,15 @@ Options:
|
||||
| =--assets DIR= | where the game's =assets= are; default =./assets= |
|
||||
| =--zoom Z= | blocks per screen point, 1/16 to 32; default 4 |
|
||||
| =--base LAYER= | the base layer: =ocean=, =rivers= or =height=; default =height= |
|
||||
| =--overlay NAME= | turn on an overlay: =landform=, =climate=, =province=, =upheaval=, =strata=, =rock=; repeatable |
|
||||
| =--overlay NAME= | turn on an overlay: =landform=, =climate=, =province=, =upheaval=, =strata=, =rock=, =mineral=; repeatable |
|
||||
| =--opacity F= | overlay opacity, 0 to 1; default 0.5 |
|
||||
| =--rock-depth N= / =--rock-y Y= | rocks at N blocks under the surface, or at height Y |
|
||||
| =--rock-any= | the one highlighted rock at any depth |
|
||||
| =--highlight ROCK= | highlight a rock, e.g. =chalk=; repeatable |
|
||||
| =--find= | find the nearest highlighted rock on start |
|
||||
| =--mineral CODE= | show a mineral's readings, e.g. =nativecopper= |
|
||||
| =--min-reading NAME= | Find nearest's least reading for minerals, e.g. =high= or =very-poor=; default =decent= |
|
||||
| =--find-mineral= | find the nearest such reading on start |
|
||||
| =--probe X Z= | probe the column at block X, Z on start |
|
||||
| =--screenshot FILE.png= | wait until everything is drawn, save the window, quit |
|
||||
| =--mouse X Y= | place the cursor, for screenshots |
|
||||
@@ -90,12 +97,14 @@ The map fills the middle of the window, between two panels.
|
||||
*** The map
|
||||
- Drag with the left mouse button to pan.
|
||||
- Scroll to zoom, around the cursor.
|
||||
- Click (without dragging) to probe that column: its rock strata appear
|
||||
in the Probe section, and a numbered pin marks the place. Click a pin
|
||||
to probe it again.
|
||||
- Click (without dragging) to probe that column: its rock strata and
|
||||
the prospecting pick's reading there appear in the Probe section, and
|
||||
a numbered pin marks the place. Click a pin to probe it again.
|
||||
- With /Rock under cursor/ on, a label by the cursor names the rock
|
||||
under it, as the Rocks section is set (at the surface, at a depth, or
|
||||
at a height).
|
||||
at a height). At any depth, it gives the Y of the rock's topmost block
|
||||
and how far down that is, or says the column has none. With the
|
||||
Minerals overlay on, a second line gives the mineral's reading.
|
||||
|
||||
The further out you zoom, the coarser the terrain is sampled: every
|
||||
block when zoomed in close, one in 32 when far out. Only what is on screen is computed;
|
||||
@@ -120,7 +129,9 @@ when nothing is left to compute, the viewer sleeps.
|
||||
|
||||
Below it, how many tiles are still being generated.
|
||||
- *Probe*: the last column probed: its surface height and its strata,
|
||||
top down, with the Y range and thickness of each.
|
||||
top down, with the Y range and thickness of each. Below them, what
|
||||
the prospecting pick reads there: every mineral it finds, highest
|
||||
first, with its parts per thousand, then the miniscule amounts.
|
||||
- /Go to/ centres it.
|
||||
- /Clear pins/ removes the pins.
|
||||
- /Close/ hides it.
|
||||
@@ -129,13 +140,16 @@ when nothing is left to compute, the viewer sleeps.
|
||||
- *Layers*:
|
||||
- *Base*: one of Ocean, Rivers or Terrain height. Drawn opaque.
|
||||
- *Overlays*: any of Landform, Climate, Geologic province, Upheaval,
|
||||
Rock strata thickness (pick the stratum below it) and Rock. Drawn
|
||||
over the base at the /Overlay opacity/.
|
||||
Rock strata thickness (pick the stratum below it), Rock and
|
||||
Minerals. Drawn over the base at the /Overlay opacity/.
|
||||
- /Story locations/ marks spawn and the story structures.
|
||||
- /Rock under cursor/ turns the cursor label on and off.
|
||||
- *Rocks*: finding rock.
|
||||
- Choose where to look: at the /Surface/, at a /Depth below
|
||||
surface/, or /At Y/, and set the depth or Y.
|
||||
surface/, or /At Y/, and set the depth or Y. /Any depth/ looks for
|
||||
one rock anywhere from the surface down to the mantle; it can be
|
||||
chosen while exactly one rock is highlighted, and while it is on,
|
||||
clicking a rock in the legend highlights that one instead.
|
||||
- The legend lists every rock with its share of the visible map,
|
||||
while the Rock overlay is on.
|
||||
- Click rocks in the legend to highlight them. With any highlighted,
|
||||
@@ -145,6 +159,17 @@ when nothing is left to compute, the viewer sleeps.
|
||||
the view, up to about 12,000 blocks out, jumps to the nearest one
|
||||
and probes it. It samples every 16 blocks before it refines, so a
|
||||
patch smaller than that can be missed. /Cancel/ stops it.
|
||||
- *Minerals*: finding ore, the way the prospecting pick's density mode
|
||||
does.
|
||||
- Choose a mineral. The Minerals overlay colours the map by what the
|
||||
pick would read there: miniscule, then very poor up to ultra high.
|
||||
The legend gives each reading's share of the view.
|
||||
- A reading combines the mineral's regional ore map with how much of
|
||||
the column is its host rock, at the depths its deposits are placed
|
||||
in. It says how likely the ore is near, not where the ore blocks
|
||||
are.
|
||||
- /Find nearest/ looks for the nearest column that reads at least
|
||||
/Find at least/, as Rocks' /Find nearest/ does.
|
||||
|
||||
** vsmv
|
||||
The command-line side, mostly for checking the generator against a
|
||||
@@ -159,7 +184,8 @@ save:
|
||||
| =vsmv verify SAVE.vcdbs DIR OUT= | regenerates everything the save stored and compares it; diff images go to OUT |
|
||||
|
||||
=verify= takes a few minutes, most of it on the terrain heights of
|
||||
every stored chunk.
|
||||
every stored chunk. It also compares the ore maps, and the prospecting
|
||||
pick readings players took in the save, if there are any.
|
||||
|
||||
** Limits
|
||||
- Only the /realistic/ world climate is supported, not /patchy/.
|
||||
@@ -168,6 +194,14 @@ every stored chunk.
|
||||
- Rivers' settings are not stored in a save. Without a =rivers.json=,
|
||||
the mod's defaults are assumed.
|
||||
- Other mods that change worldgen are not modelled.
|
||||
- Prospecting readings come out a little higher than the game's: in
|
||||
the readings checked, the game's was up to 12.5% lower, which can
|
||||
move one across a category edge. The game's column already holds the ore of the
|
||||
deposits generated in its chunk, and those deposits are not
|
||||
generated here.
|
||||
- Silver, gold and peridot are left out of Minerals. The game reads
|
||||
them from ore inside other deposits (quartz and olivine),
|
||||
which needs the deposits themselves.
|
||||
|
||||
** Notes
|
||||
- =Plan.org= is the design and how each part was checked.
|
||||
|
||||
25
src/cs.sex
25
src/cs.sex
@@ -87,3 +87,28 @@
|
||||
(>= v INT32_MIN) (<= v INT32_MAX))
|
||||
(return (cast v i32)))
|
||||
(return (dotnet-string-hash text)))
|
||||
|
||||
(fn rotl5 ((h u32)) u32
|
||||
(return (c-bit-or (<< h 5) (>> h 27))))
|
||||
|
||||
;;; StringUtil.GetNonRandomizedHashCode: the newer .NET string hash the
|
||||
;;; game seeds ore maps with. Unlike dotnet-string-hash it rotates, and
|
||||
;;; it reads past the end into the terminator.
|
||||
;;; (nonrandomized-string-hash "lignite")
|
||||
(pub fn nonrandomized-string-hash ((text (* const char))) i32
|
||||
(var units (* u16) NULL)
|
||||
(var len int (cast (utf16 text (& units)) int))
|
||||
(var h1 u32 (+ (<< (cast 5381 u32) 16) 5381))
|
||||
(var h2 u32 h1)
|
||||
(var i int 0)
|
||||
(while (> len 2)
|
||||
(-= len 4)
|
||||
(= h1 (^ (+ (rotl5 h1) h1) (c-bit-or [units i] (<< (cast [units (+ i 1)] u32) 16))))
|
||||
(= h2 (^ (+ (rotl5 h2) h2) (c-bit-or [units (+ i 2)] (<< (cast [units (+ i 3)] u32) 16))))
|
||||
(+= i 4))
|
||||
(if (> len 0)
|
||||
(= h2 (^ (+ (rotl5 h2) h2) (c-bit-or [units i] (<< (cast [units (+ i 1)] u32) 16)))))
|
||||
(free units)
|
||||
;; TODO sex#47: write the multiplier (0x5D588B65) in hex once there
|
||||
;; are hex literals.
|
||||
(return (cast (+ h1 (* h2 (cast 1566083941 u32))) i32)))
|
||||
|
||||
@@ -22,17 +22,23 @@
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import ores)
|
||||
|
||||
(pub record hover-query ((x int) (z int) (mode int) (value int)))
|
||||
;;; MINERAL is the mineral whose reading is wanted, or -1.
|
||||
(pub record hover-query ((x int) (z int) (mode int) (value int) (mineral int)))
|
||||
|
||||
(pub record hover-result
|
||||
((valid bool) (query hover-query)
|
||||
(height int) (sea-level int)
|
||||
;; rock index at the query's surface, depth or Y; -1 when the block
|
||||
;; there is water or air, -2 below the mantle
|
||||
;; there is water or air, -2 below the mantle. At any depth (mode
|
||||
;; 3, the value a rock index), that rock and the Y of its topmost
|
||||
;; block, or -3 when the column has none of it.
|
||||
(rock int) (rock-y int) (surface-rock int)
|
||||
(landform int) (province int) (climate int) (ocean int) (upheaval int)
|
||||
(river-distance double) (bank double)))
|
||||
(river-distance double) (bank double)
|
||||
;; the pick's reading of the query's mineral
|
||||
(mineral mineral-reading)))
|
||||
|
||||
(pub record hover-worker
|
||||
((lock pthread-mutex-t) (wake pthread-cond-t) (thread pthread-t) (quit bool)
|
||||
@@ -47,8 +53,10 @@
|
||||
|
||||
;;; The worker's generators and the region and plate it has at hand.
|
||||
(record kit
|
||||
((g (* worldgen)) (tr (* terra)) (rocks (* strata)) (generation int)
|
||||
((g (* worldgen)) (tr (* terra)) (rocks (* strata)) (minerals (* ores)) (generation int)
|
||||
(rx int) (rz int) (maps [int-map 5]) (has-region bool)
|
||||
;; the ore map last asked for: its mineral and region
|
||||
(ore-map int-map) (ore-mineral int) (ore-rx int) (ore-rz int)
|
||||
(plate (* river-plate)) (segments (* int)) (sampler river-sampler)
|
||||
(column (* u8))))
|
||||
|
||||
@@ -59,6 +67,8 @@
|
||||
(for (var i int 0) (< i 5) (++ i)
|
||||
(free (. [(. k maps) i] data))))
|
||||
(if (. k plate) (river-plate/free (. k plate)))
|
||||
(free (. k ore-map data))
|
||||
(if (. k minerals) (ores/free (. k minerals)))
|
||||
(if (. k rocks) (strata/free (. k rocks)))
|
||||
(if (. k tr) (terra/free (. k tr)))
|
||||
(if (. k g) (worldgen/free (. k g)))
|
||||
@@ -108,6 +118,28 @@
|
||||
(= (. r sea-level) (. (. k tr) sea-level))
|
||||
(strata/column (. k rocks) (/ x 32) (/ z 32) (% x 32) (% z 32) h (. k column))
|
||||
(= (. r surface-rock) [(. k column) h])
|
||||
(if (&& (. k minerals) (>= (. q mineral) 0) (< (. q mineral) (. (. k minerals) count)))
|
||||
(do
|
||||
(if (|| (! (. k ore-map data)) (!= (. k ore-mineral) (. q mineral)) (!= (. k ore-rx) rx)
|
||||
(!= (. k ore-rz) rz))
|
||||
(do
|
||||
(free (. k ore-map data))
|
||||
(ores/map (. k minerals) (. q mineral) rx rz (& (. k ore-map)))
|
||||
(= (. k ore-mineral) (. q mineral))
|
||||
(= (. k ore-rx) rx)
|
||||
(= (. k ore-rz) rz)))
|
||||
(= (. r mineral) (ores/reading (. k minerals) (. q mineral) (& (. k ore-map)) x z (. k column) h))))
|
||||
(if (== (. q mode) 3)
|
||||
(do
|
||||
(= (. r rock) -3)
|
||||
(for (var y int h) (>= y 1) (-- y)
|
||||
(if (== [(. k column) y] (. q value))
|
||||
(do
|
||||
(= (. r rock) (. q value))
|
||||
(= (. r rock-y) y)
|
||||
(break))))
|
||||
(= (. r valid) true)
|
||||
(return)))
|
||||
(var y int h)
|
||||
(if (== (. q mode) 1) (= y (- h (. q value)))
|
||||
(== (. q mode) 2) (= y (. q value)))
|
||||
@@ -143,6 +175,7 @@
|
||||
(do
|
||||
(= (. k tr) (terra/make (. k g) (. w rivers)))
|
||||
(= (. k rocks) (strata/make (. k g) (. w assets-dir)))
|
||||
(= (. k minerals) (ores/make settings (. w assets-dir) (. k rocks)))
|
||||
(= (. k sampler) (river-sampler/make (& (. w rivers)) (. settings size-y)))
|
||||
(= (. k column) (malloc (+ (. settings size-y) 1)))))
|
||||
(= (. k generation) generation)))
|
||||
@@ -180,7 +213,8 @@
|
||||
(pub fn hover-worker/ask ((w (* hover-worker)) (q hover-query)) void
|
||||
(pthread-mutex-lock (& (. w lock)))
|
||||
(if (|| (!= (. w query x) (. q x)) (!= (. w query z) (. q z)) (!= (. w query mode) (. q mode))
|
||||
(!= (. w query value) (. q value)) (! (. w result valid)))
|
||||
(!= (. w query value) (. q value)) (!= (. w query mineral) (. q mineral))
|
||||
(! (. w result valid)))
|
||||
(do
|
||||
(= (. w query) q)
|
||||
(= (. w pending) true)
|
||||
|
||||
543
src/ores.sex
Normal file
543
src/ores.sex
Normal file
@@ -0,0 +1,543 @@
|
||||
;;; Ore deposits as the prospecting pick's density mode sees them: per
|
||||
;;; mineral, the region ore map GenDeposits makes, and the reading the
|
||||
;;; pick gives for a column.
|
||||
;;;
|
||||
;;; A reading is the ore map's value there times the share of the
|
||||
;;; column that is the mineral's host rock within the Y range its
|
||||
;;; deposits are placed in (DiscDepositGenerator.GetPropickReading).
|
||||
;;; It says how likely ore is near, not where the ore blocks are.
|
||||
;;;
|
||||
;;; Two things the game folds into a reading are left out:
|
||||
;;; - The game draws a deposit's Y range from 100 random samples each
|
||||
;;; time, from an RNG whose state depends on what ran before. The
|
||||
;;; limits of the distribution are taken instead, so a range can be
|
||||
;;; a block or two wider than the game's.
|
||||
;;; - The pick's column includes the deposits generated in its own
|
||||
;;; chunk. Those are not generated here, so a column is all host rock
|
||||
;;; where the game may already have put ore in some of it. And a
|
||||
;;; child deposit (silver, gold, and peridot, whose reading comes from
|
||||
;;; the peridot inside olivine) is hosted by its parent's ore, so it
|
||||
;;; can't be read at all without the deposits.
|
||||
|
||||
(include stdio.h stdlib.h string.h math.h dirent.h)
|
||||
;; TODO sex#58: import only the modules used here once an import brings
|
||||
;; the types its interface needs; until then, every dependency, in
|
||||
;; dependency order.
|
||||
(import cs)
|
||||
(import maps)
|
||||
(import lcg)
|
||||
(import noise)
|
||||
(import shape)
|
||||
(import json)
|
||||
(import worldgen)
|
||||
(import fastnoise)
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
|
||||
(pub define MAX-MINERALS 48)
|
||||
(define MAX-DEPOSIT-FILES 64)
|
||||
;;; TerraGenConfig: ore map pixels per region side, and the scales of
|
||||
;;; the ore noise and its wobble.
|
||||
(define ORE-MAP-SIZE 32)
|
||||
(define ORE-SUB-SCALE 16)
|
||||
(define ORE-WOBBLE-SCALE 110)
|
||||
|
||||
;;; The reading's categories, as the pick words them: none, miniscule
|
||||
;;; amounts, then very poor up to ultra high.
|
||||
(pub define READING-CATEGORIES 8)
|
||||
|
||||
;;; Where a deposit generator puts its deposits, for the reading's Y
|
||||
;;; range.
|
||||
(define PLACE-NONE 0)
|
||||
(define PLACE-FOLLOW-SURFACE 1)
|
||||
(define PLACE-FOLLOW-SEALEVEL 2)
|
||||
(define PLACE-FOLLOW-SURFACE-BELOW 3)
|
||||
|
||||
;;; NatFloat, with the distributions the deposits use.
|
||||
(define DIST-UNIFORM 0)
|
||||
(define DIST-GAUSSIAN 1)
|
||||
(define DIST-INVEXP 2)
|
||||
(define DIST-STRONGINVEXP 3)
|
||||
(define DIST-TRIANGLE 4)
|
||||
(define DIST-NARROWGAUSSIAN 5)
|
||||
(define DIST-STRONGERINVEXP 6)
|
||||
|
||||
;; pub only because `mineral' holds one (see the field notes).
|
||||
(pub record natfloat ((dist int) (avg float) (var float)))
|
||||
|
||||
;;; A mineral is one code with an ore map. Its map is made with the
|
||||
;;; parameters of the first deposit that asks for it; its reading comes
|
||||
;;; from the last deposit with that code, as in ProPickWorkSpace.
|
||||
(pub record mineral
|
||||
((code [char 32])
|
||||
;; the ore map: NoiseOre, MapLayerOre and MapLayerPerlinWobble
|
||||
(noise lcg) (wobble-x (* simplex-noise)) (wobble-z (* simplex-noise))
|
||||
(scale float) (contrast float) (sub float)
|
||||
;; the reading
|
||||
(readable bool) (place int) (y natfloat) (abs-avg double) (bearing u32)))
|
||||
|
||||
;; TODO sex#50: write MAX-MINERALS once constants in array types are
|
||||
;; kebab-converted.
|
||||
(pub record ores
|
||||
((minerals [mineral MAX_MINERALS]) (count int) (granite int) (sea-level int)))
|
||||
|
||||
;;; The reading at one column: TotalFactor and PartsPerThousand.
|
||||
(pub record mineral-reading ((total double) (ppt double)))
|
||||
|
||||
;;; NatFloat ---------------------------------------------------------
|
||||
|
||||
(var dist-names [(* const char) 7]
|
||||
#("uniform" "gaussian" "invexp" "stronginvexp" "triangle" "narrowgaussian" "strongerinvexp"))
|
||||
|
||||
(fn read-natfloat ((o (* cJSON))) natfloat
|
||||
(var n natfloat #(natfloat : DIST-UNIFORM 0 0))
|
||||
(if (! o)
|
||||
(return n))
|
||||
(var dist (* const char) (cJSON-GetStringValue (cJSON-GetObjectItem o "dist")))
|
||||
(for (var i int 0) (&& dist (< i 7)) (++ i)
|
||||
(if (== (strcasecmp dist [dist-names i]) 0)
|
||||
(= (. n dist) i)))
|
||||
(= (. n avg) (cast (cJSON-GetNumberValue (cJSON-GetObjectItem o "avg")) float))
|
||||
(= (. n var) (cast (cJSON-GetNumberValue (cJSON-GetObjectItem o "var")) float))
|
||||
(if (isnan (. n avg)) (= (. n avg) 0))
|
||||
(if (isnan (. n var)) (= (. n var) 0))
|
||||
(return n))
|
||||
|
||||
;;; NatFloat.nextFloat(1, rand).
|
||||
(fn natfloat-next ((n (* const natfloat)) (r (* lcg))) float
|
||||
(var half float (cast 0.5 float))
|
||||
(var two float (cast 2 float))
|
||||
(var rnd float 0)
|
||||
(switch (. n dist)
|
||||
(case DIST-GAUSSIAN
|
||||
(do
|
||||
(var a float (.next-float r))
|
||||
(var b float (.next-float r))
|
||||
(var c float (.next-float r))
|
||||
(= rnd (- (/ (+ a b c) (cast 3 float)) half)))
|
||||
(return (+ (. n avg) (* rnd two (. n var)))))
|
||||
(case DIST-NARROWGAUSSIAN
|
||||
(do
|
||||
(var sum float 0)
|
||||
(for (var i int 0) (< i 6) (++ i)
|
||||
(+= sum (.next-float r)))
|
||||
(= rnd (- (/ sum (cast 6 float)) half)))
|
||||
(return (+ (. n avg) (* rnd two (. n var)))))
|
||||
(case DIST-INVEXP
|
||||
(do
|
||||
(var a float (.next-float r))
|
||||
(var b float (.next-float r))
|
||||
(= rnd (* a b)))
|
||||
(return (+ (. n avg) (* rnd (. n var)))))
|
||||
(case DIST-STRONGINVEXP
|
||||
(do
|
||||
(var a float (.next-float r))
|
||||
(var b float (.next-float r))
|
||||
(var c float (.next-float r))
|
||||
(= rnd (* a b c)))
|
||||
(return (+ (. n avg) (* rnd (. n var)))))
|
||||
(case DIST-STRONGERINVEXP
|
||||
(do
|
||||
(var a float (.next-float r))
|
||||
(var b float (.next-float r))
|
||||
(var c float (.next-float r))
|
||||
(var d float (.next-float r))
|
||||
(= rnd (* a b c d)))
|
||||
(return (+ (. n avg) (* rnd (. n var)))))
|
||||
(case DIST-TRIANGLE
|
||||
(do
|
||||
(var a float (.next-float r))
|
||||
(var b float (.next-float r))
|
||||
(= rnd (- (/ (+ a b) two) half)))
|
||||
(return (+ (. n avg) (* rnd two (. n var)))))
|
||||
(default
|
||||
(= rnd (- (.next-float r) half))
|
||||
(return (+ (. n avg) (* rnd two (. n var)))))))
|
||||
|
||||
;;; The least and greatest values the distribution gives.
|
||||
(fn natfloat-min ((n (* const natfloat))) float
|
||||
(if (|| (== (. n dist) DIST-INVEXP) (== (. n dist) DIST-STRONGINVEXP)
|
||||
(== (. n dist) DIST-STRONGERINVEXP))
|
||||
(return (fminf (. n avg) (+ (. n avg) (. n var)))))
|
||||
(return (fminf (- (. n avg) (. n var)) (+ (. n avg) (. n var)))))
|
||||
|
||||
(fn natfloat-max ((n (* const natfloat))) float
|
||||
(if (|| (== (. n dist) DIST-INVEXP) (== (. n dist) DIST-STRONGINVEXP)
|
||||
(== (. n dist) DIST-STRONGERINVEXP))
|
||||
(return (fmaxf (. n avg) (+ (. n avg) (. n var)))))
|
||||
(return (fmaxf (- (. n avg) (. n var)) (+ (. n avg) (. n var)))))
|
||||
|
||||
;;; Deposits ---------------------------------------------------------
|
||||
|
||||
(fn find-mineral ((o (* ores)) (code (* const char))) int
|
||||
(for (var i int 0) (< i (. o count)) (++ i)
|
||||
(if (== (strcmp (. [(. o minerals) i] code) code) 0)
|
||||
(return i)))
|
||||
(return -1))
|
||||
|
||||
(fn json-float ((o (* cJSON)) (key (* const char)) (fallback float)) float
|
||||
(var v (* cJSON) (cJSON-GetObjectItem o key))
|
||||
(if (cJSON-IsNumber v)
|
||||
(return (cast (cJSON-GetNumberValue v) float)))
|
||||
(return fallback))
|
||||
|
||||
;;; GenDeposits.getOrCreateMapLayer: the map for CODE, with the
|
||||
;;; parameters of the deposit that asks first. Seeds are C# ints, so
|
||||
;;; their sums wrap.
|
||||
(fn add-map ((o (* ores)) (seed i32) (code (* const char)) (params (* cJSON))) void
|
||||
(if (|| (>= (find-mineral o code) 0) (>= (. o count) MAX-MINERALS))
|
||||
(return))
|
||||
(var m (* mineral) (& [(. o minerals) (. o count)]))
|
||||
(memset m 0 (sizeof mineral))
|
||||
(snprintf (. m code) (sizeof (. m code)) "%s" code)
|
||||
(var hash u32 (cast (nonrandomized-string-hash code) u32))
|
||||
(var noise-seed i32 (cast (+ (cast seed u32) hash) i32))
|
||||
(var map-seed i32 (cast (+ (cast seed u32) hash 1) i32))
|
||||
(= (. m noise) (lcg/make noise-seed))
|
||||
(var wobble-seed i64 (+ (cast map-seed i64) 2))
|
||||
(var frequency float (/ (cast 1 float) (cast ORE-WOBBLE-SCALE float)))
|
||||
(= (. m wobble-x) (simplex-noise/octaves 5 frequency (cast 0.85 float) wobble-seed))
|
||||
(= (. m wobble-z) (simplex-noise/octaves 5 frequency (cast 0.85 float) (+ wobble-seed 1231296)))
|
||||
(= (. m scale) (* (cast ORE-SUB-SCALE float) (json-float params "oreMapScale" 1)))
|
||||
(= (. m contrast) (json-float params "oreMapContrast" 1))
|
||||
(= (. m sub) (json-float params "oreMapSub" 0))
|
||||
(++ (. o count)))
|
||||
|
||||
;;; Whether rock CODE is one INBLOCK's code and allowedVariants take.
|
||||
(fn in-block-matches ((inblock (* cJSON)) (code (* const char))) bool
|
||||
(var pattern (* const char) (cJSON-GetStringValue (cJSON-GetObjectItem inblock "code")))
|
||||
(if (! pattern)
|
||||
(return false))
|
||||
(var star (* const char) (strchr pattern #\*))
|
||||
(if (! star)
|
||||
(return (== (strcmp pattern code) 0)))
|
||||
(var prefix size-t (cast (- star pattern) size-t))
|
||||
(if (!= (strncmp pattern code prefix) 0)
|
||||
(return false))
|
||||
(var allowed (* cJSON) (cJSON-GetObjectItem inblock "allowedVariants"))
|
||||
(if (! allowed)
|
||||
(return true))
|
||||
(for (var v (* cJSON) (. allowed child)) v (= v (. v next))
|
||||
(var s (* const char) (cJSON-GetStringValue v))
|
||||
(if (&& s (== (strcmp s (+ code prefix)) 0))
|
||||
(return true)))
|
||||
(return false))
|
||||
|
||||
;;; DiscDepositGenerator.GetAbsAvgQuantity with a fresh LCGRandom of
|
||||
;;; the world seed, as Init calls it.
|
||||
(fn abs-avg-quantity ((seed i32) (radius (* const natfloat)) (thickness (* const natfloat))
|
||||
(tries float)) double
|
||||
(var r lcg (lcg/make seed))
|
||||
(var rs float 0)
|
||||
(var ts float 0)
|
||||
(for (var j int 0) (< j 100) (++ j)
|
||||
(+= rs (natfloat-next radius (& r)))
|
||||
(+= ts (natfloat-next thickness (& r))))
|
||||
(/= rs (cast 100 float))
|
||||
(/= ts (cast 100 float))
|
||||
(var pi float (cast M-PI float))
|
||||
(return (* ts rs rs pi tries)))
|
||||
|
||||
;;; The reading for CODE now comes from deposit V; a child deposit,
|
||||
;;; hosted by its parent's ore, can't be read.
|
||||
(fn set-reading ((o (* ores)) (v (* cJSON)) (child bool) (seed i32) (rocks (* const strata))) void
|
||||
(var i int (find-mineral o (cJSON-GetStringValue (cJSON-GetObjectItem v "code"))))
|
||||
(if (< i 0)
|
||||
(return))
|
||||
(var m (* mineral) (& [(. o minerals) i]))
|
||||
(= (. m readable) false)
|
||||
(= (. m place) PLACE-NONE)
|
||||
(var gen (* const char) (cJSON-GetStringValue (cJSON-GetObjectItem v "generator")))
|
||||
(var attributes (* cJSON) (cJSON-GetObjectItem v "attributes"))
|
||||
(if (|| child (! gen) (! attributes))
|
||||
(return))
|
||||
(if (== (strcmp gen "disc-followsurface") 0)
|
||||
(do
|
||||
(= (. m place) PLACE-FOLLOW-SURFACE)
|
||||
(= (. m y) (read-natfloat (cJSON-GetObjectItem attributes "yPosRel"))))
|
||||
(== (strcmp gen "disc-followsealevel") 0)
|
||||
(do
|
||||
(= (. m place) PLACE-FOLLOW-SEALEVEL)
|
||||
(= (. m y) (read-natfloat (cJSON-GetObjectItem attributes "yPosRel")))
|
||||
;; FollowSealevelDiscGenerator.Init
|
||||
(*= (. m y avg) (cast (. o sea-level) float))
|
||||
(*= (. m y var) (cast (. o sea-level) float)))
|
||||
(== (strcmp gen "disc-followsurfacebelow") 0)
|
||||
(do
|
||||
(= (. m place) PLACE-FOLLOW-SURFACE-BELOW)
|
||||
(= (. m y) (read-natfloat (cJSON-GetObjectItem attributes "depth"))))
|
||||
(return))
|
||||
(var radius natfloat (read-natfloat (cJSON-GetObjectItem attributes "radius")))
|
||||
(if (! (cJSON-GetObjectItem attributes "radius"))
|
||||
(= radius #(natfloat : DIST-UNIFORM 10 0)))
|
||||
(var thickness natfloat (read-natfloat (cJSON-GetObjectItem attributes "thickness")))
|
||||
(= (. m abs-avg) (abs-avg-quantity seed (& radius) (& thickness) (json-float v "triesPerChunk" 0)))
|
||||
(var inblock (* cJSON) (cJSON-GetObjectItem attributes "inblock"))
|
||||
(= (. m bearing) 0)
|
||||
(for (var r int 0) (&& inblock (< r (. rocks rock-count)) (< r 32)) (++ r)
|
||||
(if (in-block-matches inblock [(. rocks rock-codes) r])
|
||||
(c-bit-or= (. m bearing) (<< (cast 1 u32) r))))
|
||||
(= (. m readable) true))
|
||||
|
||||
(fn by-name ((pa (* const void)) (pb (* const void))) int
|
||||
(var a (* * char) (cast pa (* * char)))
|
||||
(var b (* * char) (cast pb (* * char)))
|
||||
(return (strcmp (* a) (* b))))
|
||||
|
||||
;;; The JSON files under DIR, relative to ROOT, into PATHS.
|
||||
(fn list-files ((root (* const char)) (dir (* const char)) (paths (* * char)) (n (* int))) void
|
||||
(var full [char 1024])
|
||||
(snprintf full (sizeof full) "%s/%s" root dir)
|
||||
(var d (* DIR) (opendir full))
|
||||
(if (! d)
|
||||
(return))
|
||||
(var ent (* struct dirent) NULL)
|
||||
(while (&& (= ent (readdir d)) (< (* n) MAX-DEPOSIT-FILES))
|
||||
(var name (* const char) (. ent d-name))
|
||||
(if (== [name 0] #\.)
|
||||
(continue))
|
||||
(var rel [char 1024])
|
||||
(if (* dir)
|
||||
(snprintf rel (sizeof rel) "%s/%s" dir name)
|
||||
(snprintf rel (sizeof rel) "%s" name))
|
||||
(var len size-t (strlen name))
|
||||
(if (== (. ent d-type) DT-DIR)
|
||||
(list-files root rel paths n)
|
||||
(&& (> len 5) (== (strcmp (+ name (- len 5)) ".json") 0))
|
||||
(do
|
||||
(= [paths (* n)] (strdup rel))
|
||||
(++ (* n)))))
|
||||
(closedir d))
|
||||
|
||||
;;; GenDeposits.initAssets and initWorldGen, and ProPickWorkSpace's
|
||||
;;; depositsByCode: deposits/*.json in path order, each file's
|
||||
;;; variants in order, children after their parent.
|
||||
(pub fn ores/make ((settings world-settings) (assets-dir (* const char)) (rocks (* const strata)))
|
||||
(* ores)
|
||||
(var o (* ores) (calloc 1 (sizeof ores)))
|
||||
(= (. o granite) (. rocks granite))
|
||||
(= (. o sea-level) (cast (* 0.4313725490196078 (. settings size-y)) int))
|
||||
(var root [char 1024])
|
||||
(snprintf root (sizeof root) "%s/survival/worldgen/deposits" assets-dir)
|
||||
(var paths [* char MAX_DEPOSIT_FILES])
|
||||
(var n int 0)
|
||||
(list-files root "" paths (& n))
|
||||
(qsort paths n (sizeof [paths 0]) by-name)
|
||||
;; TODO sex#60: size with MAX-DEPOSIT-FILES once arrays of a header
|
||||
;; type take a symbolic size.
|
||||
(var files [* cJSON 64])
|
||||
(for (var f int 0) (< f n) (++ f)
|
||||
(var path [char 1024])
|
||||
(snprintf path (sizeof path) "%s/%s" root [paths f])
|
||||
(= [files f] (json-load path))
|
||||
(free [paths f]))
|
||||
|
||||
(var seed i32 (. settings seed))
|
||||
;; the maps, first come first served
|
||||
(for (var f int 0) (< f n) (++ f)
|
||||
(for (var v (* cJSON) (if [files f] (. [files f] child) NULL)) v (= v (. v next))
|
||||
(if (cJSON-IsTrue (cJSON-GetObjectItem v "withOreMap"))
|
||||
(add-map o seed (cJSON-GetStringValue (cJSON-GetObjectItem v "code")) v))
|
||||
(var children (* cJSON) (cJSON-GetObjectItem v "childDeposits"))
|
||||
(for (var c (* cJSON) (if children (. children child) NULL)) c (= c (. c next))
|
||||
;; a child's map takes its parent's parameters
|
||||
(if (cJSON-IsTrue (cJSON-GetObjectItem c "withOreMap"))
|
||||
(add-map o seed (cJSON-GetStringValue (cJSON-GetObjectItem c "code")) v)))))
|
||||
;; the readings, last come last served
|
||||
(for (var f int 0) (< f n) (++ f)
|
||||
(for (var v (* cJSON) (if [files f] (. [files f] child) NULL)) v (= v (. v next))
|
||||
(if (cJSON-IsTrue (cJSON-GetObjectItem v "withOreMap"))
|
||||
(set-reading o v false seed rocks))
|
||||
(var children (* cJSON) (cJSON-GetObjectItem v "childDeposits"))
|
||||
(for (var c (* cJSON) (if children (. children child) NULL)) c (= c (. c next))
|
||||
(if (cJSON-IsTrue (cJSON-GetObjectItem c "withOreMap"))
|
||||
(set-reading o c true seed rocks)))))
|
||||
(for (var f int 0) (< f n) (++ f)
|
||||
(if [files f] (cJSON-Delete [files f])))
|
||||
(return o))
|
||||
|
||||
(pub fn ores/free ((o (* ores))) void
|
||||
(for (var i int 0) (< i (. o count)) (++ i)
|
||||
(free (. [(. o minerals) i] wobble-x))
|
||||
(free (. [(. o minerals) i] wobble-z)))
|
||||
(free o))
|
||||
|
||||
(pub fn ores/find ((o (* const ores)) (code (* const char))) int
|
||||
(for (var i int 0) (< i (. o count)) (++ i)
|
||||
(if (== (strcmp (. [(. o minerals) i] code) code) 0)
|
||||
(return i)))
|
||||
(return -1))
|
||||
|
||||
;;; Ore maps ---------------------------------------------------------
|
||||
|
||||
(fn smooth-step ((x float)) float
|
||||
(return (* x x (- (cast 3 float) (* (cast 2 float) x)))))
|
||||
|
||||
(fn lerp-byte ((t float) (a int) (b int)) int
|
||||
(return (cast (cast (+ (* (- (cast 1 float) t) (cast a float)) (* t (cast b float))) int) u8)))
|
||||
|
||||
;;; NoiseOre.GetRandomOre: density in the low byte, hyper-rich at 256,
|
||||
;;; quality at 1024 and 2048.
|
||||
(fn random-ore ((r (* lcg))) int
|
||||
(var rnd int (.next-int r 1024))
|
||||
(var quality int 0)
|
||||
(if (> (.next-int r 2) 0)
|
||||
(= quality 1)
|
||||
(if (> (.next-int r 50) 15) (= quality 0) (= quality 2)))
|
||||
(= quality (<< quality 10))
|
||||
(if (< rnd 1) (return (c-bit-or quality 256 255)))
|
||||
(if (< rnd 30) (return (c-bit-or quality 255)))
|
||||
(if (< rnd 105) (return (c-bit-or quality (+ 75 (.next-int r 100)))))
|
||||
(if (< rnd 190) (return (c-bit-or quality (+ 20 (.next-int r 20)))))
|
||||
(return 0))
|
||||
|
||||
(fn max4 ((a int) (b int) (c int) (d int) (mask int)) int
|
||||
(var m int (& a mask))
|
||||
(if (> (& b mask) m) (= m (& b mask)))
|
||||
(if (> (& c mask) m) (= m (& c mask)))
|
||||
(if (> (& d mask) m) (= m (& d mask)))
|
||||
(return m))
|
||||
|
||||
;;; NoiseOre.GetLerpedOreValueAt.
|
||||
(fn lerped-ore ((x double) (z double) (cache (* const int)) (w int) (contrast float)
|
||||
(sub float)) int
|
||||
(var xi int (cast x int))
|
||||
(var zi int (cast z int))
|
||||
(var lt int [cache (+ (* zi w) xi)])
|
||||
(var rt int [cache (+ (* zi w) xi 1)])
|
||||
(var lb int [cache (+ (* (+ zi 1) w) xi)])
|
||||
(var rb int [cache (+ (* (+ zi 1) w) xi 1)])
|
||||
(var fx float (smooth-step (cast (- x xi) float)))
|
||||
(var fz float (smooth-step (cast (- z zi) float)))
|
||||
(var top int (lerp-byte fx (& lt 255) (& rt 255)))
|
||||
(var bottom int (lerp-byte fx (& lb 255) (& rb 255)))
|
||||
(var v float (cast (lerp-byte fz top bottom) float))
|
||||
(var c float (- (+ (* (- v (cast 128 float)) contrast) (cast 128 float)) sub))
|
||||
(if (< c (cast 0 float)) (= c 0))
|
||||
(if (> c (cast 255 float)) (= c 255))
|
||||
(var val int (cast (cast c int) u8))
|
||||
(if (== val 0)
|
||||
(return 0))
|
||||
;; TODO sex#47: write the masks (0xFF0000, 0xFF00) in hex once there
|
||||
;; are hex literals.
|
||||
(return (c-bit-or val (max4 lt rt lb rb 16711680) (max4 lt rt lb rb 65280))))
|
||||
|
||||
;;; MapLayerOre.GenLayer.
|
||||
(fn gen-unwobbled ((m (* const mineral)) (x0 int) (z0 int) (size-x int) (size-z int)
|
||||
(out (* int))) void
|
||||
(var noise lcg (. m noise))
|
||||
(var scale float (. m scale))
|
||||
(var cache-w int (+ (cast (ceil (cast (/ (cast size-x float) scale) double)) int) 1))
|
||||
(var cache-h int (+ (cast (ceil (cast (/ (cast size-z float) scale) double)) int) 1))
|
||||
(var cx int (cast (/ (cast x0 float) scale) int))
|
||||
(var cz int (cast (/ (cast z0 float) scale) int))
|
||||
(var cache (* int) (malloc (* cache-w cache-h (sizeof int))))
|
||||
(for (var x int 0) (< x cache-w) (++ x)
|
||||
(for (var z int 0) (< z cache-h) (++ z)
|
||||
(.init-position (& noise) (+ cx x) (+ cz z))
|
||||
(= [cache (+ (* z cache-w) x)] (random-ore (& noise)))))
|
||||
(for (var x int 0) (< x size-x) (++ x)
|
||||
(for (var z int 0) (< z size-z) (++ z)
|
||||
(= [out (+ (* z size-x) x)]
|
||||
(lerped-ore (/ x (cast scale double)) (/ z (cast scale double)) cache cache-w
|
||||
(. m contrast) (. m sub)))))
|
||||
(free cache))
|
||||
|
||||
;;; MapLayerPerlinWobble over MapLayerOre, for region (rx, rz): the map
|
||||
;;; DepositVariant.OnMapRegionGen stores, 33 pixels a side with one of
|
||||
;;; padding at the bottom right.
|
||||
(pub fn ores/map ((o (* const ores)) (i int) (rx int) (rz int) (out (* int-map))) void
|
||||
(var m (* const mineral) (& [(. o minerals) i]))
|
||||
(var size int (+ ORE-MAP-SIZE 1))
|
||||
(var x0 int (* rx ORE-MAP-SIZE))
|
||||
(var z0 int (* rz ORE-MAP-SIZE))
|
||||
(var intensity float (* (cast ORE-WOBBLE-SCALE float) (cast 0.15 float)))
|
||||
(var margin int (cast (ceil (cast intensity double)) int))
|
||||
(var pw int (+ size (* 2 margin)))
|
||||
(var in (* int) (malloc (* pw pw (sizeof int))))
|
||||
(gen-unwobbled m (- x0 margin) (- z0 margin) pw pw in)
|
||||
(= (. out size) size)
|
||||
(= (. out pad-tl) 0)
|
||||
(= (. out pad-br) 1)
|
||||
(= (. out data) (malloc (* size size (sizeof i32))))
|
||||
(for (var y int 0) (< y size) (++ y)
|
||||
(for (var x int 0) (< x size) (++ x)
|
||||
(var nx double (+ x0 x margin))
|
||||
(var nz double (+ z0 y margin))
|
||||
(var ox int (cast (* intensity (.noise-2d (. m wobble-x) nx nz)) int))
|
||||
(var oz int (cast (* intensity (.noise-2d (. m wobble-z) nx nz)) int))
|
||||
(var sx int (% (+ (% (+ x ox (/ margin 2)) pw) pw) pw))
|
||||
(var sz int (% (+ (% (+ y oz (/ margin 2)) pw) pw) pw))
|
||||
(= [(. out data) (+ (* y size) x)] [in (+ (* sz pw) sx)])))
|
||||
(free in))
|
||||
|
||||
;;; Readings ---------------------------------------------------------
|
||||
|
||||
;;; IntDataMap2D.GetUnpaddedColorLerped, the low byte only.
|
||||
(fn ore-factor ((map (* const int-map)) (x int) (z int)) double
|
||||
(var inner int (- (. map size) (. map pad-tl) (. map pad-br)))
|
||||
(var px float (* (/ (cast (% x 512) float) (cast 512 float)) (cast inner float)))
|
||||
(var pz float (* (/ (cast (% z 512) float) (cast 512 float)) (cast inner float)))
|
||||
(var ix int (cast px int))
|
||||
(var iz int (cast pz int))
|
||||
(var fx float (- px (cast ix float)))
|
||||
(var fz float (- pz (cast iz float)))
|
||||
(var i int (+ (* (+ iz (. map pad-tl)) (. map size)) ix (. map pad-tl)))
|
||||
(var lt float (cast (& [(. map data) i] 255) float))
|
||||
(var rt float (cast (& [(. map data) (+ i 1)] 255) float))
|
||||
(var lb float (cast (& [(. map data) (+ i (. map size))] 255) float))
|
||||
(var rb float (cast (& [(. map data) (+ i (. map size) 1)] 255) float))
|
||||
(var top float (+ lt (* (- rt lt) fx)))
|
||||
(var bottom float (+ lb (* (- rb lb) fx)))
|
||||
(var v int (& (cast (+ top (* (- bottom top) fz)) int) 255))
|
||||
(return (/ v 255.0)))
|
||||
|
||||
;;; The pick's reading of mineral I at column (x, z): MAP is the
|
||||
;;; mineral's ore map of the column's region, COLUMN the column's
|
||||
;;; strata up to its surface at HEIGHT.
|
||||
(pub fn ores/reading ((o (* const ores)) (i int) (map (* const int-map)) (x int) (z int)
|
||||
(column (* const u8)) (height int)) mineral-reading
|
||||
(var r mineral-reading #(mineral-reading : 0 0))
|
||||
(var m (* const mineral) (& [(. o minerals) i]))
|
||||
(if (|| (! (. m readable)) (< height 1))
|
||||
(return r))
|
||||
;; GetYMinMax
|
||||
(var miny double 0)
|
||||
(var maxy double 0)
|
||||
(if (== (. m place) PLACE-FOLLOW-SURFACE)
|
||||
(do
|
||||
(= miny (* (natfloat-min (& (. m y))) (cast height float)))
|
||||
(= maxy height))
|
||||
(== (. m place) PLACE-FOLLOW-SEALEVEL)
|
||||
(do
|
||||
(= miny (natfloat-min (& (. m y))))
|
||||
(= maxy (natfloat-max (& (. m y)))))
|
||||
(do
|
||||
(= miny (- height (natfloat-max (& (. m y)))))
|
||||
(= maxy height)))
|
||||
;; oreBearingBlockQuantityRelative over the pick's column, y below
|
||||
;; the surface; it has the default rock at y = 0, not the mantle
|
||||
(var q int 0)
|
||||
(for (var y int 0) (< y height) (++ y)
|
||||
(if (|| (< y miny) (> y maxy))
|
||||
(continue))
|
||||
(var rock int (if (== y 0) (. o granite) [column y]))
|
||||
(if (&& (< rock 32) (!= (& (. m bearing) (<< (cast 1 u32) rock)) 0))
|
||||
(++ q)))
|
||||
(var rock-factor double (/ (cast q double) height))
|
||||
(= (. r total) (* (ore-factor map x z) rock-factor))
|
||||
(var blocks int (* height 1024))
|
||||
(= (. r ppt) (* (/ (* (. r total) (. m abs-avg)) blocks) 1000))
|
||||
(return r))
|
||||
|
||||
;;; The category the pick words a reading in: 0 nothing, 1 miniscule
|
||||
;;; amounts, 2 very poor to 7 ultra high.
|
||||
(pub fn ores/category ((total double)) int
|
||||
(if (<= total 0.002)
|
||||
(return 0))
|
||||
(if (<= total 0.025)
|
||||
(return 1))
|
||||
(var k double (* total (cast 7.5 float)))
|
||||
(if (> k 5) (= k 5))
|
||||
(return (+ 2 (cast k int))))
|
||||
97
src/save.sex
97
src/save.sex
@@ -26,13 +26,19 @@
|
||||
|
||||
(pub record story-location ((code [char 64]) (x i32) (y i32) (z i32)))
|
||||
|
||||
;;; One mineral of a prospecting pick reading a player took: where,
|
||||
;;; and the reading's TotalFactor and PartsPerThousand.
|
||||
(pub record pick-reading ((x int) (y int) (z int) (code [char 32]) (total double) (ppt double)))
|
||||
|
||||
(pub record save
|
||||
((db (* sqlite3)) (seed i32) (size-x i32) (size-y i32) (size-z i32)
|
||||
(config-keys (* * char)) (config-values (* * char)) (config-count int)
|
||||
(block-codes (* * char)) (block-count int)
|
||||
;; TODO sex#50: write MAX-STORIES once constants in array types are
|
||||
;; kebab-converted.
|
||||
(stories [story-location MAX_STORIES]) (story-count int)))
|
||||
(stories [story-location MAX_STORIES]) (story-count int)
|
||||
;; every player's stored pick readings
|
||||
(pick-readings (* pick-reading)) (pick-reading-count int)))
|
||||
|
||||
;;; Map regions and map chunks share one key: x in the low 27 bits,
|
||||
;;; z above them.
|
||||
@@ -172,6 +178,59 @@
|
||||
(.skip (& body) wire))))
|
||||
(++ (. s story-count))))
|
||||
|
||||
(fn read-double ((r (* pb))) double
|
||||
(var bits u64 (read-le r 8))
|
||||
(var d double)
|
||||
(memcpy (& d) (& bits) 8)
|
||||
(return d))
|
||||
|
||||
(fn add-pick-reading ((s (* save)) (reading pick-reading)) void
|
||||
(var n int (. s pick-reading-count))
|
||||
(= (. s pick-readings) (realloc (. s pick-readings) (* (+ n 1) (sizeof pick-reading))))
|
||||
(= [(. s pick-readings) n] reading)
|
||||
(= (. s pick-reading-count) (+ n 1)))
|
||||
|
||||
;;; oreMapMarkers-PLAYER: List<PropickReading>, entries {1: position
|
||||
;;; {1: x, 2: y, 3: z}, 2: {1: code, 2: {2: total, 3: ppt}}*}.
|
||||
(fn read-pick-readings ((s (* save)) (r pb)) void
|
||||
(var wire int)
|
||||
(while (> (.field (& r) (& wire)) 0)
|
||||
(var body pb (.bytes (& r)))
|
||||
(var at pick-reading)
|
||||
(memset (& at) 0 (sizeof at))
|
||||
(var f u32)
|
||||
(while (> (= f (.field (& body) (& wire))) 0)
|
||||
(if (== f 1)
|
||||
(do
|
||||
(var position pb (.bytes (& body)))
|
||||
(var g u32)
|
||||
(while (> (= g (.field (& position) (& wire))) 0)
|
||||
(if (== g 1) (= (. at x) (cast (read-double (& position)) int))
|
||||
(== g 2) (= (. at y) (cast (read-double (& position)) int))
|
||||
(== g 3) (= (. at z) (cast (read-double (& position)) int))
|
||||
(.skip (& position) wire))))
|
||||
(== f 2)
|
||||
(do
|
||||
(var entry pb (.bytes (& body)))
|
||||
(var reading pick-reading at)
|
||||
(var g u32)
|
||||
(while (> (= g (.field (& entry) (& wire))) 0)
|
||||
(if (== g 1)
|
||||
(do
|
||||
(var code pb (.bytes (& entry)))
|
||||
(snprintf (. reading code) 32 "%.*s" (cast (.len code) int) (. code p)))
|
||||
(== g 2)
|
||||
(do
|
||||
(var value pb (.bytes (& entry)))
|
||||
(var h u32)
|
||||
(while (> (= h (.field (& value) (& wire))) 0)
|
||||
(if (== h 2) (= (. reading total) (read-double (& value)))
|
||||
(== h 3) (= (. reading ppt) (read-double (& value)))
|
||||
(.skip (& value) wire))))
|
||||
(.skip (& entry) wire)))
|
||||
(add-pick-reading s reading))
|
||||
(.skip (& body) wire)))))
|
||||
|
||||
;;; Game data --------------------------------------------------------
|
||||
|
||||
(fn read-gamedata ((s (* save)) (r pb)) void
|
||||
@@ -194,7 +253,10 @@
|
||||
(== g 2) (= value (.bytes (& entry)))
|
||||
(.skip (& entry) wire)))
|
||||
(if (.equals key "BlockIDs") (read-block-ids s value)
|
||||
(.equals key "storystructurelocations") (read-stories s value)))
|
||||
(.equals key "storystructurelocations") (read-stories s value)
|
||||
(&& (. key p) (>= (.len key) 14)
|
||||
(== (strncmp (cast (. key p) (* const char)) "oreMapMarkers-" 14) 0))
|
||||
(read-pick-readings s value)))
|
||||
(.skip (& r) wire))))
|
||||
|
||||
(fn query-blob ((s (* const save)) (sql (* const char)) (key i64)
|
||||
@@ -243,6 +305,7 @@
|
||||
(for (var i int 0) (< i (. s block-count)) (++ i)
|
||||
(free [(. s block-codes) i]))
|
||||
(free (. s block-codes))
|
||||
(free (. s pick-readings))
|
||||
(sqlite3-close (. s db))
|
||||
(free s))
|
||||
|
||||
@@ -299,6 +362,36 @@
|
||||
(sqlite3-finalize stmt)
|
||||
(return found))
|
||||
|
||||
;;; ServerMapRegion field 8, OreMaps: one {1: code, 2: IntDataMap2D}
|
||||
;;; entry per mineral. Fills up to MAX of CODES (each strdup'd) and
|
||||
;;; MAPS, and returns how many; -1 when the save has no such region.
|
||||
(pub fn save/ore-maps ((s (* const save)) (rx i32) (rz i32) (codes (* * char)) (maps (* int-map))
|
||||
(max int)) int
|
||||
(var stmt (* sqlite3-stmt) NULL)
|
||||
(var r pb (query-blob s "select data from mapregion where position = ?1"
|
||||
(position rx rz) (& stmt)))
|
||||
(if (. r err)
|
||||
(do (sqlite3-finalize stmt) (return -1)))
|
||||
(var n int 0)
|
||||
(var wire int)
|
||||
(var f u32)
|
||||
(while (> (= f (.field (& r) (& wire))) 0)
|
||||
(if (|| (!= f 8) (>= n max))
|
||||
(do (.skip (& r) wire) (continue)))
|
||||
(var entry pb (.bytes (& r)))
|
||||
(= [codes n] NULL)
|
||||
(= [maps n] #(int-map : NULL 0 0 0))
|
||||
(var g u32)
|
||||
(while (> (= g (.field (& entry) (& wire))) 0)
|
||||
(if (== g 1) (= [codes n] (strndup-pb (.bytes (& entry))))
|
||||
(== g 2) (read-int-map (.bytes (& entry)) (& [maps n]))
|
||||
(.skip (& entry) wire)))
|
||||
(if [codes n]
|
||||
(++ n)
|
||||
(free (. [maps n] data))))
|
||||
(sqlite3-finalize stmt)
|
||||
(return n))
|
||||
|
||||
;;; Map chunks -------------------------------------------------------
|
||||
|
||||
;;; A repeated ushort field arrives one value per field, or packed.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
;;; Finds the block nearest a point where one of a set of rocks lies, at
|
||||
;;; the surface, at a depth below it or at a Y.
|
||||
;;; the surface, at a depth below it, at a Y or at any depth; or where
|
||||
;;; the prospecting pick reads a mineral at least so high.
|
||||
;;;
|
||||
;;; Regions are taken in order of their distance from the point and
|
||||
;;; sampled every 16 blocks by several threads at once, each with its
|
||||
@@ -23,8 +24,12 @@
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import ores)
|
||||
|
||||
(pub define SEARCH-RADIUS-REGIONS 24)
|
||||
;;; The mode that looks for a mineral: the value is the mineral, the
|
||||
;;; mask the least reading category.
|
||||
(pub define SEARCH-MINERAL 4)
|
||||
(define SEARCH-STEP 16)
|
||||
(define MAX-SEARCH-THREADS 16)
|
||||
|
||||
@@ -50,6 +55,12 @@
|
||||
(var b (* const region-order) pb)
|
||||
(return (- (> (. a distance) (. b distance)) (< (. a distance) (. b distance)))))
|
||||
|
||||
;;; A thread's generators, and the searched mineral's ore map of the
|
||||
;;; region it last scanned in.
|
||||
(record scanner
|
||||
((tr (* terra)) (rocks (* strata)) (minerals (* ores)) (column (* u8))
|
||||
(ore-map int-map) (ore-rx int) (ore-rz int)))
|
||||
|
||||
(fn region-distance ((s (* const search)) (rx int) (rz int)) double
|
||||
(var x0 double (* rx 512.0))
|
||||
(var z0 double (* rz 512.0))
|
||||
@@ -70,6 +81,32 @@
|
||||
(fn matches ((s (* const search)) (rock int)) bool
|
||||
(return (&& (>= rock 0) (< rock 32) (!= (& (. s mask) (<< (cast 1 u32) rock)) 0))))
|
||||
|
||||
;;; Whether column (x, z), with the strata in the scanner's column,
|
||||
;;; holds what is searched for: a rock where the mode looks, at any
|
||||
;;; depth (mode 3) anywhere from y = 1 to the surface; or a reading of
|
||||
;;; the mineral of at least the mask's category.
|
||||
(fn column-matches ((s (* const search)) (sc (* scanner)) (x int) (z int) (height int)) bool
|
||||
(var column (* const u8) (. sc column))
|
||||
(if (== (. s mode) SEARCH-MINERAL)
|
||||
(do
|
||||
(var rx int (/ x 512))
|
||||
(var rz int (/ z 512))
|
||||
(if (|| (! (. sc ore-map data)) (!= (. sc ore-rx) rx) (!= (. sc ore-rz) rz))
|
||||
(do
|
||||
(free (. sc ore-map data))
|
||||
(ores/map (. sc minerals) (. s value) rx rz (& (. sc ore-map)))
|
||||
(= (. sc ore-rx) rx)
|
||||
(= (. sc ore-rz) rz)))
|
||||
(var r mineral-reading (ores/reading (. sc minerals) (. s value) (& (. sc ore-map)) x z
|
||||
column height))
|
||||
(return (>= (ores/category (. r total)) (cast (. s mask) int)))))
|
||||
(if (!= (. s mode) 3)
|
||||
(return (matches s (rock-at column height (. s mode) (. s value)))))
|
||||
(for (var y int 1) (<= y height) (++ y)
|
||||
(if (matches s [column y])
|
||||
(return true)))
|
||||
(return false))
|
||||
|
||||
(fn offer ((s (* search)) (x int) (z int)) void
|
||||
(var dx double (- (+ x 0.5) (. s x)))
|
||||
(var dz double (- (+ z 0.5) (. s z)))
|
||||
@@ -84,24 +121,30 @@
|
||||
(pthread-mutex-unlock (& (. s lock))))
|
||||
|
||||
;;; Every STEP-th column of chunk (cx, cz) against the mask.
|
||||
(fn scan-chunk ((s (* search)) (tr (* terra)) (rocks (* strata)) (cx int) (cz int) (step int)
|
||||
(column (* u8))) void
|
||||
(fn scan-chunk ((s (* search)) (sc (* scanner)) (cx int) (cz int) (step int)) void
|
||||
(var heights [u16 1024])
|
||||
(terra/chunk-heights tr cx cz step heights)
|
||||
(terra/chunk-heights (. sc tr) cx cz step heights)
|
||||
(for (var lz int 0) (< lz 32) (+= lz step)
|
||||
(for (var lx int 0) (< lx 32) (+= lx step)
|
||||
(var h int [heights (+ (* lz 32) lx)])
|
||||
(strata/column rocks cx cz lx lz h column)
|
||||
(if (matches s (rock-at column h (. s mode) (. s value)))
|
||||
(offer s (+ (* cx 32) lx) (+ (* cz 32) lz))))))
|
||||
(var x int (+ (* cx 32) lx))
|
||||
(var z int (+ (* cz 32) lz))
|
||||
(strata/column (. sc rocks) cx cz lx lz h (. sc column))
|
||||
(if (column-matches s sc x z h)
|
||||
(offer s x z)))))
|
||||
|
||||
(fn search-thread ((arg (* void))) (* void)
|
||||
(var s (* search) arg)
|
||||
(var g (* worldgen) (worldgen/make (. s settings) (. s assets-dir)))
|
||||
(var tr (* terra) (if g (terra/make g (. s rivers)) NULL))
|
||||
(var rocks (* strata) (if g (strata/make g (. s assets-dir)) NULL))
|
||||
(var column (* u8) (malloc (+ (. s settings size-y) 1)))
|
||||
(while (&& tr rocks)
|
||||
(var sc scanner)
|
||||
(memset (& sc) 0 (sizeof sc))
|
||||
(= (. sc tr) (if g (terra/make g (. s rivers)) NULL))
|
||||
(= (. sc rocks) (if g (strata/make g (. s assets-dir)) NULL))
|
||||
(if (&& (. sc rocks) (== (. s mode) SEARCH-MINERAL))
|
||||
(= (. sc minerals) (ores/make (. s settings) (. s assets-dir) (. sc rocks))))
|
||||
(= (. sc column) (malloc (+ (. s settings size-y) 1)))
|
||||
(var ready bool (&& (. sc tr) (. sc rocks) (|| (!= (. s mode) SEARCH-MINERAL) (. sc minerals))))
|
||||
(while ready
|
||||
(pthread-mutex-lock (& (. s lock)))
|
||||
(var i int (. s next))
|
||||
(var stop bool (|| (. s cancel) (>= i (. s region-count))))
|
||||
@@ -117,7 +160,7 @@
|
||||
(var rz int [(. s regions) (+ (* i 2) 1)])
|
||||
(for (var cz int 0) (< cz 16) (++ cz)
|
||||
(for (var cx int 0) (< cx 16) (++ cx)
|
||||
(scan-chunk s tr rocks (+ (* rx 16) cx) (+ (* rz 16) cz) SEARCH-STEP column)))
|
||||
(scan-chunk s (& sc) (+ (* rx 16) cx) (+ (* rz 16) cz) SEARCH-STEP)))
|
||||
(pthread-mutex-lock (& (. s lock)))
|
||||
(++ (. s done-count))
|
||||
(pthread-mutex-unlock (& (. s lock))))
|
||||
@@ -131,16 +174,18 @@
|
||||
(var bx int (. s best-x))
|
||||
(var bz int (. s best-z))
|
||||
(pthread-mutex-unlock (& (. s lock)))
|
||||
(if (&& last tr rocks)
|
||||
(if (&& last ready)
|
||||
(for (var dz int -1) (<= dz 1) (++ dz)
|
||||
(for (var dx int -1) (<= dx 1) (++ dx)
|
||||
(var cx int (+ (/ bx 32) dx))
|
||||
(var cz int (+ (/ bz 32) dz))
|
||||
(if (&& (>= cx 0) (>= cz 0) (< (* cx 32) (. s settings size-x)) (< (* cz 32) (. s settings size-z)))
|
||||
(scan-chunk s tr rocks cx cz 1 column)))))
|
||||
(free column)
|
||||
(if rocks (strata/free rocks))
|
||||
(if tr (terra/free tr))
|
||||
(scan-chunk s (& sc) cx cz 1)))))
|
||||
(free (. sc column))
|
||||
(free (. sc ore-map data))
|
||||
(if (. sc minerals) (ores/free (. sc minerals)))
|
||||
(if (. sc rocks) (strata/free (. sc rocks)))
|
||||
(if (. sc tr) (terra/free (. sc tr)))
|
||||
(if g (worldgen/free g))
|
||||
(return NULL))
|
||||
|
||||
@@ -162,7 +207,9 @@
|
||||
(free (. s regions))
|
||||
(= (. s regions) NULL))
|
||||
|
||||
;;; Starts looking for MASK's rocks nearest (x, z); see search/poll.
|
||||
;;; Starts looking for MASK's rocks nearest (x, z), or in mode
|
||||
;;; SEARCH-MINERAL for mineral VALUE read as category MASK or higher;
|
||||
;;; see search/poll.
|
||||
(pub fn search/start ((s (* search)) (settings world-settings) (rivers river-config)
|
||||
(assets-dir (* const char)) (mode int) (value int) (mask u32)
|
||||
(x double) (z double) (threads int)) void
|
||||
|
||||
@@ -26,16 +26,24 @@
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import ores)
|
||||
|
||||
(pub define MAX-TILES 65536)
|
||||
;;; Not worldgen maps: Rivers' distance to the nearest river, the
|
||||
;;; terrain height, and the rock at the surface, at a depth or at a Y.
|
||||
;;; terrain height, and the rock at the surface, at a depth or at a Y,
|
||||
;;; or where one rock lies at any depth; and the prospecting pick's
|
||||
;;; reading of one mineral.
|
||||
(pub define LAYER-RIVERS 6)
|
||||
(pub define LAYER-HEIGHT 7)
|
||||
(pub define LAYER-ROCK 8)
|
||||
(pub define LAYER-MINERAL 9)
|
||||
(pub define ROCK-AT-SURFACE 0)
|
||||
(pub define ROCK-AT-DEPTH 1)
|
||||
(pub define ROCK-AT-Y 2)
|
||||
;;; The param's value is then the rock's index.
|
||||
(pub define ROCK-ANY-DEPTH 3)
|
||||
;;; Mineral tile values: this plus the reading's category.
|
||||
(pub define MINERAL-VALUE-BASE 64)
|
||||
;;; Rock tile values besides rock indices.
|
||||
(pub define VALUE-WATER 253)
|
||||
(pub define VALUE-AIR 254)
|
||||
@@ -51,11 +59,13 @@
|
||||
(define TILE-DRAWN 4)
|
||||
|
||||
;;; STRATUM is the stratum for MAP-STRATA, the samples per region side
|
||||
;;; for the sampled layers; PARAM is the rock layer's mode * 1024 + value.
|
||||
;;; for the sampled layers; PARAM is the rock layer's mode * 1024 + value,
|
||||
;;; or the mineral layer's mineral.
|
||||
(pub record tile-key ((map int) (stratum int) (rx int) (rz int) (param int)))
|
||||
|
||||
;;; Rock tiles keep their VALUES, rock indices, and are coloured from
|
||||
;;; the palette on upload, so a new palette only re-uploads them.
|
||||
;;; Rock and mineral tiles keep their VALUES, rock indices or reading
|
||||
;;; categories, and are coloured from the palette on upload, so a new
|
||||
;;; palette only re-uploads them.
|
||||
(pub record tile
|
||||
((key tile-key) (state int) (generation int) (size int) (pixels (* u32)) (values (* u8))
|
||||
(texture (* SDL-Texture)) (last-used u64)))
|
||||
@@ -280,7 +290,9 @@
|
||||
(return px))
|
||||
|
||||
;;; The rock tile: per sample, the rock at the surface, at a depth
|
||||
;;; below it, or at an absolute Y (water or air above the surface).
|
||||
;;; below it, or at an absolute Y (water or air above the surface); or,
|
||||
;;; at any depth, the rock where the column holds it at all and air
|
||||
;;; where it doesn't.
|
||||
(fn render-rocks ((tr (* terra)) (rocks (* strata)) (k tile-key) (size (* int))) (* u8)
|
||||
(var res int (. k stratum))
|
||||
(var step int (/ 512 res))
|
||||
@@ -308,7 +320,10 @@
|
||||
(if (== mode ROCK-AT-DEPTH) (= y (- h value))
|
||||
(== mode ROCK-AT-Y) (= y value))
|
||||
(var v u8 VALUE-AIR)
|
||||
(if (< y 0) (= v ROCK-MANTLE)
|
||||
(if (== mode ROCK-ANY-DEPTH)
|
||||
(for (var ry int 1) (<= ry h) (++ ry)
|
||||
(if (== [column ry] value) (= v (cast value u8))))
|
||||
(< y 0) (= v ROCK-MANTLE)
|
||||
(<= y h) (= v [column y])
|
||||
(< y (. tr sea-level)) (= v VALUE-WATER))
|
||||
(= [out (+ (* (+ (/ (* cz 32) step) dz) res) (/ (* cx 32) step) dx)] v)))))
|
||||
@@ -316,6 +331,41 @@
|
||||
(= (* size) res)
|
||||
(return out))
|
||||
|
||||
;;; The mineral tile: per sample, MINERAL-VALUE-BASE plus the category
|
||||
;;; of the pick's reading there.
|
||||
(fn render-minerals ((tr (* terra)) (rocks (* strata)) (o (* ores)) (k tile-key) (size (* int)))
|
||||
(* u8)
|
||||
(var res int (. k stratum))
|
||||
(var step int (/ 512 res))
|
||||
(var map int-map)
|
||||
(ores/map o (. k param) (. k rx) (. k rz) (& map))
|
||||
(var out (* u8) (malloc (* res res)))
|
||||
(var heights [u16 1024])
|
||||
(var column (* u8) (malloc (+ (. tr size-y) 1)))
|
||||
(var per-chunk int (/ 32 step))
|
||||
(if (< per-chunk 1) (= per-chunk 1))
|
||||
(for (var cz int 0) (< cz 16) (++ cz)
|
||||
(for (var cx int 0) (< cx 16) (++ cx)
|
||||
(if (|| (!= (% (* cx 32) step) 0) (!= (% (* cz 32) step) 0))
|
||||
(continue))
|
||||
(var chunk-x int (+ (* (. k rx) 16) cx))
|
||||
(var chunk-z int (+ (* (. k rz) 16) cz))
|
||||
(terra/chunk-heights tr chunk-x chunk-z (if (> step 32) 32 step) heights)
|
||||
(for (var dz int 0) (< dz per-chunk) (++ dz)
|
||||
(for (var dx int 0) (< dx per-chunk) (++ dx)
|
||||
(var lx int (* dx step))
|
||||
(var lz int (* dz step))
|
||||
(var h int [heights (+ (* lz 32) lx)])
|
||||
(strata/column rocks chunk-x chunk-z lx lz h column)
|
||||
(var r mineral-reading (ores/reading o (. k param) (& map) (+ (* chunk-x 32) lx)
|
||||
(+ (* chunk-z 32) lz) column h))
|
||||
(= [out (+ (* (+ (/ (* cz 32) step) dz) res) (/ (* cx 32) step) dx)]
|
||||
(cast (+ MINERAL-VALUE-BASE (ores/category (. r total))) u8))))))
|
||||
(free column)
|
||||
(free (. map data))
|
||||
(= (* size) res)
|
||||
(return out))
|
||||
|
||||
;;; Workers -------------------------------------------------------
|
||||
|
||||
(fn worker-main ((arg (* void))) (* void)
|
||||
@@ -326,6 +376,7 @@
|
||||
(memset (& cache) 0 (sizeof cache))
|
||||
(var tr (* terra) NULL)
|
||||
(var rocks (* strata) NULL)
|
||||
(var minerals (* ores) NULL)
|
||||
(pthread-mutex-lock (& (. t lock)))
|
||||
(while (! (. t quit))
|
||||
(if (>= (. t queue-pos) (. t queue-len))
|
||||
@@ -348,6 +399,8 @@
|
||||
(do
|
||||
(if tr (terra/free tr))
|
||||
(= tr NULL)
|
||||
(if minerals (ores/free minerals))
|
||||
(= minerals NULL)
|
||||
(if rocks (strata/free rocks))
|
||||
(= rocks NULL)
|
||||
(if g (worldgen/free g))
|
||||
@@ -355,6 +408,7 @@
|
||||
(= g (worldgen/make settings (. t assets-dir)))
|
||||
(if g (= tr (terra/make g rivers)))
|
||||
(if g (= rocks (strata/make g (. t assets-dir))))
|
||||
(if rocks (= minerals (ores/make settings (. t assets-dir) rocks)))
|
||||
(= (. cache sampler) (river-sampler/make (& rivers) (. settings size-y)))
|
||||
(= g-generation generation)))
|
||||
(var size int 0)
|
||||
@@ -366,6 +420,8 @@
|
||||
(= px (render-heights tr key (& size)))
|
||||
(&& tr rocks (== (. key map) LAYER-ROCK))
|
||||
(= values (render-rocks tr rocks key (& size)))
|
||||
(&& tr rocks minerals (== (. key map) LAYER-MINERAL))
|
||||
(= values (render-minerals tr rocks minerals key (& size)))
|
||||
g
|
||||
(= px (render g key (& size))))
|
||||
|
||||
@@ -382,6 +438,7 @@
|
||||
(if (&& (== generation (. t generation)) (== (. tl state) TILE-WORKING))
|
||||
(= (. tl state) TILE-QUEUED)))))
|
||||
(pthread-mutex-unlock (& (. t lock)))
|
||||
(if minerals (ores/free minerals))
|
||||
(if rocks (strata/free rocks))
|
||||
(if tr (terra/free tr))
|
||||
(if g (worldgen/free g))
|
||||
|
||||
128
src/verify.sex
128
src/verify.sex
@@ -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 time.h)
|
||||
(include stdio.h stdlib.h string.h math.h time.h)
|
||||
;; TODO sex#58: import only the modules used here once an import brings
|
||||
;; the types its interface needs; until then, every dependency, in
|
||||
;; dependency order.
|
||||
@@ -17,9 +17,13 @@
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import ores)
|
||||
(import img)
|
||||
|
||||
(define MAP-KINDS 6)
|
||||
;;; How far below the computed reading the game's may be; see
|
||||
;;; verify-readings.
|
||||
(define READING-SLACK 0.85)
|
||||
|
||||
(var map-names [(* const char) 6] #("landform" "climate" "province" "upheaval" "ocean" "strata"))
|
||||
|
||||
@@ -116,6 +120,128 @@
|
||||
(.release (& [diffs k])))
|
||||
(return failed))
|
||||
|
||||
;;; Regenerates the ore map of every mineral in every region the save
|
||||
;;; stored and compares them; one diff image for all minerals, a region
|
||||
;;; red where any of its ore maps differs.
|
||||
(pub fn verify-ores ((s (* save)) (o (* ores)) (dir (* const char))) int
|
||||
(var e extent (save/extent s "mapregion"))
|
||||
(var cell int 32)
|
||||
(var diff image (image/make (* (+ (- (. e x1) (. e x0)) 1) cell) (* (+ (- (. e z1) (. e z0)) 1) cell)))
|
||||
;; TODO sex#50: write MAX-MINERALS once constants in array types are
|
||||
;; kebab-converted.
|
||||
(var codes [* char MAX_MINERALS])
|
||||
(var want [int-map MAX_MINERALS])
|
||||
(var t tally)
|
||||
(memset (& t) 0 (sizeof t))
|
||||
(var unknown int 0)
|
||||
(for (var rz int (. e z0)) (<= rz (. e z1)) (++ rz)
|
||||
(for (var rx int (. e x0)) (<= rx (. e x1)) (++ rx)
|
||||
(var n int (save/ore-maps s rx rz codes want MAX-MINERALS))
|
||||
(var ox int (* (- rx (. e x0)) cell))
|
||||
(var oz int (* (- rz (. e z0)) cell))
|
||||
(var ok bool true)
|
||||
(for (var i int 0) (< i n) (++ i)
|
||||
(var k int (ores/find o [codes i]))
|
||||
(if (< k 0)
|
||||
(++ unknown)
|
||||
(do
|
||||
(var got int-map)
|
||||
(ores/map o k rx rz (& got))
|
||||
(++ (. t regions))
|
||||
(if (!= (. got size) (. [want i] size))
|
||||
(do (++ (. t size-mismatch)) (= ok false))
|
||||
(for (var p int 0) (< p (* (. got size) (. got size))) (++ p)
|
||||
(++ (. t compared))
|
||||
(if (== [(. got data) p] [(. [want i] data) p])
|
||||
(++ (. t matched))
|
||||
(= ok false))))
|
||||
(free (. got data))))
|
||||
(free [codes i])
|
||||
(free (. [want i] data)))
|
||||
(if (> n 0)
|
||||
(for (var y int 0) (< y cell) (++ y)
|
||||
(for (var x int 0) (< x cell) (++ x)
|
||||
(.set (& diff) (+ ox x) (+ oz y) (if ok (grey 96) 16719904)))))))
|
||||
(var percent double (if (> (. t compared) 0) (/ (* 100.0 (. t matched)) (. t compared)) 0))
|
||||
(printf "%-9s %4d maps %10lld/%-10lld px %8.4f%%%s\n" "ore" (. t regions)
|
||||
(. t matched) (. t compared) percent
|
||||
(if (. t size-mismatch) " (size mismatch)" ""))
|
||||
(if (> unknown 0)
|
||||
(printf "ore %d stored maps of minerals the deposits don't define\n" unknown))
|
||||
(var path [char 1024])
|
||||
(snprintf path (sizeof path) "%s/diff-ore.png" dir)
|
||||
(.write (& diff) path)
|
||||
(.release (& diff))
|
||||
(return (if (|| (!= (. t matched) (. t compared)) (> unknown 0)) 1 0)))
|
||||
|
||||
;;; Recomputes the prospecting pick readings players took in the save
|
||||
;;; and compares each mineral's TotalFactor: per reading, every
|
||||
;;; mineral the save has or this reads above nothing.
|
||||
;;;
|
||||
;;; They can't match exactly. The pick's column already has the ore of
|
||||
;;; the deposits generated in its chunk, which no longer counts as host
|
||||
;;; rock, and the game's Y range is drawn from samples where this takes
|
||||
;;; the distribution's limits. Both only ever make the game's reading
|
||||
;;; lower, so a reading passes when the game's is at most this much
|
||||
;;; below it, and never above.
|
||||
(pub fn verify-readings ((s (* save)) (g (* worldgen)) (config river-config) (rocks (* strata))
|
||||
(o (* ores))) int
|
||||
(if (== (. s pick-reading-count) 0)
|
||||
(do (printf "readings none stored\n") (return 0)))
|
||||
(var t (* terra) (terra/make g config))
|
||||
(var column [u8 1024])
|
||||
(var compared int 0)
|
||||
(var passed int 0)
|
||||
(var same-category int 0)
|
||||
(var unreadable int 0)
|
||||
(var worst double 1)
|
||||
(var i int 0)
|
||||
(while (< i (. s pick-reading-count))
|
||||
;; the minerals of one reading are stored one after another
|
||||
(var at (* pick-reading) (& [(. s pick-readings) i]))
|
||||
(var end int i)
|
||||
(while (&& (< end (. s pick-reading-count)) (== (. [(. s pick-readings) end] x) (. at x))
|
||||
(== (. [(. s pick-readings) end] z) (. at z)))
|
||||
(++ end))
|
||||
(var x int (. at x))
|
||||
(var z int (. at z))
|
||||
(var h int (terra/column-height t x z))
|
||||
(strata/column rocks (/ x 32) (/ z 32) (% x 32) (% z 32) h column)
|
||||
(printf "reading %d, %d: stored height %d, computed %d\n" x z (. at y) h)
|
||||
(for (var k int 0) (< k (. o count)) (++ k)
|
||||
(var m (* mineral) (& [(. o minerals) k]))
|
||||
(var stored (* pick-reading) NULL)
|
||||
(for (var j int i) (< j end) (++ j)
|
||||
(if (== (strcmp (. [(. s pick-readings) j] code) (. m code)) 0)
|
||||
(= stored (& [(. s pick-readings) j]))))
|
||||
(var map int-map)
|
||||
(ores/map o k (/ x 512) (/ z 512) (& map))
|
||||
(var r mineral-reading (ores/reading o k (& map) x z column h))
|
||||
(free (. map data))
|
||||
(var want double (if stored (. stored total) 0))
|
||||
(if (&& (! stored) (== (ores/category (. r total)) 0))
|
||||
(continue))
|
||||
(if (! (. m readable))
|
||||
(do
|
||||
(++ unreadable)
|
||||
(printf " %-14s %9.6f (not read here)\n" (. m code) want)
|
||||
(continue)))
|
||||
(++ compared)
|
||||
;; the game's reading over this one's
|
||||
(var ratio double (if (> (. r total) 0) (/ want (. r total)) 0))
|
||||
(var ok bool (&& (<= want (+ (. r total) 1e-9)) (>= ratio READING-SLACK)))
|
||||
(var category bool (== (ores/category want) (ores/category (. r total))))
|
||||
(if ok (++ passed))
|
||||
(if category (++ same-category))
|
||||
(if (< ratio worst) (= worst ratio))
|
||||
(printf " %-14s %9.6f %9.6f %5.3f %s\n" (. m code) want (. r total) ratio
|
||||
(if ok "ok" "MISMATCH")))
|
||||
(= i end))
|
||||
(terra/free t)
|
||||
(printf "readings %d of %d no higher than computed and within %.0f%% of it (worst %.3f); %d of %d in the same category; %d child deposits not read\n"
|
||||
passed compared (* 100 (- 1 READING-SLACK)) worst same-category compared unreadable)
|
||||
(return (if (== passed compared) 0 1)))
|
||||
|
||||
;;; 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
|
||||
|
||||
347
src/viewer.sex
347
src/viewer.sex
@@ -3,7 +3,8 @@
|
||||
;;;
|
||||
;;; vs-map-viewer [--assets DIR] [--zoom BLOCKS-PER-POINT]
|
||||
;;; [--base ocean|rivers|height] [--overlay NAME]... [--opacity F]
|
||||
;;; [--rock-depth N | --rock-y Y] [--highlight ROCK]... [--find]
|
||||
;;; [--rock-depth N | --rock-y Y | --rock-any] [--highlight ROCK]... [--find]
|
||||
;;; [--mineral CODE] [--min-reading NAME] [--find-mineral]
|
||||
;;; [--probe X Z] [--mouse X Y]
|
||||
;;; [--screenshot FILE.png] [WORLD.vcdbs | serverconfig.json]
|
||||
;;;
|
||||
@@ -25,6 +26,7 @@
|
||||
(import rivers)
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import ores)
|
||||
(import search)
|
||||
(import hover)
|
||||
(import settings)
|
||||
@@ -47,13 +49,17 @@
|
||||
(var base-layers [int 3] #(4 6 7))
|
||||
(var base-names [(* const char) 3] #("ocean" "rivers" "height"))
|
||||
(var base-labels [(* const char) 3] #("Ocean" "Rivers" "Terrain height"))
|
||||
(var overlay-layers [int 6] #(0 1 2 3 5 8))
|
||||
(var overlay-names [(* const char) 6] #("landform" "climate" "province" "upheaval" "strata" "rock"))
|
||||
;;; The Rock overlay's bit in `overlays'.
|
||||
(var overlay-layers [int 7] #(0 1 2 3 5 8 9))
|
||||
(var overlay-names [(* const char) 7]
|
||||
#("landform" "climate" "province" "upheaval" "strata" "rock" "mineral"))
|
||||
;;; The Rock and Minerals overlays' bits in `overlays'.
|
||||
(define ROCK-OVERLAY-BIT 32)
|
||||
(var overlay-labels [(* const char) 6]
|
||||
#("Landform" "Climate" "Geologic province" "Upheaval" "Rock strata thickness" "Rock"))
|
||||
(var rock-mode-names [(* const char) 3] #("Surface" "Depth below surface" "At Y"))
|
||||
(define MINERAL-OVERLAY-BIT 64)
|
||||
(define OVERLAY-COUNT 7)
|
||||
(var overlay-labels [(* const char) 7]
|
||||
#("Landform" "Climate" "Geologic province" "Upheaval" "Rock strata thickness" "Rock"
|
||||
"Minerals"))
|
||||
(var rock-mode-names [(* const char) 4] #("Surface" "Depth below surface" "At Y" "Any depth"))
|
||||
|
||||
;;; Rock colours, roughly as they look in game; others get a stable one.
|
||||
(var rock-colour-codes [(* const char) 15]
|
||||
@@ -67,10 +73,37 @@
|
||||
#(11836044 7236198 3815997 5204794 5926522 12618330 14205834 6186096 10124124 13223864 9067080 15790312 11883310 4871528 8227450))
|
||||
(var climate-names [(* const char) 5] #("temperate" "hot" "warm" "cool" "icy"))
|
||||
|
||||
;;; The pick's reading categories, ores/category's numbering, and their
|
||||
;;; colours on the Minerals overlay.
|
||||
(var reading-names [(* const char) 8]
|
||||
#("none" "miniscule" "very poor" "poor" "decent" "high" "very high" "ultra high"))
|
||||
;; TODO sex#47: write the colours in hex once there are hex literals.
|
||||
(var reading-colours [u32 8]
|
||||
;; Sex has no hex literals: 000000 5A6E7A 3B6FB6 2BA3A3 7BC043 F3C623 F37735 D11141
|
||||
#(0 5926522 3895222 2859939 8110147 15975971 15955765 13701441))
|
||||
;;; Find nearest's least reading, unless set: decent.
|
||||
(define DEFAULT-MIN-READING 4)
|
||||
|
||||
;;; The category NAME names, with a hyphen for a space ("very-high"),
|
||||
;;; from miniscule up; the default for a name it doesn't know.
|
||||
(fn reading-named ((name (* const char))) int
|
||||
(for (var c int 1) (< c 8) (++ c)
|
||||
(var hyphenated [char 16])
|
||||
(snprintf hyphenated (sizeof hyphenated) "%s" [reading-names c])
|
||||
(for (var p (* char) hyphenated) (* p) (++ p)
|
||||
(if (== (* p) #\space) (= (* p) #\-)))
|
||||
(if (== (strcmp hyphenated name) 0)
|
||||
(return c)))
|
||||
(return DEFAULT-MIN-READING))
|
||||
|
||||
;;; The strata of the column clicked last: top down, as (rock, top y,
|
||||
;;; bottom y) runs.
|
||||
;;; bottom y) runs; and the pick's readings there, highest first.
|
||||
;; TODO sex#50: write MAX-MINERALS once constants in array types are
|
||||
;; kebab-converted.
|
||||
(record probe ((valid bool) (x int) (z int) (height int) (count int)
|
||||
(rocks [int 64]) (tops [int 64]) (bottoms [int 64])))
|
||||
(rocks [int 64]) (tops [int 64]) (bottoms [int 64])
|
||||
(reading-count int) (reading-minerals [int MAX_MINERALS])
|
||||
(readings [mineral-reading MAX_MINERALS])))
|
||||
|
||||
(record app
|
||||
((window (* SDL-Window)) (renderer (* SDL-Renderer)) (ctx (* struct nk-context))
|
||||
@@ -87,6 +120,15 @@
|
||||
(coverage [i64 256]) (coverage-total i64)
|
||||
(pins [int 64]) (pin-count int)
|
||||
(search (* search)) (searching bool) (search-status [char 160]) (find-requested bool)
|
||||
;; minerals: the one shown, the readable ones for the panel's list,
|
||||
;; its share of the view per category, and what Find nearest wants
|
||||
(minerals (* ores)) (mineral int) (mineral-code (* const char))
|
||||
;; TODO sex#50: write MAX-MINERALS once constants in array types
|
||||
;; are kebab-converted.
|
||||
(mineral-items [* const char MAX_MINERALS]) (mineral-ids [int MAX_MINERALS])
|
||||
(mineral-item-count int)
|
||||
(mineral-coverage [i64 256]) (mineral-coverage-total i64)
|
||||
(min-reading int) (find-mineral-requested bool) (searching-mineral bool)
|
||||
(show-stories bool) (show-cursor-rock bool)
|
||||
;; what is under the cursor, from the hover worker; and a terrain
|
||||
;; generator of the main thread's own, for probes
|
||||
@@ -214,8 +256,52 @@
|
||||
(= [p i] (c-bit-or 4278190080 c))
|
||||
(if (&& (!= (. a highlight) 0) (== (& (. a highlight) (<< (cast 1 u32) i)) 0))
|
||||
(= [p i] 0)))
|
||||
;; the base shows through where the pick reads nothing
|
||||
(= [p MINERAL-VALUE-BASE] 0)
|
||||
(for (var c int 1) (< c READING-CATEGORIES) (++ c)
|
||||
(= [p (+ MINERAL-VALUE-BASE c)] (c-bit-or 4278190080 [reading-colours c])))
|
||||
(.set-palette (. a tiles) p))
|
||||
|
||||
;;; The highlighted rock when it is the only one, else -1.
|
||||
(fn single-highlight ((a (* app))) int
|
||||
(for (var i int 0) (< i 32) (++ i)
|
||||
(if (== (. a highlight) (<< (cast 1 u32) i))
|
||||
(return i)))
|
||||
(return -1))
|
||||
|
||||
;;; What the rock mode looks for: the depth or Y, the rock at any
|
||||
;;; depth, nothing at the surface.
|
||||
(fn rock-query-value ((a (* app))) int
|
||||
(if (== (. a rock-mode) ROCK-AT-SURFACE) (return 0))
|
||||
(if (== (. a rock-mode) ROCK-ANY-DEPTH) (return (single-highlight a)))
|
||||
(return (. a rock-value)))
|
||||
|
||||
;;; Any depth needs one rock highlighted; without it, back to the
|
||||
;;; surface.
|
||||
(fn fix-rock-mode ((a (* app))) void
|
||||
(if (&& (== (. a rock-mode) ROCK-ANY-DEPTH) (< (single-highlight a) 0))
|
||||
(= (. a rock-mode) ROCK-AT-SURFACE)))
|
||||
|
||||
;;; Takes O as the minerals, keeping the one shown if it is still there.
|
||||
(fn set-minerals ((a (* app)) (o (* ores))) void
|
||||
;; the code may live in the old minerals, so it is looked up first
|
||||
(var code (* const char) (. a mineral-code))
|
||||
(= (. a mineral) (if code (ores/find o code) -1))
|
||||
(if (. a minerals)
|
||||
(ores/free (. a minerals)))
|
||||
(= (. a minerals) o)
|
||||
;; the panel's list: nothing, then every mineral the pick can read
|
||||
(= [(. a mineral-items) 0] "(none)")
|
||||
(= [(. a mineral-ids) 0] -1)
|
||||
(= (. a mineral-item-count) 1)
|
||||
(for (var i int 0) (< i (. o count)) (++ i)
|
||||
(if (. [(. o minerals) i] readable)
|
||||
(do
|
||||
(= [(. a mineral-items) (. a mineral-item-count)] (. [(. o minerals) i] code))
|
||||
(= [(. a mineral-ids) (. a mineral-item-count)] i)
|
||||
(++ (. a mineral-item-count)))))
|
||||
(= (. a mineral-code) (if (>= (. a mineral) 0) (. [(. o minerals) (. a mineral)] code) NULL)))
|
||||
|
||||
;;; Makes SOURCE the world shown: a fresh generator for the panels,
|
||||
;;; and every tile regenerated.
|
||||
(fn apply ((a (* app)) (source world-source)) bool
|
||||
@@ -229,6 +315,7 @@
|
||||
(if (. a rocks)
|
||||
(strata/free (. a rocks)))
|
||||
(= (. a rocks) rocks)
|
||||
(set-minerals a (ores/make (. source settings) (. a assets-dir) rocks))
|
||||
(&= (. a highlight) (- (<< (cast 1 u32) (. rocks rock-count)) 1))
|
||||
(= (. a probe valid) false)
|
||||
(search/stop (. a search))
|
||||
@@ -305,15 +392,17 @@
|
||||
(== layer LAYER-ROCK)
|
||||
(do
|
||||
(= (. k stratum) (height-resolution (. a zoom)))
|
||||
(var value int (. a rock-value))
|
||||
(if (== (. a rock-mode) ROCK-AT-SURFACE) (= value 0))
|
||||
(= (. k param) (+ (* (. a rock-mode) 1024) value))))
|
||||
(= (. k param) (+ (* (. a rock-mode) 1024) (rock-query-value a))))
|
||||
(== layer LAYER-MINERAL)
|
||||
(do
|
||||
(= (. k stratum) (height-resolution (. a zoom)))
|
||||
(= (. k param) (. a mineral))))
|
||||
(return k))
|
||||
|
||||
;;; Adds a value tile's samples that fall inside the visible world
|
||||
;;; rectangle (x0, z0)-(x1, z1) to the coverage counts.
|
||||
(fn count-visible ((a (* app)) (values (* const u8)) (size int) (rx int) (rz int)
|
||||
(x0 double) (z0 double) (x1 double) (z1 double)) void
|
||||
;;; rectangle (x0, z0)-(x1, z1) to COUNTS, per value, and TOTAL.
|
||||
(fn count-visible ((counts (* i64)) (total (* i64)) (values (* const u8)) (size int) (rx int)
|
||||
(rz int) (x0 double) (z0 double) (x1 double) (z1 double)) void
|
||||
(var step double (/ (cast REGION double) size))
|
||||
(var ix0 int (cast (fmax 0 (floor (/ (- x0 (* rx REGION)) step))) int))
|
||||
(var iz0 int (cast (fmax 0 (floor (/ (- z0 (* rz REGION)) step))) int))
|
||||
@@ -321,8 +410,8 @@
|
||||
(var iz1 int (cast (fmin (- size 1) (floor (/ (- z1 (* rz REGION)) step))) int))
|
||||
(for (var z int iz0) (<= z iz1) (++ z)
|
||||
(for (var x int ix0) (<= x ix1) (++ x)
|
||||
(++ [(. a coverage) [values (+ (* z size) x)]])
|
||||
(++ (. a coverage-total)))))
|
||||
(++ [counts [values (+ (* z size) x)]])
|
||||
(++ (* total)))))
|
||||
|
||||
;;; Requests the visible tiles, nearest the centre first, and draws
|
||||
;;; those that are ready.
|
||||
@@ -353,15 +442,19 @@
|
||||
|
||||
(memset (. a coverage) 0 (sizeof (. a coverage)))
|
||||
(= (. a coverage-total) 0)
|
||||
(memset (. a mineral-coverage) 0 (sizeof (. a mineral-coverage)))
|
||||
(= (. a mineral-coverage-total) 0)
|
||||
(.begin-frame (. a tiles))
|
||||
;; layer by layer, each nearest the centre first: the base fills in
|
||||
;; before the overlays start
|
||||
(var layers [int 8])
|
||||
(var layers [int 9])
|
||||
(var layer-count int 0)
|
||||
(= [layers 0] (. a base))
|
||||
(= layer-count 1)
|
||||
(for (var o int 0) (< o 6) (++ o)
|
||||
(if (!= (& (. a overlays) (<< (cast 1 u32) o)) 0)
|
||||
(for (var o int 0) (< o OVERLAY-COUNT) (++ o)
|
||||
;; the Minerals overlay has nothing to show until one is chosen
|
||||
(if (&& (!= (& (. a overlays) (<< (cast 1 u32) o)) 0)
|
||||
(|| (!= [overlay-layers o] LAYER-MINERAL) (>= (. a mineral) 0)))
|
||||
(do (= [layers layer-count] [overlay-layers o]) (++ layer-count))))
|
||||
(var alpha u8 (cast (* (. a opacity) 255) u8))
|
||||
(for (var l int 0) (< l layer-count) (++ l)
|
||||
@@ -373,7 +466,11 @@
|
||||
(if (! tex)
|
||||
(continue))
|
||||
(if (&& values (== [layers l] LAYER-ROCK))
|
||||
(count-visible a values size (. k rx) (. k rz) x0 z0 x1 z1))
|
||||
(count-visible (. a coverage) (& (. a coverage-total)) values size (. k rx) (. k rz)
|
||||
x0 z0 x1 z1)
|
||||
(&& values (== [layers l] LAYER-MINERAL))
|
||||
(count-visible (. a mineral-coverage) (& (. a mineral-coverage-total)) values size
|
||||
(. k rx) (. k rz) x0 z0 x1 z1))
|
||||
(SDL-SetTextureBlendMode tex SDL-BLENDMODE-BLEND)
|
||||
(SDL-SetTextureAlphaMod tex (if (== l 0) 255 alpha))
|
||||
(var sx0 float (roundf (to-screen-x a (* (. k rx) REGION))))
|
||||
@@ -503,13 +600,19 @@
|
||||
|
||||
;;; The rock layer's mode, its depth or Y, and the legend: clicking rocks
|
||||
;;; highlights them, each with its share of the view; Find nearest
|
||||
;;; looks for the highlighted rocks around the view's centre.
|
||||
;;; looks for the highlighted rocks around the view's centre. Any depth
|
||||
;;; is for one rock: it can be chosen while one is highlighted, and
|
||||
;;; while it is on, clicking a rock highlights that one instead.
|
||||
(fn draw-rock-controls ((a (* app))) void
|
||||
(var ctx (* struct nk-context) (. a ctx))
|
||||
(var single int (single-highlight a))
|
||||
(nk-layout-row-dynamic ctx 20 1)
|
||||
(for (var i int 0) (< i 3) (++ i)
|
||||
(for (var i int 0) (< i 4) (++ i)
|
||||
(var disabled bool (&& (== i ROCK-ANY-DEPTH) (< single 0)))
|
||||
(if disabled (nk-widget-disable-begin ctx))
|
||||
(if (nk-option-label ctx [rock-mode-names i] (== (. a rock-mode) i))
|
||||
(= (. a rock-mode) i)))
|
||||
(= (. a rock-mode) i))
|
||||
(if disabled (nk-widget-disable-end ctx)))
|
||||
(if (== (. a rock-mode) ROCK-AT-DEPTH)
|
||||
(nk-property-int ctx "Depth" 0 (& (. a rock-value)) 300 1 0.5)
|
||||
(== (. a rock-mode) ROCK-AT-Y)
|
||||
@@ -526,7 +629,9 @@
|
||||
(nk-button-color ctx (nk-rgb (cast (& (>> c 16) 255) int) (cast (& (>> c 8) 255) int)
|
||||
(cast (& c 255) int)))
|
||||
(var label [char 64])
|
||||
(if (&& (> (. a coverage-total) 0) (!= (& (. a overlays) ROCK-OVERLAY-BIT) 0))
|
||||
;; at any depth, the tiles only know about the one rock
|
||||
(var counted bool (|| (!= (. a rock-mode) ROCK-ANY-DEPTH) (== i single)))
|
||||
(if (&& counted (> (. a coverage-total) 0) (!= (& (. a overlays) ROCK-OVERLAY-BIT) 0))
|
||||
(snprintf label (sizeof label) "%-13s %5.1f%%" (+ [(. rocks rock-codes) i] 5)
|
||||
(/ (* 100.0 [(. a coverage) i]) (. a coverage-total)))
|
||||
(snprintf label (sizeof label) "%s" (+ [(. rocks rock-codes) i] 5)))
|
||||
@@ -534,7 +639,9 @@
|
||||
(var selected nk-bool (!= (& (. a highlight) bit) 0))
|
||||
(if (nk-selectable-label ctx label NK-TEXT-LEFT (& selected))
|
||||
(do
|
||||
(^= (. a highlight) bit)
|
||||
(if (== (. a rock-mode) ROCK-ANY-DEPTH)
|
||||
(= (. a highlight) bit)
|
||||
(^= (. a highlight) bit))
|
||||
(update-palette a))))
|
||||
(nk-layout-row-dynamic ctx 18 1)
|
||||
(if (== (. a highlight) 0)
|
||||
@@ -543,7 +650,7 @@
|
||||
(nk-layout-row-dynamic ctx 24 2)
|
||||
(if (nk-button-label ctx "Show all")
|
||||
(do (= (. a highlight) 0) (update-palette a)))
|
||||
(if (. a searching)
|
||||
(if (&& (. a searching) (! (. a searching-mineral)))
|
||||
(if (nk-button-label ctx "Cancel")
|
||||
(do
|
||||
(search/stop (. a search))
|
||||
@@ -551,7 +658,7 @@
|
||||
(snprintf (. a search-status) (sizeof (. a search-status)) "cancelled")))
|
||||
(if (nk-button-label ctx "Find nearest")
|
||||
(= (. a find-requested) true)))))
|
||||
(if (* (. a search-status))
|
||||
(if (&& (* (. a search-status)) (! (. a searching-mineral)))
|
||||
(do
|
||||
(nk-layout-row-dynamic ctx 34 1)
|
||||
(nk-label-wrap ctx (. a search-status)))))
|
||||
@@ -571,7 +678,7 @@
|
||||
(nk-layout-row-dynamic ctx 18 1)
|
||||
(nk-label ctx "Overlays" NK-TEXT-LEFT)
|
||||
(nk-layout-row-dynamic ctx 20 1)
|
||||
(for (var i int 0) (< i 6) (++ i)
|
||||
(for (var i int 0) (< i OVERLAY-COUNT) (++ i)
|
||||
(var bit u32 (<< (cast 1 u32) i))
|
||||
(var on nk-bool (!= (& (. a overlays) bit) 0))
|
||||
(if (nk-checkbox-label ctx [overlay-labels i] (& on))
|
||||
@@ -606,6 +713,70 @@
|
||||
(draw-rock-controls a)
|
||||
(nk-tree-pop ctx))))
|
||||
|
||||
;;; The mineral shown, the legend of the pick's readings with each one's
|
||||
;;; share of the view, and Find nearest for a reading at least so high.
|
||||
(fn draw-mineral-controls ((a (* app))) void
|
||||
(var ctx (* struct nk-context) (. a ctx))
|
||||
(var current int 0)
|
||||
(for (var i int 1) (< i (. a mineral-item-count)) (++ i)
|
||||
(if (== [(. a mineral-ids) i] (. a mineral))
|
||||
(= current i)))
|
||||
(nk-layout-row-dynamic ctx 22 1)
|
||||
(var chosen int (nk-combo ctx (cast (. a mineral-items) (* * const char)) (. a mineral-item-count)
|
||||
current 20 (nk-vec2 220 400)))
|
||||
(if (!= chosen current)
|
||||
(do
|
||||
(= (. a mineral) [(. a mineral-ids) chosen])
|
||||
(= (. a mineral-code) (if (>= (. a mineral) 0) [(. a mineral-items) chosen] NULL))))
|
||||
(if (< (. a mineral) 0)
|
||||
(do
|
||||
(nk-layout-row-dynamic ctx 34 1)
|
||||
(nk-label-wrap ctx "Choose a mineral to see what the prospecting pick reads")
|
||||
(return)))
|
||||
(nk-layout-row-dynamic ctx 8 1)
|
||||
(nk-spacing ctx 1)
|
||||
(var shown bool (&& (> (. a mineral-coverage-total) 0)
|
||||
(!= (& (. a overlays) MINERAL-OVERLAY-BIT) 0)))
|
||||
(for (var c int (- READING-CATEGORIES 1)) (>= c 1) (-- c)
|
||||
(nk-layout-row-template-begin ctx 18)
|
||||
(nk-layout-row-template-push-static ctx 18)
|
||||
(nk-layout-row-template-push-dynamic ctx)
|
||||
(nk-layout-row-template-end ctx)
|
||||
(var colour u32 [reading-colours c])
|
||||
(nk-button-color ctx (nk-rgb (cast (& (>> colour 16) 255) int) (cast (& (>> colour 8) 255) int)
|
||||
(cast (& colour 255) int)))
|
||||
(if shown
|
||||
(nk-labelf ctx NK-TEXT-LEFT "%-13s %5.1f%%" [reading-names c]
|
||||
(/ (* 100.0 [(. a mineral-coverage) (+ MINERAL-VALUE-BASE c)])
|
||||
(. a mineral-coverage-total)))
|
||||
(nk-label ctx [reading-names c] NK-TEXT-LEFT)))
|
||||
(nk-layout-row-dynamic ctx 22 2)
|
||||
(nk-label ctx "Find at least" NK-TEXT-LEFT)
|
||||
;; from miniscule up
|
||||
(= (. a min-reading)
|
||||
(+ 1 (nk-combo ctx (+ reading-names 1) (- READING-CATEGORIES 1) (- (. a min-reading) 1) 20
|
||||
(nk-vec2 140 200))))
|
||||
(nk-layout-row-dynamic ctx 24 1)
|
||||
(if (&& (. a searching) (. a searching-mineral))
|
||||
(if (nk-button-label ctx "Cancel")
|
||||
(do
|
||||
(search/stop (. a search))
|
||||
(= (. a searching) false)
|
||||
(snprintf (. a search-status) (sizeof (. a search-status)) "cancelled")))
|
||||
(if (nk-button-label ctx "Find nearest")
|
||||
(= (. a find-mineral-requested) true)))
|
||||
(if (&& (* (. a search-status)) (. a searching-mineral))
|
||||
(do
|
||||
(nk-layout-row-dynamic ctx 34 1)
|
||||
(nk-label-wrap ctx (. a search-status)))))
|
||||
|
||||
(fn draw-minerals ((a (* app))) void
|
||||
(var ctx (* struct nk-context) (. a ctx))
|
||||
(if (nk-tree-push ctx NK-TREE-TAB "Minerals" NK-MAXIMIZED)
|
||||
(do
|
||||
(draw-mineral-controls a)
|
||||
(nk-tree-pop ctx))))
|
||||
|
||||
;;; A pin per probed column, so a probe can be found again. The oldest
|
||||
;;; goes when there are 32.
|
||||
(fn add-pin ((a (* app)) (x int) (z int)) void
|
||||
@@ -654,7 +825,27 @@
|
||||
(= [(. p rocks) (. p count)] r)
|
||||
(= [(. p tops) (. p count)] y)
|
||||
(= [(. p bottoms) (. p count)] y)
|
||||
(++ (. p count))))))
|
||||
(++ (. p count)))))
|
||||
;; what the pick reads here: every mineral it can, highest first
|
||||
(var o (* ores) (. a minerals))
|
||||
(= (. p reading-count) 0)
|
||||
(for (var i int 0) (< i (. o count)) (++ i)
|
||||
(if (! (. [(. o minerals) i] readable))
|
||||
(continue))
|
||||
(var m int-map)
|
||||
(ores/map o i (/ x 512) (/ z 512) (& m))
|
||||
(var r mineral-reading (ores/reading o i (& m) x z (. a column) h))
|
||||
(free (. m data))
|
||||
(if (== (ores/category (. r total)) 0)
|
||||
(continue))
|
||||
(var n int (. p reading-count))
|
||||
(while (&& (> n 0) (< (. [(. p readings) (- n 1)] total) (. r total)))
|
||||
(= [(. p readings) n] [(. p readings) (- n 1)])
|
||||
(= [(. p reading-minerals) n] [(. p reading-minerals) (- n 1)])
|
||||
(-- n))
|
||||
(= [(. p readings) n] r)
|
||||
(= [(. p reading-minerals) n] i)
|
||||
(++ (. p reading-count))))
|
||||
|
||||
(fn draw-probe ((a (* app))) void
|
||||
(var p (* probe) (& (. a probe)))
|
||||
@@ -684,6 +875,32 @@
|
||||
(var name (* const char) (if (== r ROCK-MANTLE) "mantle" (+ [(. a rocks rock-codes) r] 5)))
|
||||
(var thick int (+ (- [(. p tops) i] [(. p bottoms) i]) 1))
|
||||
(nk-labelf ctx NK-TEXT-LEFT "%3d-%-3d %-14s %3d" [(. p tops) i] [(. p bottoms) i] name thick))
|
||||
(nk-layout-row-dynamic ctx 6 1)
|
||||
(nk-spacing ctx 1)
|
||||
(nk-layout-row-dynamic ctx 18 1)
|
||||
(nk-label ctx "Prospecting pick" NK-TEXT-LEFT)
|
||||
(var trace [char 256])
|
||||
(= [trace 0] 0)
|
||||
(var shown int 0)
|
||||
(for (var i int 0) (< i (. p reading-count)) (++ i)
|
||||
(var r (* mineral-reading) (& [(. p readings) i]))
|
||||
(var code (* const char) (. [(. (. a minerals) minerals) [(. p reading-minerals) i]] code))
|
||||
(var c int (ores/category (. r total)))
|
||||
(if (>= c 2)
|
||||
(do
|
||||
(nk-labelf ctx NK-TEXT-LEFT "%-10s %-14s %5.2f ppt" [reading-names c] code (. r ppt))
|
||||
(++ shown))
|
||||
(do
|
||||
(var used size-t (strlen trace))
|
||||
(snprintf (+ trace used) (- (sizeof trace) used) "%s%s" (if (> used 0) ", " "") code))))
|
||||
(if (> (strlen trace) 0)
|
||||
(do
|
||||
(nk-layout-row-dynamic ctx 34 1)
|
||||
(var text [char 300])
|
||||
(snprintf text (sizeof text) "miniscule amounts of %s" trace)
|
||||
(nk-label-wrap ctx text))
|
||||
(== shown 0)
|
||||
(nk-label ctx "nothing" NK-TEXT-LEFT))
|
||||
(nk-tree-pop ctx))))
|
||||
|
||||
;;; The block under the cursor; false when the cursor is not on the
|
||||
@@ -702,12 +919,12 @@
|
||||
(var bz int)
|
||||
(if (cursor-block a (& bx) (& bz))
|
||||
(do
|
||||
(var value int (. a rock-value))
|
||||
(if (== (. a rock-mode) ROCK-AT-SURFACE) (= value 0))
|
||||
(var value int (rock-query-value a))
|
||||
;; TODO sex#45: use (. a rock-mode) in the literal once member
|
||||
;; access inside a compound literal follows the pointer.
|
||||
(var mode int (. a rock-mode))
|
||||
(hover-worker/ask (. a hover-worker) #(hover-query : bx bz mode value))))
|
||||
(var mineral int (if (!= (& (. a overlays) MINERAL-OVERLAY-BIT) 0) (. a mineral) -1))
|
||||
(hover-worker/ask (. a hover-worker) #(hover-query : bx bz mode value mineral))))
|
||||
(= (. a hover) (hover-worker/result (. a hover-worker))))
|
||||
|
||||
(fn rock-name ((a (* app)) (rock int)) (* const char)
|
||||
@@ -741,7 +958,11 @@
|
||||
(nk-labelf ctx NK-TEXT-LEFT "river distance %.0f, bank depth %.3f"
|
||||
(. r river-distance) (. r bank))
|
||||
(nk-labelf ctx NK-TEXT-LEFT "terrain height %d (sea level %d)" (. r height) (. r sea-level))
|
||||
(nk-labelf ctx NK-TEXT-LEFT "surface rock %s" (rock-name a (. r surface-rock)))))
|
||||
(nk-labelf ctx NK-TEXT-LEFT "surface rock %s" (rock-name a (. r surface-rock)))
|
||||
(if (>= (. r query mineral) 0)
|
||||
(nk-labelf ctx NK-TEXT-LEFT "%s %s, %.2f ppt"
|
||||
(. [(. (. a minerals) minerals) (. r query mineral)] code)
|
||||
[reading-names (ores/category (. r mineral total))] (. r mineral ppt)))))
|
||||
(nk-labelf ctx NK-TEXT-LEFT "%d tiles pending" (. a pending))
|
||||
(nk-label ctx (. a status) NK-TEXT-LEFT)
|
||||
(nk-tree-pop ctx))))
|
||||
@@ -752,12 +973,22 @@
|
||||
(if (. a find-requested)
|
||||
(do
|
||||
(= (. a find-requested) false)
|
||||
(var value int (. a rock-value))
|
||||
(if (== (. a rock-mode) ROCK-AT-SURFACE) (= value 0))
|
||||
(var value int (rock-query-value a))
|
||||
(search/start (. a search) (. a source settings) (. a rivers) (. a assets-dir)
|
||||
(. a rock-mode) value (. a highlight) (. a center-x) (. a center-z)
|
||||
(- (SDL-GetNumLogicalCPUCores) 1))
|
||||
(= (. a searching) true)))
|
||||
(= (. a searching) true)
|
||||
(= (. a searching-mineral) false)))
|
||||
(if (. a find-mineral-requested)
|
||||
(do
|
||||
(= (. a find-mineral-requested) false)
|
||||
(if (>= (. a mineral) 0)
|
||||
(do
|
||||
(search/start (. a search) (. a source settings) (. a rivers) (. a assets-dir)
|
||||
SEARCH-MINERAL (. a mineral) (cast (. a min-reading) u32)
|
||||
(. a center-x) (. a center-z) (- (SDL-GetNumLogicalCPUCores) 1))
|
||||
(= (. a searching) true)
|
||||
(= (. a searching-mineral) true)))))
|
||||
(if (! (. a searching))
|
||||
(return))
|
||||
(var s (* search) (. a search))
|
||||
@@ -798,11 +1029,15 @@
|
||||
(if (nk-begin ctx "right" right NK-WINDOW-BORDER)
|
||||
(do
|
||||
(draw-layers a)
|
||||
(draw-rocks a)))
|
||||
(draw-rocks a)
|
||||
(draw-minerals a)))
|
||||
(nk-end ctx))
|
||||
|
||||
;;; A label by the cursor naming the rock under it, as the Rocks
|
||||
;;; window's mode has it: at the surface, at a depth or at a Y. It moves
|
||||
;;; window's mode has it: at the surface, at a depth or at a Y; at any
|
||||
;;; depth, how deep the rock looked for starts, if it is there. With
|
||||
;;; the Minerals overlay on, a second line gives the pick's reading of
|
||||
;;; the mineral shown. It moves
|
||||
;;; with the cursor every frame; its text is the hover worker's newest,
|
||||
;;; which can trail the cursor by a frame or two.
|
||||
(fn draw-cursor-rock ((a (* app))) void
|
||||
@@ -814,17 +1049,31 @@
|
||||
(var text [char 64])
|
||||
(if (! (. r valid)) (snprintf text (sizeof text) "...")
|
||||
(== (. r rock) -2) (snprintf text (sizeof text) "mantle")
|
||||
(== (. r rock) -3) (snprintf text (sizeof text) "no %s" (rock-name a (. r query value)))
|
||||
(== (. r query mode) ROCK-ANY-DEPTH)
|
||||
(snprintf text (sizeof text) "%s, y %d, %d deep" (rock-name a (. r rock)) (. r rock-y)
|
||||
(- (. r height) (. r rock-y)))
|
||||
(>= (. r rock) 0) (snprintf text (sizeof text) "%s, y %d" (rock-name a (. r rock)) (. r rock-y))
|
||||
(< (. r rock-y) (. r sea-level)) (snprintf text (sizeof text) "water, y %d" (. r rock-y))
|
||||
(snprintf text (sizeof text) "air, y %d" (. r rock-y)))
|
||||
;; and the pick's reading of the mineral shown
|
||||
(var reading [char 96])
|
||||
(= [reading 0] 0)
|
||||
(if (&& (. r valid) (>= (. r query mineral) 0))
|
||||
(snprintf reading (sizeof reading) "%s %s, %.2f ppt"
|
||||
(. [(. (. a minerals) minerals) (. r query mineral)] code)
|
||||
[reading-names (ores/category (. r mineral total))] (. r mineral ppt)))
|
||||
(var height float (if [reading 0] 50 30))
|
||||
;; beside the cursor, not under it, so it never takes the map's input
|
||||
(var ctx (* struct nk-context) (. a ctx))
|
||||
(var bounds (struct nk-rect) (nk-rect (+ (. a mouse-x) 16) (+ (. a mouse-y) 16) 190 30))
|
||||
(var bounds (struct nk-rect) (nk-rect (+ (. a mouse-x) 16) (+ (. a mouse-y) 16) 260 height))
|
||||
(nk-window-set-bounds ctx "cursor" bounds)
|
||||
(if (nk-begin ctx "cursor" bounds (| NK-WINDOW-BORDER NK-WINDOW-NO-SCROLLBAR NK-WINDOW-NO-INPUT))
|
||||
(do
|
||||
(nk-layout-row-dynamic ctx 18 1)
|
||||
(nk-label ctx text NK-TEXT-LEFT)))
|
||||
(nk-label ctx text NK-TEXT-LEFT)
|
||||
(if [reading 0]
|
||||
(nk-label ctx reading NK-TEXT-LEFT))))
|
||||
(nk-end ctx))
|
||||
|
||||
;;; Events ---------------------------------------------------------
|
||||
@@ -902,6 +1151,7 @@
|
||||
(= (. a opacity) 0.5)
|
||||
(= (. a show-stories) false)
|
||||
(= (. a show-cursor-rock) true)
|
||||
(= (. a min-reading) DEFAULT-MIN-READING)
|
||||
(snprintf (. a assets-dir) (sizeof (. a assets-dir)) "assets")
|
||||
(snprintf (. a world-path) (sizeof (. a world-path)) "serverconfig.json")
|
||||
(for (var i int 1) (< i argc) (++ i)
|
||||
@@ -923,13 +1173,15 @@
|
||||
(&& (== (strcmp [argv i] "--overlay") 0) more)
|
||||
(do
|
||||
(++ i)
|
||||
(for (var o int 0) (< o 6) (++ o)
|
||||
(for (var o int 0) (< o OVERLAY-COUNT) (++ o)
|
||||
(if (== (strcmp [argv i] [overlay-names o]) 0)
|
||||
(c-bit-or= (. a overlays) (<< (cast 1 u32) o)))))
|
||||
(&& (== (strcmp [argv i] "--rock-depth") 0) more)
|
||||
(do (++ i) (= (. a rock-mode) ROCK-AT-DEPTH) (= (. a rock-value) (atoi [argv i])))
|
||||
(&& (== (strcmp [argv i] "--rock-y") 0) more)
|
||||
(do (++ i) (= (. a rock-mode) ROCK-AT-Y) (= (. a rock-value) (atoi [argv i])))
|
||||
(== (strcmp [argv i] "--rock-any") 0)
|
||||
(= (. a rock-mode) ROCK-ANY-DEPTH)
|
||||
(&& (== (strcmp [argv i] "--mouse") 0) (< (+ i 2) argc))
|
||||
(do
|
||||
(= (. a mouse-x) (cast (atof [argv (+ i 1)]) float))
|
||||
@@ -942,6 +1194,12 @@
|
||||
(+= i 2))
|
||||
(== (strcmp [argv i] "--find") 0)
|
||||
(= (. a find-requested) true)
|
||||
(&& (== (strcmp [argv i] "--mineral") 0) more)
|
||||
(do (++ i) (= (. a mineral-code) [argv i]))
|
||||
(&& (== (strcmp [argv i] "--min-reading") 0) more)
|
||||
(do (++ i) (= (. a min-reading) (reading-named [argv i])))
|
||||
(== (strcmp [argv i] "--find-mineral") 0)
|
||||
(= (. a find-mineral-requested) true)
|
||||
(&& (== (strcmp [argv i] "--highlight") 0) more)
|
||||
(do
|
||||
(++ i)
|
||||
@@ -1005,6 +1263,7 @@
|
||||
(nk-sdl-update-TextInput (. a ctx))
|
||||
(nk-input-end (. a ctx))
|
||||
|
||||
(fix-rock-mode a)
|
||||
(update-search a)
|
||||
(update-hover a)
|
||||
(draw-panels a)
|
||||
@@ -1021,7 +1280,8 @@
|
||||
(draw-markers a)
|
||||
(SDL-SetRenderClipRect (. a renderer) NULL)
|
||||
(nk-sdl-render (. a ctx) NK-ANTI-ALIASING-ON)
|
||||
(if (&& (. a screenshot) (== (. a pending) 0) (! (. a searching)) (! (. a find-requested)))
|
||||
(if (&& (. a screenshot) (== (. a pending) 0) (! (. a searching)) (! (. a find-requested))
|
||||
(! (. a find-mineral-requested)))
|
||||
(do
|
||||
(if (! (save-screenshot a))
|
||||
(fprintf stderr "%s: %s\n" (. a screenshot) (SDL-GetError)))
|
||||
@@ -1032,6 +1292,7 @@
|
||||
(.stop (. a tiles))
|
||||
(release-probe-terra a)
|
||||
(hover-worker/stop (. a hover-worker))
|
||||
(ores/free (. a minerals))
|
||||
(strata/free (. a rocks))
|
||||
(worldgen/free (. a g))
|
||||
(nk-sdl-shutdown (. a ctx))
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
(import terra)
|
||||
(import strata)
|
||||
(import settings)
|
||||
(import ores)
|
||||
(import verify)
|
||||
|
||||
(var worldgen-assets [(* const char) 6]
|
||||
@@ -93,9 +94,13 @@
|
||||
(if (! g)
|
||||
(return 1))
|
||||
(var s (* save) (save/open save-path))
|
||||
(var rocks (* strata) (strata/make g assets-dir))
|
||||
(var minerals (* ores) (ores/make (. source settings) assets-dir rocks))
|
||||
(var failed int (+ (verify-stories s g) (verify-regions s g out)
|
||||
(verify-ores s minerals out)
|
||||
(verify-readings s g (river-config/defaults) rocks minerals)
|
||||
(verify-rivers s g (river-config/defaults) out)
|
||||
(verify-heights s g (river-config/defaults) (strata/make g assets-dir) out)))
|
||||
(verify-heights s g (river-config/defaults) rocks out)))
|
||||
(save/close s)
|
||||
(return failed))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user