载入中...
搜索中...
未找到
GeneratedArtifact.cpp
浏览该文件的文档.
66 return bounds.valid && std::isfinite(bounds.minX) && std::isfinite(bounds.minY) && std::isfinite(bounds.minZ) &&
72 if (mesh.empty() || mesh.positions().size() % 3u != 0u || mesh.indices().size() % 3u != 0u) return false;
81 std::all_of(mesh.uvs().begin(), mesh.uvs().end(), [](float value) { return std::isfinite(value); }) &&
115 return !part.role.empty() && !part.id.isNil() && !part.schemaVersion.isZero() && !part.buildKey.empty() &&
152 eve::DiagnosticCode::InvalidArgument, "artifact publish batch must not be empty", "artifacts"));
159 eve::DiagnosticCode::InvalidArgument, "artifact structure or typed payload is invalid", "artifact"));
178 [&typeFor](ArtifactType type, const std::vector<ArtifactId> &dependencies) -> std::optional<eve::Diagnostic> {
284eve::Value encodeVectorMap(const std::unordered_map<std::string, ProcgenAttributeVector> &values) {
499bool readStringValue(const eve::Value::Object &object, const char *name, std::string &output, bool allowEmpty = false) {
562 if (!integer || *integer < 0 || static_cast<std::uint64_t>(*integer) > std::numeric_limits<T>::max())
567 if (!integer || *integer < std::numeric_limits<T>::min() || *integer > std::numeric_limits<T>::max())
577 if (!object || !readFloatValue(*object, "minX", bounds.minX) || !readFloatValue(*object, "minY", bounds.minY) ||
578 !readFloatValue(*object, "minZ", bounds.minZ) || !readFloatValue(*object, "maxX", bounds.maxX) ||
579 !readFloatValue(*object, "maxY", bounds.maxY) || !readFloatValue(*object, "maxZ", bounds.maxZ) ||
585bool decodeStringMap(const eve::Value *encoded, std::unordered_map<std::string, std::string> &output) {
687std::optional<ArtifactType> decodeArtifactType(const eve::Value::Object &object, const char *name = "type") {
690 for (const ArtifactType type : {ArtifactType::Grid, ArtifactType::PointSet, ArtifactType::MeshData,
710 if (!wrapper || !readStringValue(*wrapper, "kind", kind) || kind != artifactTypeName(type) || !data) return false;
720 if (!readIntValue(*object, "width", width) || !readIntValue(*object, "height", height) || width <= 0 ||
721 height <= 0 || width > std::numeric_limits<int>::max() || height > std::numeric_limits<int>::max() ||
741 !readFloatValue(*item, "height", objectHeight) || !readIntValue(*item, "gid", gid) || gid < 0 ||
751 const auto *encodedPoints = encodedPointsValue ? encodedPointsValue->getIf<eve::Value::Array>() : nullptr;
766 !readFloatValue(*item, "normalY", point.normalY) || !readFloatValue(*item, "normalZ", point.normalZ) ||
769 !readOptionalFloatValue(*item, "roll", point.roll) || !readFloatValue(*item, "scaleX", point.scaleX) ||
770 !readFloatValue(*item, "scaleY", point.scaleY) || !readFloatValue(*item, "scaleZ", point.scaleZ) ||
771 !readFloatValue(*item, "density", point.density) || !readIntValue(*item, "seed", seed) || seed < 0 ||
805 if (!points.trySetVectorAttribute(pointIndex, name, value.x, value.y, value.z).ok()) return false;
818 const auto *encodedNames = encodedNamesValue ? encodedNamesValue->getIf<eve::Value::Array>() : nullptr;
826 !readIntValue(*object, "activeGroup", activeGroup) || activeGroup < std::numeric_limits<int>::min() ||
847 channels > std::numeric_limits<int>::max() || !readStringValue(*object, "format", image.format) ||
879 object && readStringValue(*object, "artifactId", idText) ? ArtifactId::parse(idText) : std::nullopt;
880 if (!object || !readStringValue(*object, "role", role) || !parsedId || parsedId->isNil() || !type ||
882 !readStringValue(*object, "buildKey", buildKeyText) || !decodeBounds(stateMember(*object, "bounds"), bounds) ||
906 object && readStringValue(*object, "artifactId", idText) ? ArtifactId::parse(idText) : std::nullopt;
907 if (!object || !parsedId || parsedId->isNil() || !type || !decodeSchemaVersion(*object, schemaVersion) ||
908 !readStringValue(*object, "buildKey", buildKeyText) || !decodeBounds(stateMember(*object, "bounds"), bounds) ||
917 const auto *payloadObject = payloadObjectValue ? payloadObjectValue->getIf<eve::Value::Object>() : nullptr;
919 const auto *encodedChildren = payloadObject ? stateMember(*payloadObject, "children") : nullptr;
922 if (!payloadObject || !readStringValue(*payloadObject, "kind", kind) || kind != "composite" || !children)
940 auto result = makeArtifact(*parsedId, *type, schemaVersion, *key, bounds, std::move(dependencies),
988 const std::uint32_t value = seed ^ (std::uint32_t(x) * 0x9e3779b9u) ^ (std::uint32_t(y) * 0x85ebca6bu);
1008 anchors.add(float(width - 1) * xStep, 0.f, (float(height - 1) + float((width - 1) & 1) * .5f) * zStep);
1031 const float keepWidth = std::clamp(params.getFloat("keepWidth", width * .25f), 6.f, width * .55f);
1032 const float keepDepth = std::clamp(params.getFloat("keepDepth", depth * .24f), 6.f, depth * .55f);
1047eve::Result<ArtifactPart> partFromMesh(std::string role, ArtifactId parent, const BuildKey &parentKey, MeshBuild mesh,
1051 return rejectedPart(eve::DiagnosticCode::InvalidArgument, "cannot derive child build key for " + role);
1054 return makeArtifactPart(std::move(role), childId, ArtifactType::MeshData, eve::SchemaVersion(1),
1058eve::Result<ArtifactPart> partFromCollider(std::string role, ArtifactId parent, const BuildKey &parentKey,
1062 return rejectedPart(eve::DiagnosticCode::InvalidArgument, "cannot derive child build key for " + role);
1065 return makeArtifactPart(std::move(role), childId, ArtifactType::Collider, eve::SchemaVersion(1),
1070eve::Result<ArtifactPart> partFromGrid(std::string role, ArtifactId parent, const BuildKey &parentKey, Grid2D grid,
1074 return rejectedPart(eve::DiagnosticCode::InvalidArgument, "cannot derive child build key for " + role);
1077 return makeArtifactPart(std::move(role), childId, ArtifactType::Grid, eve::SchemaVersion(1), std::move(*childKey),
1081eve::Result<ArtifactPart> partFromPoints(std::string role, ArtifactId parent, const BuildKey &parentKey,
1085 return rejectedPart(eve::DiagnosticCode::InvalidArgument, "cannot derive child build key for " + role);
1088 return makeArtifactPart(std::move(role), childId, ArtifactType::PointSet, eve::SchemaVersion(1),
1093bool appendPart(eve::Result<ArtifactPart> &&result, std::vector<ArtifactPart> &parts, eve::Status &failure) {
1102eve::Result<GeneratedArtifact> generateComposite(const Params ¶ms, ArtifactId id, std::string_view recipe,
1106 return rejectedArtifact(eve::DiagnosticCode::InvalidArgument, "top-level artifact identity must not be nil");
1109 return rejectedArtifact(eve::DiagnosticCode::InvalidArgument, "recipe or parameters cannot form a build key");
1137 auto topologyPart = partFromGrid("topology", id, *key, std::move(topology), std::move(topologyMeta));
1144 auto anchorsPart = partFromPoints("anchors", id, *key, std::move(anchors), std::move(anchorsMeta));
1156 return makeArtifact(id, ArtifactType::Composite, eve::SchemaVersion(1), *key, bounds, {}, std::move(metadata),
1224 return finiteBounds(bounds) && !shape.empty() && vertices.size() % 3u == 0u && indices.size() % 3u == 0u &&
1233 std::find_if(children.begin(), children.end(), [&](const ArtifactPart &part) { return part.role == role; });
1263eve::Result<GeneratedArtifact> makeArtifact(ArtifactId id, ArtifactType type, eve::SchemaVersion schemaVersion,
1276 return rejectedArtifact(eve::DiagnosticCode::InvalidArgument, "artifact structure or typed payload is invalid");
1307eve::Result<std::vector<ArtifactId>> ArtifactStore::publishBatch(std::vector<GeneratedArtifact> artifacts) {
1310 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "artifact store already has a pending stage"));
1313 eve::DiagnosticCode::InvalidArgument, "artifact publish batch must not be empty", "artifacts"));
1332 eve::DiagnosticCode::InvalidArgument, "artifact structure or typed payload is invalid", "artifact"));
1335 eve::DiagnosticCode::Conflict, "artifact or part identity is already published", "artifact.id"));
1394 eve::DiagnosticCode::Failed, "artifact store allocation failed; batch rolled back", "artifacts"));
1403 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "artifact store already has a pending stage"));
1409 return eve::Result<std::unique_ptr<eve::artifact::PreparedPublication>>::failure(valid.status());
1424 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store stage allocation failed"));
1453 std::find_if(children.begin(), children.end(), [id](const ArtifactPart &part) { return part.id == id; });
1487 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "artifact identity is not published", "artifact.id"));
1509 std::sort(ids.begin(), ids.end(), [](ArtifactId lhs, ArtifactId rhs) { return lhs.format() < rhs.format(); });
1522 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store snapshot allocation failed"));
1529 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "artifact store restore requires an empty store"));
1536 const auto *encodedList = encodedArtifacts ? encodedArtifacts->getIf<eve::Value::Array>() : nullptr;
1537 if (!object || !providerName || *providerName != "procgen.cpu-artifact-store" || !version || *version != 2 ||
1549 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "invalid dense artifact store record"));
1554 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store restore allocation failed"));
1576 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store restore indexing allocation failed"));
1583eve::Result<GeneratedArtifact> generateHexTerrainArtifact(const Params ¶ms, ArtifactId id) {
1584 return generateComposite(params, id, "mesh.hexterrain", generateHexTerrainMesh, makeHexTopology(params),
1589 return generateComposite(params, id, "mesh.castle", generateCastleMesh, makeCastleTopology(params),
1593eve::Result<GeneratedArtifact> generateMeshArtifact(std::string_view recipeId, const Params ¶ms, ArtifactId id) {
1598 return rejectedArtifact(eve::DiagnosticCode::InvalidArgument, "top-level artifact identity must not be nil");
1601 return rejectedArtifact(eve::DiagnosticCode::InvalidArgument, "recipe or parameters cannot form a build key");
1612 return makeArtifact(id, ArtifactType::MeshData, eve::SchemaVersion(1), *key, bounds, {}, std::move(metadata),
std::map< std::string, std::vector< Key >, std::less<> > channels
Definition AnimCurveLibrary.cpp:19
Owning, backend-neutral products published by procedural generation.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:124
A prepared consumer mutation with a non-throwing visibility boundary.
Definition ArtifactPublication.h:102
static std::optional< Id128 > parse(std::string_view text) noexcept
Parses canonical UUID text.
Definition Identity.h:151
Id128 child(std::string_view role) const noexcept
Derives a deterministic child UUID for a hierarchical identity.
Definition Identity.h:192
void rollback() noexcept override
Discard the prepared mutation; idempotent and non-throwing.
Definition GeneratedArtifact.cpp:1175
ArtifactStoreStage(ArtifactStore &owner, std::vector< GeneratedArtifact > artifacts)
Definition GeneratedArtifact.cpp:1164
void commit() noexcept override
Make the prepared mutation observable; the operation cannot fail.
Definition GeneratedArtifact.cpp:1169
~ArtifactStoreStage() override
Definition GeneratedArtifact.cpp:1167
In-memory owner and publisher for generated artifacts.
Definition GeneratedArtifact.h:227
std::optional< ArtifactType > typeOf(ArtifactId id) const noexcept
Return the kind of a live identity or composite part.
Definition GeneratedArtifact.cpp:1457
std::size_t partCount() const noexcept
Return the number of indexed composite child products.
Definition GeneratedArtifact.cpp:1502
eve::Result< std::unique_ptr< eve::artifact::PreparedPublication > > stagePublish(GeneratedArtifact artifact)
Prepare one store mutation for a larger provider transaction.
Definition GeneratedArtifact.cpp:1399
const ArtifactPart * findPart(ArtifactId id) const noexcept
Look up a composite child part.
Definition GeneratedArtifact.cpp:1446
eve::Result< ArtifactId > publish(GeneratedArtifact artifact)
Validate and atomically publish one artifact and all composite parts.
Definition GeneratedArtifact.cpp:1300
std::vector< ArtifactId > findByBuildKey(const BuildKey &key) const
Find all identities with a matching deterministic build key.
Definition GeneratedArtifact.cpp:1473
const GeneratedArtifact * find(ArtifactId id) const noexcept
Look up a published artifact.
Definition GeneratedArtifact.cpp:1441
eve::Result< void > restoreState(const eve::Value &state)
Restore complete identity/build-key and typed payload state transactionally.
Definition GeneratedArtifact.cpp:1526
eve::Result< eve::Value > snapshotState() const
Export identity, build-key and complete typed dense payload state.
Definition GeneratedArtifact.cpp:1504
eve::Result< std::vector< ArtifactId > > publishBatch(std::vector< GeneratedArtifact > artifacts)
Validate and atomically publish a dependency-connected batch.
Definition GeneratedArtifact.cpp:1307
eve::Result< void > remove(ArtifactId id)
Remove one artifact; NotFound is returned when absent.
Definition GeneratedArtifact.cpp:1483
Stable key for deterministic-equivalent generation inputs.
Definition GeneratedArtifact.h:46
static std::optional< BuildKey > fromCanonical(std::string_view canonical)
Construct a build key from canonical text.
Definition GeneratedArtifact.cpp:1187
static std::optional< BuildKey > forRecipe(std::string_view recipeId, const Params ¶ms)
Derive a compact deterministic key for a recipe and parameters.
Definition GeneratedArtifact.cpp:1192
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:19
static MeshRecipeRegistry & instance()
Access the process-wide mesh recipe registry.
Definition MarchingCubes.cpp:451
@ ImageData
@ Collider
@ PointSet
Definition EvpackPointGraphLoader.h:12
EVENGINE_API_DOMAINS eve::Result< GeneratedArtifact > generateRoadNetworkArtifact(const Params ¶ms, ArtifactId id)
Generate a road composite containing mesh, collider, terrain footprint, navigation and placement poin...
Definition RoadArtifact.cpp:356
eve::Result< GeneratedArtifact > generateHexTerrainArtifact(const Params ¶ms, ArtifactId id)
Generate a hex-terrain composite containing mesh, collider, topology and world anchors.
Definition GeneratedArtifact.cpp:1583
eve::Result< GeneratedArtifact > generateMeshArtifact(std::string_view recipeId, const Params ¶ms, ArtifactId id)
Generate any registered mesh recipe as a CPU artifact.
Definition GeneratedArtifact.cpp:1593
ArtifactType artifactType(const GeneratedArtifact::Payload &payload) noexcept
Return the variant kind for a payload.
Definition GeneratedArtifact.cpp:1237
bool generateHexTerrainMesh(const Params ¶ms, MeshBuild &out, std::string &error)
Build a deterministic, flat-top hexagonal continent mesh.
Definition HexTerrain.cpp:375
bool generateCastleMesh(const Params &p, MeshBuild &out, std::string &error)
Build a complete, walkable, multi-ring medieval castle.
Definition CastleMesh.cpp:104
const char * artifactTypeName(ArtifactType type) noexcept
Return the stable textual spelling of an artifact kind.
Definition GeneratedArtifact.cpp:1251
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.
Definition GeneratedArtifact.cpp:1280
MeshBuild MeshData
Existing dense CPU mesh type under the artifact vocabulary.
Definition GeneratedArtifact.h:142
ArtifactType
Runtime payload kind; it is checked against the variant on publish.
Definition GeneratedArtifact.h:109
@ ImageData
@ Composite
@ MeshData
@ Collider
@ PointSet
eve::ArtifactId ArtifactId
Common strong UUID identity for one published procedural artifact.
Definition GeneratedArtifact.h:43
std::variant< Grid2D, PointSet, MeshData, ImageData, Collider > ArtifactLeafPayload
Leaf payloads used by a CompositeArtifact.
Definition GeneratedArtifact.h:145
eve::Result< GeneratedArtifact > generateCastleArtifact(const Params ¶ms, ArtifactId id)
Generate a castle composite containing mesh, collider, ring topology and gate/keep anchors.
Definition GeneratedArtifact.cpp:1588
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.
Definition GeneratedArtifact.cpp:1263
WidgetDesc child(std::string id, std::vector< WidgetDesc > children, float width, float height)
Scrollable child region with an explicit size.
Definition Widget.cpp:635
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
Definition Widget.cpp:687
@ InvalidArgument
@ NotFound
@ UnknownVersion
@ PreconditionViolation
@ Failed
@ ParseError
@ Conflict
@ Applied
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Definition SchemaVersion.h:13
Definition Container.h:602
One typed, role-named child product inside a composite artifact.
Definition GeneratedArtifact.h:148
eve::SchemaVersion schemaVersion
Definition GeneratedArtifact.h:151
std::vector< ArtifactId > dependencies
Definition GeneratedArtifact.h:154
Axis-aligned bounds in the artifact's declared world coordinate space.
Definition GeneratedArtifact.h:93
void include(float x, float y, float z) noexcept
Expand this box to include one point.
Definition GeneratedArtifact.cpp:1200
std::vector< std::uint32_t > indices
Definition GeneratedArtifact.h:133
bool isValid() const noexcept
Return whether the collider has complete triangle data.
Definition GeneratedArtifact.cpp:1223
A coherent set of products published from one deterministic build.
Definition GeneratedArtifact.h:161
const ArtifactPart * find(std::string_view role) const noexcept
Find a child by its stable role.
Definition GeneratedArtifact.cpp:1231
Complete immutable-once-published artifact record.
Definition GeneratedArtifact.h:181
std::variant< Grid2D, PointSet, MeshData, ImageData, Collider, CompositeArtifact > Payload
Definition GeneratedArtifact.h:189
std::vector< ArtifactId > dependencies
Definition GeneratedArtifact.h:187
eve::Value::Object metadata
Definition GeneratedArtifact.h:188
eve::SchemaVersion schemaVersion
Definition GeneratedArtifact.h:184
bool isValid() const noexcept
Return whether dimensions and pixel storage describe an image.
Definition GeneratedArtifact.cpp:1216