diff --git a/Readme.org b/Readme.org index 31980a0..5e18083 100644 --- a/Readme.org +++ b/Readme.org @@ -71,6 +71,7 @@ Options: | =--overlay NAME= | turn on an overlay: =landform=, =climate=, =province=, =upheaval=, =strata=, =rock=; 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 | | =--probe X Z= | probe the column at block X, Z on start | @@ -95,7 +96,8 @@ The map fills the middle of the window, between two panels. 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. 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; @@ -135,7 +137,10 @@ when nothing is left to compute, the viewer sleeps. - /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, diff --git a/src/hover.sex b/src/hover.sex index 51c3d21..3591ad5 100644 --- a/src/hover.sex +++ b/src/hover.sex @@ -29,7 +29,9 @@ ((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))) @@ -108,6 +110,17 @@ (= (. 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 (== (. 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))) diff --git a/src/search.sex b/src/search.sex index 7311115..8ae27d1 100644 --- a/src/search.sex +++ b/src/search.sex @@ -1,5 +1,5 @@ ;;; 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. ;;; ;;; Regions are taken in order of their distance from the point and ;;; sampled every 16 blocks by several threads at once, each with its @@ -70,6 +70,16 @@ (fn matches ((s (* const search)) (rock int)) bool (return (&& (>= rock 0) (< rock 32) (!= (& (. s mask) (<< (cast 1 u32) rock)) 0)))) +;;; Whether the column holds a searched rock where the mode looks: at +;;; any depth (mode 3), anywhere from y = 1 to the surface. +(fn column-matches ((s (* const search)) (column (* const u8)) (height int)) bool + (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))) @@ -92,7 +102,7 @@ (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))) + (if (column-matches s column h) (offer s (+ (* cx 32) lx) (+ (* cz 32) lz)))))) (fn search-thread ((arg (* void))) (* void) diff --git a/src/tiles.sex b/src/tiles.sex index f641c85..b644044 100644 --- a/src/tiles.sex +++ b/src/tiles.sex @@ -29,13 +29,16 @@ (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. (pub define LAYER-RIVERS 6) (pub define LAYER-HEIGHT 7) (pub define LAYER-ROCK 8) (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) ;;; Rock tile values besides rock indices. (pub define VALUE-WATER 253) (pub define VALUE-AIR 254) @@ -280,7 +283,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 +313,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))))) diff --git a/src/viewer.sex b/src/viewer.sex index 611e394..dec6b4f 100644 --- a/src/viewer.sex +++ b/src/viewer.sex @@ -3,7 +3,7 @@ ;;; ;;; 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] ;;; [--probe X Z] [--mouse X Y] ;;; [--screenshot FILE.png] [WORLD.vcdbs | serverconfig.json] ;;; @@ -53,7 +53,7 @@ (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")) +(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] @@ -216,6 +216,26 @@ (= [p i] 0))) (.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))) + ;;; Makes SOURCE the world shown: a fresh generator for the panels, ;;; and every tile regenerated. (fn apply ((a (* app)) (source world-source)) bool @@ -305,9 +325,7 @@ (== 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))))) (return k)) ;;; Adds a value tile's samples that fall inside the visible world @@ -503,13 +521,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 +550,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 +560,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) @@ -702,8 +730,7 @@ (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)) @@ -752,8 +779,7 @@ (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)) @@ -802,7 +828,8 @@ (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. 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,12 +841,16 @@ (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))) ;; 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) 240 30)) (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 @@ -930,6 +961,8 @@ (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)) @@ -1005,6 +1038,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)