载入中...
搜索中...
未找到
TerrainDetailLayer.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <climits>
4#include <cmath>
5#include <limits>
6#include <map>
7#include <unordered_set>
8#include <vector>
13
14namespace eve::procgen {
15namespace {
16Result<int> invalid() {
19 "terrain.detail: initialized matching finite input and valid settings required"));
20}
21class DetailThinningStream {
22 uint64_t a_, b_;
23
24public:
25 explicit DetailThinningStream(int32_t seed) {
26 const auto bits = static_cast<uint32_t>(seed == 0 ? 1 : seed);
27 a_ = uint64_t(181353) * bits;
28 b_ = uint64_t(7) * bits;
29 }
30 float next() {
31 auto x = a_, y = b_;
32 a_ = y;
33 x ^= x << 23;
34 x ^= x >> 17;
35 x ^= y ^ (y >> 26);
36 b_ = x;
37 return static_cast<float>(x + y) / static_cast<float>(UINT64_MAX);
38 }
39};
40float inverseLerp(float a, float b, float value) {
41 return a == b ? 0.0F : std::clamp((value - a) / (b - a), 0.0F, 1.0F);
42}
43int nearestEven(float value) {
44 const double lower = std::floor(double(value)), fraction = double(value) - lower;
45 return int(lower + (fraction > 0.5 || (fraction == 0.5 && std::fmod(lower, 2.0) != 0)));
46}
47bool validSettings(const TerrainDetailSettings& settings) {
48 return std::isfinite(settings.minimumFitness) && settings.minimumFitness >= 0 && settings.minimumFitness <= 1 &&
49 std::isfinite(settings.fadeStart) && settings.fadeStart >= 0 && settings.fadeStart <= 1 &&
50 std::isfinite(settings.density) && settings.density >= 0 && double(settings.density) < double(INT_MAX) &&
53}
54} // namespace
56 std::vector<int> totals(counts.size(), 0);
57 for (const auto& [namespaceId, resourceCounts] : resources) {
58 (void)namespaceId;
59 if (resourceCounts.size() != totals.size()) return invalid();
60 for (std::size_t i = 0; i < totals.size(); ++i) {
61 if (resourceCounts[i] > INT_MAX - totals[i]) return invalid();
62 totals[i] += resourceCounts[i];
63 }
64 }
65 counts.swap(totals);
66 return Result<int>::success(static_cast<int>(counts.size()));
67}
71TerrainDetailLayer& TerrainDetailLayer::operator=(TerrainDetailLayer&&) noexcept = default;
73 : impl_(other.impl_ ? std::make_unique<Impl>(*other.impl_) : nullptr) {}
75 if (this != &other) impl_ = other.impl_ ? std::make_unique<Impl>(*other.impl_) : nullptr;
76 return *this;
77}
78int TerrainDetailLayer::getWidth() const noexcept { return impl_ ? impl_->width : 0; }
79int TerrainDetailLayer::getHeight() const noexcept { return impl_ ? impl_->height : 0; }
81 if (width <= 0 || height <= 0 || width > INT_MAX / height || count < 0) return invalid();
82 auto candidate = std::make_unique<Impl>();
83 candidate->width = width;
84 candidate->height = height;
85 candidate->counts.assign(size_t(width) * height, count);
86 candidate->resources.emplace(0, candidate->counts);
87 impl_.swap(candidate);
89}
91 if (!impl_ || x < 0 || z < 0 || x >= impl_->width || z >= impl_->height) return invalid();
92 return Result<int>::success(impl_->counts[size_t(z) * impl_->width + x]);
93}
94Result<int> TerrainDetailLayer::sampleResource(std::uint64_t namespaceId, int x, int z) const {
95 if (!impl_ || x < 0 || z < 0 || x >= impl_->width || z >= impl_->height) return invalid();
96 const auto found = impl_->resources.find(namespaceId);
97 if (found == impl_->resources.end()) return Result<int>::success(0);
98 return Result<int>::success(found->second[size_t(z) * impl_->width + x]);
99}
101 if (!impl_) return invalid();
102 auto candidate = std::make_unique<Impl>(*impl_);
103 const auto found = candidate->resources.find(namespaceId);
104 if (found == candidate->resources.end()) return Result<int>::success(0);
105 int changed = 0;
106 for (int count : found->second) changed += count != 0;
107 candidate->resources.erase(found);
108 auto rebuilt = candidate->rebuildTotals();
109 if (!rebuilt.ok()) return rebuilt;
110 impl_.swap(candidate);
112}
114 if (!impl_ || fitness.getWidth() != impl_->width || fitness.getHeight() != impl_->height ||
115 fitness.data().size() != impl_->counts.size() || !validSettings(settings))
116 return invalid();
117 for (float value : fitness.data())
118 if (!std::isfinite(value)) return invalid();
119 auto next = std::make_unique<Impl>(*impl_);
120 auto [resource, inserted] = next->resources.try_emplace(settings.namespaceId, impl_->counts.size(), 0);
121 (void)inserted;
122 auto& target = resource->second;
123 if (settings.mode == TerrainDetailMode::Replace) std::fill(target.begin(), target.end(), 0);
124 DetailThinningStream random(seed);
125 const float sign = settings.mode == TerrainDetailMode::Remove ? -1.0F : 1.0F;
126 for (int x = 0; x < impl_->width; ++x)
127 for (int z = 0; z < impl_->height; ++z) {
128 const size_t index = size_t(z) * impl_->width + x;
129 const float value = fitness.data()[index];
130 if (value <= settings.minimumFitness) continue;
131 if (value < settings.fadeStart &&
132 random.next() > inverseLerp(settings.minimumFitness, settings.fadeStart, value))
133 continue;
134 const float amount = inverseLerp(settings.minimumFitness, 1.0F, value) * settings.density;
135 target[index] = nearestEven(std::clamp(float(target[index]) + sign * amount, 0.0F, settings.density));
136 }
137 auto rebuilt = next->rebuildTotals();
138 if (!rebuilt.ok()) return rebuilt;
139 int changed = 0;
140 for (size_t i = 0; i < next->counts.size(); ++i) changed += next->counts[i] != impl_->counts[i];
141 impl_.swap(next);
143}
144
146 const std::vector<TerrainDetailTile>& tiles, const Heightmap& operationFitness,
147 const TerrainDetailSettings& settings, const TerrainStampSettings& operationSettings, int32_t seed,
148 bool worldMapOperation, const std::vector<std::string>& validTerrainNames) {
149 if (tiles.empty() || !validSettings(settings))
151 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.multitile: valid tiles and settings required"));
152 std::vector<TerrainOperationTile> operationTiles;
153 operationTiles.reserve(tiles.size());
154 std::unordered_set<TerrainDetailLayer*> owners;
155 for (const auto& tile : tiles) {
156 if (!tile.layer || !tile.layer->impl_ || !owners.insert(tile.layer).second)
158 DiagnosticCode::InvalidArgument, "terrain.detail.multitile: distinct initialized layers required"));
159 operationTiles.push_back({tile.name, tile.originX, tile.originZ, tile.width, tile.depth,
160 tile.layer->impl_->width, tile.layer->impl_->height, tile.worldMap});
161 }
162 auto mapped = mapTerrainOperationMultiTile(operationTiles, operationSettings,
163 TerrainOperationDomain::TerrainDetail, worldMapOperation,
164 validTerrainNames);
165 if (!mapped.ok()) return mapped;
166 auto report = std::move(mapped.value());
167 if (operationFitness.getWidth() != report.operationWidth ||
168 operationFitness.getHeight() != report.operationHeight ||
169 operationFitness.data().size() != size_t(report.operationWidth) * report.operationHeight)
171 DiagnosticCode::InvalidArgument, "terrain.detail.multitile: operation fitness dimensions must match window"));
172 for (float value : operationFitness.data())
173 if (!std::isfinite(value))
175 DiagnosticCode::InvalidArgument, "terrain.detail.multitile: finite operation fitness required"));
176
177 struct Candidate {
179 std::unique_ptr<TerrainDetailLayer::Impl> value;
180 };
181 std::vector<Candidate> candidates;
182 candidates.reserve(report.mappings.size());
183 DetailThinningStream random(seed);
184 const float sign = settings.mode == TerrainDetailMode::Remove ? -1.0F : 1.0F;
185 for (const auto& mapping : report.mappings) {
186 const auto tile = std::find_if(tiles.begin(), tiles.end(), [&](const auto& item) {
187 return item.name == mapping.terrainName;
188 });
189 if (tile == tiles.end())
191 DiagnosticCode::InvalidArgument, "terrain.detail.multitile: internal mapping has no tile"));
192 auto next = std::make_unique<TerrainDetailLayer::Impl>(*tile->layer->impl_);
193 auto [resource, inserted] = next->resources.try_emplace(settings.namespaceId, next->counts.size(), 0);
194 (void)inserted;
195 auto& targetCounts = resource->second;
196 if (settings.mode == TerrainDetailMode::Replace) std::fill(targetCounts.begin(), targetCounts.end(), 0);
197 const auto& before = tile->layer->impl_->counts;
198 for (int x = 0; x < mapping.width; ++x)
199 for (int z = 0; z < mapping.height; ++z) {
200 const int localX = mapping.localX + x, localZ = mapping.localY + z;
201 const int operationX = mapping.operationX + x, operationZ = mapping.operationY + z;
202 const size_t localIndex = size_t(localZ) * next->width + localX;
203 const float fitness = operationFitness.data()[size_t(operationZ) * report.operationWidth + operationX];
204 if (fitness <= settings.minimumFitness) continue;
205 if (fitness < settings.fadeStart &&
206 random.next() > inverseLerp(settings.minimumFitness, settings.fadeStart, fitness))
207 continue;
208 const float amount = inverseLerp(settings.minimumFitness, 1.0F, fitness) * settings.density;
209 targetCounts[localIndex] = nearestEven(
210 std::clamp(float(targetCounts[localIndex]) + sign * amount, 0.0F, settings.density));
211 }
212 auto rebuilt = next->rebuildTotals();
213 if (!rebuilt.ok()) return Result<TerrainMultiTileReport>::failure(rebuilt.status());
214 for (size_t i = 0; i < before.size(); ++i) {
215 if (before[i] == next->counts[i]) continue;
216 if (report.changedSamples == std::numeric_limits<int>::max())
218 DiagnosticCode::InvalidArgument, "terrain.detail.multitile: changed cell count exceeds integer range"));
219 ++report.changedSamples;
220 }
221 candidates.push_back({tile->layer, std::move(next)});
222 }
223 for (auto& candidate : candidates) candidate.target->impl_.swap(candidate.value);
224 return Result<TerrainMultiTileReport>::success(std::move(report));
225}
226
228 struct Tile {
229 std::string name;
231 double originX = 0, originZ = 0, width = 1, depth = 1;
232 bool worldMap = false;
233 };
234 struct Snapshot {
235 std::vector<TerrainDetailLayer> layers;
237 };
238 std::vector<Tile> tiles;
240 std::vector<Snapshot> history;
241 int cursor = 0;
242
243 Impl() = default;
244 Impl(const Impl& other) : last(other.last), history(other.history), cursor(other.cursor) {
245 tiles.reserve(other.tiles.size());
246 for (const auto& source : other.tiles) {
248 layer.impl_ = std::make_unique<TerrainDetailLayer::Impl>(*source.layer.impl_);
249 tiles.push_back({source.name, std::move(layer), source.originX, source.originZ, source.width,
250 source.depth, source.worldMap});
251 }
252 }
255 result.layers.reserve(tiles.size());
256 for (const auto& tile : tiles) result.layers.push_back(tile.layer);
257 result.report = last;
258 return result;
259 }
260 void restore(const Snapshot& snapshot) {
261 for (size_t i = 0; i < tiles.size(); ++i) tiles[i].layer = snapshot.layers[i];
262 last = snapshot.report;
263 }
264};
265
270
272 double originX, double originZ, double width, double depth,
273 bool worldMap) {
274 if (!impl_ || !layer.impl_ || name.empty())
276 DiagnosticCode::InvalidArgument, "terrain.detail.workspace: initialized named tile required"));
277 if (std::any_of(impl_->tiles.begin(), impl_->tiles.end(), [&](const auto& tile) { return tile.name == name; }))
279 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.workspace: duplicate tile name"));
280 if (impl_->history.size() > 1)
282 DiagnosticCode::InvalidArgument, "terrain.detail.workspace: topology is fixed after applying"));
283 auto candidate = std::make_unique<Impl>(*impl_);
285 owned.impl_ = std::make_unique<TerrainDetailLayer::Impl>(*layer.impl_);
286 candidate->tiles.push_back({name, std::move(owned), originX, originZ, width, depth, worldMap});
287 std::vector<TerrainOperationTile> descriptors;
288 for (const auto& tile : candidate->tiles)
289 descriptors.push_back({tile.name, tile.originX, tile.originZ, tile.width, tile.depth,
290 tile.layer.impl_->width, tile.layer.impl_->height, tile.worldMap});
292 bounds.centerX = originX + width * 0.5;
293 bounds.centerZ = originZ + depth * 0.5;
294 bounds.width = width;
295 bounds.depth = depth;
297 worldMap, {name});
298 if (!checked.ok()) return Result<int>::failure(checked.status());
299 candidate->history.clear();
300 candidate->history.push_back(candidate->snapshot());
301 candidate->cursor = 0;
302 impl_.swap(candidate);
303 return Result<int>::success(int(impl_->tiles.size()));
304}
305
306Result<int> TerrainMultiDetailWorkspace::apply(const Heightmap& operationFitness,
308 const TerrainStampSettings& operationSettings, int32_t seed,
309 bool worldMapOperation) {
310 if (!impl_)
312 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.workspace: moved-from workspace"));
313 auto candidate = std::make_unique<Impl>(*impl_);
314 std::vector<TerrainDetailTile> descriptors;
315 for (auto& tile : candidate->tiles)
316 descriptors.push_back({tile.name, &tile.layer, tile.originX, tile.originZ, tile.width, tile.depth,
317 tile.worldMap});
318 auto applied = applyTerrainDetailMultiTile(descriptors, operationFitness, settings, operationSettings, seed,
319 worldMapOperation);
320 if (!applied.ok()) return Result<int>::failure(applied.status());
321 candidate->last = std::move(applied.value());
322 candidate->history.resize(size_t(candidate->cursor + 1));
323 candidate->history.push_back(candidate->snapshot());
324 ++candidate->cursor;
325 const int changed = candidate->last.changedSamples;
326 impl_.swap(candidate);
328}
329
330Result<int> TerrainMultiDetailWorkspace::copyTile(const std::string& name, TerrainDetailLayer& output) const {
331 if (!impl_)
333 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.workspace: moved-from workspace"));
334 const auto found = std::find_if(impl_->tiles.begin(), impl_->tiles.end(),
335 [&](const auto& tile) { return tile.name == name; });
336 if (found == impl_->tiles.end())
338 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.workspace: tile not found"));
339 auto copy = std::make_unique<TerrainDetailLayer::Impl>(*found->layer.impl_);
340 output.impl_.swap(copy);
341 return Result<int>::success(found->layer.impl_->width * found->layer.impl_->height);
342}
343
344Result<int> TerrainMultiDetailWorkspace::undo() {
345 if (!impl_ || impl_->cursor <= 0)
347 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.workspace: no undo snapshot"));
348 auto candidate = std::make_unique<Impl>(*impl_);
349 --candidate->cursor;
350 candidate->restore(candidate->history[size_t(candidate->cursor)]);
351 const int cursor = candidate->cursor;
352 impl_.swap(candidate);
354}
355Result<int> TerrainMultiDetailWorkspace::redo() {
356 if (!impl_ || impl_->cursor + 1 >= int(impl_->history.size()))
358 Diagnostic::error(DiagnosticCode::InvalidArgument, "terrain.detail.workspace: no redo snapshot"));
359 auto candidate = std::make_unique<Impl>(*impl_);
360 ++candidate->cursor;
361 candidate->restore(candidate->history[size_t(candidate->cursor)]);
362 const int cursor = candidate->cursor;
363 impl_.swap(candidate);
365}
366int TerrainMultiDetailWorkspace::getTileCount() const noexcept { return impl_ ? int(impl_->tiles.size()) : 0; }
367int TerrainMultiDetailWorkspace::getLastChangedSamples() const noexcept {
368 return impl_ ? impl_->last.changedSamples : 0;
369}
370int TerrainMultiDetailWorkspace::getLastAffectedTiles() const noexcept {
371 return impl_ ? impl_->last.affectedTiles : 0;
372}
373int TerrainMultiDetailWorkspace::getOperationCount() const noexcept {
374 return impl_ ? std::max(0, int(impl_->history.size()) - 1) : 0;
375}
376int TerrainMultiDetailWorkspace::getAppliedCount() const noexcept { return impl_ ? impl_->cursor : 0; }
377} // namespace eve::procgen
378
379#include <algorithm>
380#include <cmath>
381#include <limits>
382#include <type_traits>
383#include "procgen/PointSet.h"
387namespace eve::procgen {
388namespace {
389uint64_t mix(uint64_t x) {
390 x = (x ^ (x >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
391 x = (x ^ (x >> 27)) * UINT64_C(0x94d049bb133111eb);
392 return x ^ (x >> 31);
393}
394double unit(uint64_t identity, uint64_t stream, uint32_t seed) {
395 return double(mix(identity ^ stream ^ (uint64_t(seed) << 32)) >> 40) / 16777216.0;
396}
397double smooth(double value) { return value * value * (3.0 - 2.0 * value); }
398double lattice(int64_t x, int64_t z, int32_t seed) {
399 const uint64_t key = uint64_t(x) * UINT64_C(0x9e3779b185ebca87) ^ uint64_t(z) * UINT64_C(0xc2b2ae3d27d4eb4f) ^
400 uint64_t(uint32_t(seed));
401 return double(mix(key) >> 40) / 16777216.0;
402}
403double detailColorNoise(double u, double v, float spread, int32_t seed) {
404 if (spread == 0) return 0.5;
405 const double frequency = 1.0 + 31.0 * double(spread);
406 const double x = u * frequency, z = v * frequency;
407 const int64_t x0 = int64_t(std::floor(x)), z0 = int64_t(std::floor(z));
408 const double tx = smooth(x - x0), tz = smooth(z - z0);
409 const double a = std::lerp(lattice(x0, z0, seed), lattice(x0 + 1, z0, seed), tx);
410 const double b = std::lerp(lattice(x0, z0 + 1, seed), lattice(x0 + 1, z0 + 1, seed), tx);
411 return std::lerp(a, b, tz);
412}
413bool normalized(float value) { return std::isfinite(value) && value >= 0 && value <= 1; }
414} // namespace
417 using namespace raster_detail;
418 if (layer.getWidth() <= 0 || layer.getHeight() <= 0 || !validRaster(heights) || !std::isfinite(s.originX) ||
419 !std::isfinite(s.originZ) || !std::isfinite(s.width) || s.width <= 0 || !std::isfinite(s.depth) ||
420 s.depth <= 0 || !std::isfinite(s.heightScale) || !std::isfinite(s.minimumScale) || s.minimumScale <= 0 ||
421 !std::isfinite(s.maximumScale) || s.maximumScale < s.minimumScale || !std::isfinite(s.minimumWidth) ||
422 s.minimumWidth <= 0 || !std::isfinite(s.maximumWidth) || s.maximumWidth < s.minimumWidth ||
423 !std::isfinite(s.minimumHeight) || s.minimumHeight <= 0 || !std::isfinite(s.maximumHeight) ||
424 s.maximumHeight < s.minimumHeight || !normalized(s.healthyR) || !normalized(s.healthyG) ||
425 !normalized(s.healthyB) || !normalized(s.healthyA) || !normalized(s.dryR) || !normalized(s.dryG) ||
426 !normalized(s.dryB) || !normalized(s.dryA) || !normalized(s.noiseSpread) || s.namespaceId == 0 ||
427 s.asset.empty() || s.maxPoints < 0)
428 return invalid("terrain.detailPoints: valid layer, heights, domain, resource and budget required");
429 int total = 0;
430 for (int z = 0; z < layer.getHeight(); ++z)
431 for (int x = 0; x < layer.getWidth(); ++x) {
432 auto count = layer.sampleResource(s.densityNamespaceId, x, z);
433 if (!count.ok()) return Result<int>::failure(count.status());
434 if (count.value() > s.maxPoints - total) return invalid("terrain.detailPoints: point budget exceeded");
435 total += count.value();
436 }
437 PointSet next;
438 next.reserve(size_t(total));
439 for (int z = 0; z < layer.getHeight(); ++z)
440 for (int x = 0; x < layer.getWidth(); ++x) {
441 auto count = layer.sampleResource(s.densityNamespaceId, x, z);
442 if (!count.ok()) return Result<int>::failure(count.status());
443 const auto cell = uint64_t(z) * uint64_t(layer.getWidth()) + uint64_t(x);
444 for (int ordinal = 0; ordinal < count.value(); ++ordinal) {
446 p.id = mix(mix(s.namespaceId + UINT64_C(0x9e3779b97f4a7c15)) ^ ((cell << 32) | uint64_t(ordinal + 1)));
447 if (p.id == 0) return invalid("terrain.detailPoints: reserved zero identity; choose another namespace");
448 const double u = (x + unit(p.id, UINT64_C(0x706f736974696f58), s.seed)) / layer.getWidth();
449 const double v = (z + unit(p.id, UINT64_C(0x706f736974696f5a), s.seed)) / layer.getHeight();
450 const double px = double(s.originX) + u * s.width, pz = double(s.originZ) + v * s.depth;
451 const double py = sample(heights, u, v) * double(s.heightScale);
453 return invalid("terrain.detailPoints: unrepresentable world position");
454 p.x = float(px);
455 p.y = float(py);
456 p.z = float(pz);
457 p.yaw = float(360 * unit(p.id, UINT64_C(0x726f746174696f6e), s.seed));
458 p.scaleX = p.scaleY = p.scaleZ =
459 float(double(s.minimumScale) +
460 (double(s.maximumScale) - s.minimumScale) * unit(p.id, UINT64_C(0x7363616c65), s.seed));
461 const double horizontal =
462 double(p.scaleX) * (double(s.minimumWidth) + (double(s.maximumWidth) - s.minimumWidth) *
463 unit(p.id, UINT64_C(0x7769647468), s.seed));
464 const double vertical =
465 double(p.scaleY) * (double(s.minimumHeight) + (double(s.maximumHeight) - s.minimumHeight) *
466 unit(p.id, UINT64_C(0x686569676874), s.seed));
467 if (!isRepresentable(horizontal) || !isRepresentable(vertical) || float(horizontal) <= 0 ||
468 float(vertical) <= 0)
469 return invalid("terrain.detailPoints: unrepresentable instance dimensions");
470 p.scaleX = p.scaleZ = float(horizontal);
471 p.scaleY = float(vertical);
472 const double colorMix = detailColorNoise(u, v, s.noiseSpread, s.noiseSeed);
473 p.colorR = float(std::lerp(double(s.dryR), double(s.healthyR), colorMix));
474 p.colorG = float(std::lerp(double(s.dryG), double(s.healthyG), colorMix));
475 p.colorB = float(std::lerp(double(s.dryB), double(s.healthyB), colorMix));
476 p.colorA = float(std::lerp(double(s.dryA), double(s.healthyA), colorMix));
477 p.seed = uint32_t(mix(p.id ^ s.seed));
478 const int row = next.appendPoint(p);
479 auto asset = next.trySetStringAttribute(row, "asset", s.asset);
480 if (!asset.ok()) return Result<int>::failure(asset.status());
481 auto source = next.trySetStringAttribute(row, "spawnNamespace", std::to_string(s.namespaceId));
482 if (!source.ok()) return Result<int>::failure(source.status());
483 auto cellAttribute = next.trySetIntAttribute(row, "detailCell", int64_t(cell));
484 if (!cellAttribute.ok()) return Result<int>::failure(cellAttribute.status());
485 auto ordinalAttribute = next.trySetIntAttribute(row, "detailOrdinal", ordinal);
486 if (!ordinalAttribute.ok()) return Result<int>::failure(ordinalAttribute.status());
487 }
488 }
489 static_assert(std::is_nothrow_move_assignable_v<PointSet>);
490 output = std::move(next);
491 return Result<int>::success(total);
492}
493} // namespace eve::procgen
double z
double y
double x
LogicalId target
std::string output
ActiveSource owned
std::size_t cursor
const std::string & s
bool changed
bool applied
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
float u
Definition Grass.cpp:233
float v
std::vector< Colorf > px
std::uint32_t height
std::uint32_t width
Poco::JSON::Object::Ptr result
Snapshot snapshot
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
OceanWakeSettings settings
TileLayer * layer
Object::Ptr value
std::vector< WfcTile > tiles
bool found
std::string_view source
std::map< std::array< int, 4 >, std::vector< const Subject * > > candidates
Definition Sensing.cpp:32
std::string resource
int count
Cell cell
TacticalUnit * unit
Battle::Random random
uint32_t seed
Definition TreeMesh.cpp:276
std::uint32_t depth
uint32_t index
float fraction
uint64_t identity
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
Definition Heightmap.h:21
int getHeight() const
Returns the height.
Definition Heightmap.cpp:17
const std::vector< float > & data() const
Data.
Definition Heightmap.h:48
int getWidth() const
Returns the width.
Definition Heightmap.cpp:16
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
Owned integer terrain-detail layer, independent of graphics and resource registries....
TerrainDetailLayer()
Construct an empty layer.
friend EVENGINE_API_DOMAINS Result< TerrainMultiTileReport > applyTerrainDetailMultiTile(const std::vector< TerrainDetailTile > &, const Heightmap &, const TerrainDetailSettings &, const TerrainStampSettings &, std::int32_t, bool, const std::vector< std::string > &)
Apply one shared Pcg detail-distribution raster to every selected tile atomically.
Result< int > reset(int width, int height, int count=0)
Reset positive dimensions and uniform nonnegative count atomically.
TerrainDetailLayer & operator=(TerrainDetailLayer &&) noexcept
Transfer ownership, releasing previous counts.
Result< int > sample(int x, int z) const
Read an integer value copy; empty state or invalid coordinates return InvalidArgument.
Result< int > clearResource(std::uint64_t namespaceId)
Remove one resource layer atomically and return its changed cell count.
~TerrainDetailLayer()
Release owned counts.
Result< int > apply(const Heightmap &fitness, const TerrainDetailSettings &settings, int32_t seed)
Apply a finite aligned fitness map with source thinning and nearest-even integer rounding.
int getWidth() const noexcept
Return width, zero when empty or moved-from.
int getHeight() const noexcept
Return height, zero when empty or moved-from.
Result< int > sampleResource(std::uint64_t namespaceId, int x, int z) const
Read one resource layer without exposing mutable storage; an absent namespace reads as zero.
Owning script-safe multi-terrain detail transaction workspace. Input layers are copied on insertion....
~TerrainMultiDetailWorkspace()
Terrain multi detail workspace.
TerrainMultiDetailWorkspace()
Terrain multi detail workspace.
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
double sample(const Heightmap &map, double u, double v)
Sample.
bool validRaster(const Heightmap &map)
Valid raster.
Result< int > invalid(std::string message)
Invalid.
bool isRepresentable(double value)
True when representable.
Result< TerrainMultiTileReport > mapTerrainOperationMultiTile(const std::vector< TerrainOperationTile > &tiles, const TerrainStampSettings &settings, TerrainOperationDomain domain, bool worldMapOperation, const std::vector< std::string > &validTerrainNames)
Calculate Pcg-compatible local and shared pixel rectangles for any multi-terrain raster domain.
Result< int > exportTerrainDetailPoints(PointSet &output, const TerrainDetailLayer &layer, const Heightmap &heights, const TerrainDetailPlacementSettings &s)
Expand integer detail counts into the existing attributed PointSet, atomically.
Result< TerrainMultiTileReport > applyTerrainDetailMultiTile(const std::vector< TerrainDetailTile > &tiles, const Heightmap &operationFitness, const TerrainDetailSettings &settings, const TerrainStampSettings &operationSettings, int32_t seed, bool worldMapOperation, const std::vector< std::string > &validTerrainNames)
One deterministic sample used by script-first procedural pipelines.
Definition PointSet.h:17
std::uint64_t id
Stable non-zero identity; zero marks legacy or not-yet-assigned data.
Definition PointSet.h:19
std::map< std::uint64_t, std::vector< int > > resources
Explicit native placement domain and resource for a terrain detail layer.
Effective detail rule settings; density is rule density times global spawn density.
Completed multi-tile stamp statistics and Pcg-compatible affected-pixel mappings.
Value configuration for a rectangular stamp in world X/Z coordinates.
glm::vec4 bounds