载入中...
搜索中...
未找到
CaveGeneration.cpp
浏览该文件的文档.
2
5
6#include <cmath>
7
8namespace eve::procgen {
9namespace {
10Result<void> wrongPhase() {
12 "cave operation requires a different generation stage", {}, {},
13 "procgen.cave"));
14}
15bool editableField(CaveGenerationPhase phase) {
17}
18} // namespace
19
22CaveGeneration::CaveGeneration(CaveGeneration&&) noexcept = default;
23CaveGeneration& CaveGeneration::operator=(CaveGeneration&&) noexcept = default;
24
25CaveGenerationPhase CaveGeneration::phase() const noexcept { return state_ ? phase_ : CaveGenerationPhase::Empty; }
26
28 auto candidate = std::make_unique<cave_detail::State>();
29 candidate->params = params;
30 auto result = candidate->configure();
31 if (!result.ok()) return result;
32 state_ = std::move(candidate);
34 return Result<void>::success();
35}
36
38 if (phase() != CaveGenerationPhase::Configured) return wrongPhase();
39 auto candidate = std::make_unique<cave_detail::State>(*state_);
40 auto result = candidate->skeleton();
41 if (!result.ok()) return result;
42 state_ = std::move(candidate);
44 return Result<void>::success();
45}
46
47int CaveGeneration::chamberCount() const noexcept { return state_ ? int(state_->chambers.size()) : 0; }
48
49Result<void> CaveGeneration::setChamber(int index, float x, float y, float z, float rx, float ry, float rz) {
50 if (phase() != CaveGenerationPhase::Skeleton) return wrongPhase();
51 if (index < 0 || index >= chamberCount() || !std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z) ||
52 !std::isfinite(rx) || !std::isfinite(ry) || !std::isfinite(rz) || rx <= 0.f || ry <= 0.f || rz <= 0.f ||
53 std::abs(x) > 1.f || std::abs(y) > 1.f || std::abs(z) > 1.f || rx > 2.f || ry > 2.f || rz > 2.f) {
55 DiagnosticCode::InvalidArgument, "invalid normalized chamber bounds or index", {}, {}, "procgen.cave"));
56 }
57 auto& chamber = state_->chambers[size_t(index)];
58 chamber.center = {x, y, z};
59 chamber.radii = {rx, ry, rz};
60 state_->breakdownChambers[size_t(index)] = {x, y, z, rx, ry, rz};
61 state_->breakdownSet = createCaveBreakdown(state_->breakdownChambers, state_->breakdownEvents, state_->breakdown,
62 state_->params.getSeed());
63 state_->obstacleScourSites =
64 createCaveObstacleScourSites(state_->breakdownSet, state_->spine, state_->hydrology.trunk, state_->sedimentLoad,
65 state_->multiscaleRoughness);
66 if (index == state_->primaryChamber) state_->primaryChamberVerticalRadius = ry;
67 state_->skeletonEdited = true;
68 return Result<void>::success();
69}
70
72 if (phase() != CaveGenerationPhase::Skeleton) return wrongPhase();
73 auto candidate = std::make_unique<cave_detail::State>(*state_);
74 auto result = candidate->sample();
75 if (!result.ok()) return result;
76 state_ = std::move(candidate);
78 return Result<void>::success();
79}
80
82 if (!editableField(phase())) return wrongPhase();
85 return wrongPhase();
86 auto candidate = std::make_unique<cave_detail::State>(*state_);
87 auto result = candidate->evolve(operation);
88 if (!result.ok()) return result;
89 candidate->surfaceSchedule.push_back(operation);
90 state_ = std::move(candidate);
92 return Result<void>::success();
93}
94
96 if (!editableField(phase())) return wrongPhase();
97 auto candidate = std::make_unique<cave_detail::State>(*state_);
98 auto result = candidate->deposit();
99 if (!result.ok()) return result;
100 candidate->depositsApplied = true;
101 state_ = std::move(candidate);
103 return Result<void>::success();
104}
105
107 if (!editableField(phase()) && phase() != CaveGenerationPhase::Deposited)
108 return Result<ScalarField3D>::failure(wrongPhase().status());
110 auto result = field.assign(state_->nx, state_->ny, state_->nz, state_->density);
111 if (!result.ok()) return Result<ScalarField3D>::failure(result.status());
112 return Result<ScalarField3D>::success(std::move(field));
113}
114
116 if (!editableField(phase())) return wrongPhase();
117 if (field.width() != state_->nx || field.height() != state_->ny || field.depth() != state_->nz)
119 DiagnosticCode::InvalidArgument, "replacement cave field dimensions differ from configured resolution", {},
120 {}, "procgen.cave"));
121 state_->density.assign(field.samples().begin(), field.samples().end());
122 state_->fieldEdited = true;
123 return Result<void>::success();
124}
125
127 if (!editableField(phase()) && phase() != CaveGenerationPhase::Deposited)
128 return Result<MeshBuild>::failure(wrongPhase().status());
129 auto candidate = std::make_unique<cave_detail::State>(*state_);
131 auto result = candidate->mesh(mesh);
132 if (!result.ok()) return Result<MeshBuild>::failure(result.status());
133 return Result<MeshBuild>::success(std::move(mesh));
134}
135} // namespace eve::procgen
double z
double y
double x
ActionParameterOperation operation
wgpu::PopErrorScopeStatus status
Poco::JSON::Object::Ptr result
std::vector< RecipeParam > params
OceanMeshSettings mesh
float phase
uint32_t index
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
Staged limestone generator sharing the canonical mesh.cave algorithms.
Result< void > deposit()
Anchor secondary deposits on the current surface; disallows subsequent surface retreat....
int chamberCount() const noexcept
Number of chamber records in the current skeleton.
~CaveGeneration()
Release owned intermediates without publication.
CaveGenerationPhase phase() const noexcept
Current stage; moved-from owners report Empty and can be configured again.
Result< void > buildSkeleton()
Generate the editable seeded cave skeleton from configured parameters. @cost Linear in skeleton candi...
Result< void > evolveSurface(CaveSurfaceOperation operation)
Apply one selected surface operator; repeated operators and caller-selected order are supported....
Result< MeshBuild > buildMesh() const
Extract an independent mesh from any sampled stage; omitted evolution/deposits stay omitted....
Result< void > replaceField(const ScalarField3D &field)
Replace the field with a same-dimension snapshot before deposition; preserve stage diagnostics....
Result< ScalarField3D > field() const
Return an independent field snapshot; no internal storage is exposed. @cost Linear in volume samples;...
CaveGeneration()
Construct an empty, inexpensive generation owner.
Result< void > configure(const Params &params)
Copy and validate configuration; success resets all derived stages.
Result< void > sampleField()
Sample the current skeleton and configured geological operators. @cost Volume samples times active ge...
Result< void > setChamber(int index, float x, float y, float z, float rx, float ry, float rz)
Edit one chamber in normalized [-1,1] coordinates before sampling; radii must be positive.
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:20
Owning, typed generation parameters.
Definition Params.h:27
Owning regular scalar volume; x is contiguous, followed by y and z.
Result< void > assign(int nx, int ny, int nz, std::span< const float > samples)
Atomically copy finite samples of a correctly sized volume. @cost Linear in sample count,...
CaveSurfaceOperation
Independently composable surface operators; order is chosen by the caller.
std::vector< CaveObstacleScourSite > createCaveObstacleScourSites(const CaveBreakdownSet &breakdown, const std::vector< CaveHydrologyPoint > &trunk, const std::vector< float > &hydraulicWeights, float sedimentLoad, float wallRoughness)
Couple landed breakdown blocks to the nearest authoritative cave-stream segment.
CaveGenerationPhase
Ordered admission states of an editable cave build.
CaveBreakdownSet createCaveBreakdown(const std::vector< CaveBreakdownChamber > &chambers, int eventCount, float strength, uint32_t seed)
Create paired ceiling-spall scars and floor blocks from host chambers.