./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
2 / 2
100.0%
Branches:
-
-%
Functions:
-
-%

src/config/layer_context.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief What checking and building a configuration's layers reads: the outputs' grids, what
5 /// the layers before found, and what each layer is built on.
6 #pragma once
7
8 #include "config/common.h"
9
10 #include "terraingen/layers/boulders/boulder_layer.h"
11 #include "terraingen/layers/craters/crater_layer.h"
12 #include "terraingen/layers/craters/secondaries.h"
13 #include "terraingen/layers/layer.h"
14 #include "terraingen/layers/terrain_base.h"
15 #include "terraingen/raster/grid.h"
16 #include "terraingen/sources/source.h"
17
18 #include <filesystem>
19 #include <memory>
20 #include <optional>
21 #include <string>
22 #include <vector>
23
24 namespace terraingen::config {
25
26 /// What checking an output's area found: the grid it covers and where it evaluates the layers.
27 struct OutputGrid {
28 std::optional<RasterGrid> grid{}; ///< None for an output without an area.
29 /// Meters a feature list over the whole body asks its features at (`Terrain::Craters`); 0 for
30 /// the grid's own.
31 double featureSpacing = 0.0;
32 double area = 0.0; ///< Square meters the grid covers.
33 double spacing = 0.0; ///< Meters the layers are evaluated or features listed at.
34 bool listed = false; ///< A feature list, which holds every boulder however small.
35 };
36
37 /// What a layer is checked against, and what the layers before it found.
38 421 struct LayerChecks {
39 const std::vector<OutputGrid>& outputs;
40 bool posts = false; ///< Whether the source has posts to estimate settings from.
41 bool craters = false; ///< Whether a crater layer came before.
42 bool boulders = false; ///< Whether a boulder layer came before.
43 /// Craters the crater layers so far are expected to generate over each output's grid, 0 for
44 /// an output without one; empty when none generate.
45 std::vector<double> expectedCraters{};
46 };
47
48 /// What a layer is built on: the surface and measured source, the top-level crater layers so far
49 /// (all for boulder ejecta, the last for secondaries), the last boulder layer (for sand shadows).
50 640 struct LayerInputs {
51 /// The surface, and the source's measured data that crater and boulder layers leave out what
52 /// it resolves of (null for none); other layers read the terrain's source when evaluated.
53 TerrainBase base;
54 const std::filesystem::path& directory;
55 const std::vector<std::shared_ptr<const CraterLayer>>& craters;
56 const std::shared_ptr<const BoulderLayer>& boulders;
57 /// The source the configuration gives; null without one.
58 const std::shared_ptr<const Source>& source;
59 /// The secondaries later layers throw from a crater layer built with these inputs.
60 std::vector<SecondaryCraterOptions> thrown{};
61 };
62
63 /// Checks a layer spec before any layer is built; most specs are checked as they are built.
64 template <typename Spec> void CheckSpec(const Spec&, const std::string&, LayerChecks&) {}
65
66 /// Checks what a layer needs built to check, `built` being the layer the spec built.
67 template <typename Spec>
68 void CheckBuilt(const Spec&, const Layer& /*built*/, const std::string&, LayerChecks&) {}
69
70 /// Requires a source with posts for a layer at `path` that estimates its settings from it.
71 /// @throws ConfigError at the layer's "estimate_from_source" without one.
72 void CheckEstimateSource(bool estimate, const std::string& path, const LayerChecks& checks);
73
74 } // namespace terraingen::config
75