载入中...
搜索中...
未找到
GeneratedArtifact.h
浏览该文件的文档.
1#pragma once
2
13#include "common/Generation.h"
14#include "common/Identity.h"
15#include "common/Result.h"
17#include "common/Snapshot.h"
18#include "common/Value.h"
19#include "procgen/Grid2D.h"
20#include "procgen/MeshBuild.h"
21#include "procgen/Params.h"
22#include "procgen/PointSet.h"
23
24#include <cstdint>
25#include <functional>
26#include <memory>
27#include <optional>
28#include <string>
29#include <string_view>
30#include <unordered_map>
31#include <utility>
32#include <variant>
33#include <vector>
34
35namespace eve::procgen {
36
44
47public:
49 BuildKey() = default;
50
56 [[nodiscard]] static std::optional<BuildKey> fromCanonical(std::string_view canonical);
57
64 [[nodiscard]] static std::optional<BuildKey> forRecipe(std::string_view recipeId, const Params& params);
65
67 [[nodiscard]] bool empty() const noexcept { return value_.empty(); }
69 [[nodiscard]] const std::string& format() const noexcept { return value_; }
70 friend bool operator==(const BuildKey&, const BuildKey&) noexcept = default;
71
72private:
73 explicit BuildKey(std::string value) : value_(std::move(value)) {}
74 std::string value_;
75};
76
77} // namespace eve::procgen
78
79namespace std {
80template <>
82struct hash<eve::procgen::BuildKey> {
84 size_t operator()(const eve::procgen::BuildKey& key) const noexcept {
85 return std::hash<std::string>{}(key.format());
86 }
87};
88} // namespace std
89
90namespace eve::procgen {
91
94 float minX = 0.f;
95 float minY = 0.f;
96 float minZ = 0.f;
97 float maxX = 0.f;
98 float maxY = 0.f;
99 float maxZ = 0.f;
100 bool valid = false;
101
103 void include(float x, float y, float z) noexcept;
105 [[nodiscard]] bool isValid() const noexcept { return valid; }
106};
107
109enum class ArtifactType : std::uint8_t {
110 Grid,
111 PointSet,
112 MeshData,
113 ImageData,
114 Collider,
115 Composite,
116};
117
119struct ImageData {
120 int width = 0;
121 int height = 0;
122 int channels = 0;
123 std::string format;
124 std::vector<std::uint8_t> pixels;
125
127 [[nodiscard]] bool isValid() const noexcept;
128};
129
132 std::vector<float> vertices;
133 std::vector<std::uint32_t> indices;
135 std::string shape = "triangle_mesh";
136
138 [[nodiscard]] bool isValid() const noexcept;
139};
140
143
146
159
162 std::vector<ArtifactPart> children;
163
175 [[nodiscard]] const ArtifactPart* find(std::string_view role) const noexcept;
177 [[nodiscard]] bool has(std::string_view role) const noexcept { return find(role) != nullptr; }
178};
179
183 ArtifactType type = ArtifactType::Grid;
184 eve::SchemaVersion schemaVersion{1};
187 std::vector<ArtifactId> dependencies;
189 using Payload = std::variant<Grid2D, PointSet, MeshData, ImageData, Collider, CompositeArtifact>;
191};
192
194[[nodiscard]] ArtifactType artifactType(const GeneratedArtifact::Payload& payload) noexcept;
204[[nodiscard]] const char* artifactTypeName(ArtifactType type) noexcept;
205
212 std::vector<ArtifactId> dependencies, eve::Value::Object metadata, GeneratedArtifact::Payload payload);
213
216 std::string role, ArtifactId id, ArtifactType type, eve::SchemaVersion schemaVersion, BuildKey buildKey,
217 Bounds bounds, std::vector<ArtifactId> dependencies, eve::Value::Object metadata, ArtifactLeafPayload payload);
218
228public:
235 [[nodiscard]] eve::Result<ArtifactId> publish(GeneratedArtifact artifact);
236
244 [[nodiscard]] eve::Result<std::vector<ArtifactId>> publishBatch(std::vector<GeneratedArtifact> artifacts);
245
253 GeneratedArtifact artifact);
254
259 [[nodiscard]] eve::Result<eve::Value> snapshotState() const;
260
269 [[nodiscard]] eve::Result<void> restoreState(const eve::Value& state);
270
282 [[nodiscard]] const GeneratedArtifact* find(ArtifactId id) const noexcept;
294 [[nodiscard]] const ArtifactPart* findPart(ArtifactId id) const noexcept;
296 [[nodiscard]] std::optional<ArtifactType> typeOf(ArtifactId id) const noexcept;
298 [[nodiscard]] std::vector<ArtifactId> findByBuildKey(const BuildKey& key) const;
300 [[nodiscard]] eve::Result<void> remove(ArtifactId id);
302 void clear() noexcept;
304 [[nodiscard]] std::size_t size() const noexcept { return artifacts_.size(); }
306 [[nodiscard]] std::size_t partCount() const noexcept;
307
308private:
309 friend class ArtifactStoreStage;
310 void commitStaged(std::vector<GeneratedArtifact> artifacts) noexcept;
311 void rollbackStaged() noexcept;
312
313 std::unordered_map<ArtifactId, GeneratedArtifact> artifacts_;
314 std::unordered_map<ArtifactId, ArtifactId> partOwners_;
315 bool stageActive_ = false;
316};
317
325[[nodiscard]] EVENGINE_API_DOMAINS eve::Result<GeneratedArtifact> generateHexTerrainArtifact(const Params& params,
326 ArtifactId id);
327
335[[nodiscard]] EVENGINE_API_DOMAINS eve::Result<GeneratedArtifact> generateCastleArtifact(const Params& params,
336 ArtifactId id);
337
348[[nodiscard]] EVENGINE_API_DOMAINS eve::Result<GeneratedArtifact> generateRoadNetworkArtifact(const Params& params,
349 ArtifactId id);
350
358[[nodiscard]] EVENGINE_API_DOMAINS eve::Result<GeneratedArtifact> generateMeshArtifact(std::string_view recipeId,
359 const Params& params,
360 ArtifactId id);
361
362} // namespace eve::procgen
double value
Value::Object payload
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
Low-level capability contracts for publishing backend-neutral artifacts.
std::string variant
std::array< std::uint8_t, 32 > hash
Definition Evpack.cpp:172
#define EVENGINE_API_DOMAINS
Definition Export.h:110
Runtime replacement generation for stale-handle rejection.
std::uint32_t key
ShaderImageInput shape
Strong identity values shared by persistence, content and logical-name APIs.
bool valid
Move-only, checked operation results for the common layer.
Persistent data-contract version identity.
Versioned, integrity-checked persistence envelopes.
Owning, renderer-independent dynamic values.
Move-only operation result carrying either a value or Status.
Definition Result.h:155
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
Id128 public API.
Definition Identity.h:112
In-memory owner and publisher for generated artifacts.
std::size_t size() const noexcept
Return the number of published top-level artifacts.
Stable key for deterministic-equivalent generation inputs.
friend bool operator==(const BuildKey &, const BuildKey &) noexcept=default
BuildKey()=default
Construct an empty invalid build key.
const std::string & format() const noexcept
Return canonical key text.
bool empty() const noexcept
Return whether this key is non-empty.
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
Definition Grid2D.h:36
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:19
Owning, typed generation parameters.
Definition Params.h:27
Script-friendly collection of attributed 3D samples.
Definition PointSet.h:59
std::vector< ParamSpec > params
Result< int > publish(Heightmap &target, std::vector< float > candidate)
Publish.
ArtifactType artifactType(const GeneratedArtifact::Payload &payload) noexcept
Return the variant kind for a payload.
const char * artifactTypeName(ArtifactType type) noexcept
Return the stable textual spelling of an artifact kind.
eve::Result< ArtifactPart > makeArtifactPart(std::string role, ArtifactId id, ArtifactType type, eve::SchemaVersion schemaVersion, BuildKey buildKey, Bounds bounds, std::vector< ArtifactId > dependencies, eve::Value::Object metadata, ArtifactLeafPayload payload)
Validate and construct a leaf part for a composite artifact.
MeshBuild MeshData
Existing dense CPU mesh type under the artifact vocabulary.
ArtifactType
Runtime payload kind; it is checked against the variant on publish.
std::variant< Grid2D, PointSet, MeshData, ImageData, Collider > ArtifactLeafPayload
Leaf payloads used by a CompositeArtifact.
eve::Result< GeneratedArtifact > makeArtifact(ArtifactId id, ArtifactType type, eve::SchemaVersion schemaVersion, BuildKey buildKey, Bounds bounds, std::vector< ArtifactId > dependencies, eve::Value::Object metadata, GeneratedArtifact::Payload payload)
Validate and construct one artifact record.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
StrongUuid< detail::ArtifactIdTag > ArtifactId
Stable generated-artifact identity; content equivalence remains ContentId.
Definition Identity.h:282
One typed, role-named child product inside a composite artifact.
std::vector< ArtifactId > dependencies
Axis-aligned bounds in the artifact's declared world coordinate space.
bool isValid() const noexcept
Return whether the box encloses at least one point.
Backend-neutral collider product, normally a triangle mesh or hull.
std::vector< float > vertices
std::vector< std::uint32_t > indices
A coherent set of products published from one deterministic build.
bool has(std::string_view role) const noexcept
Return whether a role exists.
std::vector< ArtifactPart > children
Complete immutable-once-published artifact record.
std::variant< Grid2D, PointSet, MeshData, ImageData, Collider, CompositeArtifact > Payload
std::vector< ArtifactId > dependencies
Small owning image product; raw pixels stay out of JSON metadata.
std::vector< std::uint8_t > pixels
bool isValid() const noexcept
Return whether dimensions and pixel storage describe an image.
glm::vec4 bounds