载入中...
搜索中...
未找到
GeneratedArtifact.cpp
浏览该文件的文档.
40 return bounds.valid && std::isfinite(bounds.minX) && std::isfinite(bounds.minY) && std::isfinite(bounds.minZ) &&
75 return !part.role.empty() && !part.id.isNil() && !part.schemaVersion.isZero() && !part.buildKey.empty() &&
112 eve::DiagnosticCode::InvalidArgument, "artifact publish batch must not be empty", "artifacts"));
119 eve::DiagnosticCode::InvalidArgument, "artifact structure or typed payload is invalid", "artifact"));
138 [&typeFor](ArtifactType type, const std::vector<ArtifactId> &dependencies) -> std::optional<eve::Diagnostic> {
244eve::Value encodeVectorMap(const std::unordered_map<std::string, ProcgenAttributeVector> &values) {
442bool readStringValue(const eve::Value::Object &object, const char *name, std::string &output, bool allowEmpty = false) {
443 auto parsed = allowEmpty ? eve::readStringMember(object, name) : eve::readNonEmptyStringMember(object, name);
506 if (!integer || *integer < 0 || static_cast<std::uint64_t>(*integer) > std::numeric_limits<T>::max())
511 if (!integer || *integer < std::numeric_limits<T>::min() || *integer > std::numeric_limits<T>::max())
521 if (!object || !readFloatValue(*object, "minX", bounds.minX) || !readFloatValue(*object, "minY", bounds.minY) ||
522 !readFloatValue(*object, "minZ", bounds.minZ) || !readFloatValue(*object, "maxX", bounds.maxX) ||
523 !readFloatValue(*object, "maxY", bounds.maxY) || !readFloatValue(*object, "maxZ", bounds.maxZ) ||
529bool decodeStringMap(const eve::Value *encoded, std::unordered_map<std::string, std::string> &output) {
631std::optional<ArtifactType> decodeArtifactType(const eve::Value::Object &object, const char *name = "type") {
634 for (const ArtifactType type : {ArtifactType::Grid, ArtifactType::PointSet, ArtifactType::MeshData,
654 if (!wrapper || !readStringValue(*wrapper, "kind", kind) || kind != artifactTypeName(type) || !data) return false;
664 if (!readIntValue(*object, "width", width) || !readIntValue(*object, "height", height) || width <= 0 ||
665 height <= 0 || width > std::numeric_limits<int>::max() || height > std::numeric_limits<int>::max() ||
685 !readFloatValue(*item, "height", objectHeight) || !readIntValue(*item, "gid", gid) || gid < 0 ||
695 const auto *encodedPoints = encodedPointsValue ? encodedPointsValue->getIf<eve::Value::Array>() : nullptr;
710 !readFloatValue(*item, "normalY", point.normalY) || !readFloatValue(*item, "normalZ", point.normalZ) ||
713 !readOptionalFloatValue(*item, "roll", point.roll) || !readFloatValue(*item, "scaleX", point.scaleX) ||
714 !readFloatValue(*item, "scaleY", point.scaleY) || !readFloatValue(*item, "scaleZ", point.scaleZ) ||
715 !readFloatValue(*item, "density", point.density) || !readIntValue(*item, "seed", seed) || seed < 0 ||
749 if (!points.trySetVectorAttribute(pointIndex, name, value.x, value.y, value.z).ok()) return false;
762 const auto *encodedNames = encodedNamesValue ? encodedNamesValue->getIf<eve::Value::Array>() : nullptr;
770 !readIntValue(*object, "activeGroup", activeGroup) || activeGroup < std::numeric_limits<int>::min() ||
795 channels > std::numeric_limits<int>::max() || !readStringValue(*object, "format", image.format) ||
827 object && readStringValue(*object, "artifactId", idText) ? ArtifactId::parse(idText) : std::nullopt;
828 if (!object || !readStringValue(*object, "role", role) || !parsedId || parsedId->isNil() || !type ||
830 !readStringValue(*object, "buildKey", buildKeyText) || !decodeBounds(stateMember(*object, "bounds"), bounds) ||
854 object && readStringValue(*object, "artifactId", idText) ? ArtifactId::parse(idText) : std::nullopt;
855 if (!object || !parsedId || parsedId->isNil() || !type || !decodeSchemaVersion(*object, schemaVersion) ||
856 !readStringValue(*object, "buildKey", buildKeyText) || !decodeBounds(stateMember(*object, "bounds"), bounds) ||
865 const auto *payloadObject = payloadObjectValue ? payloadObjectValue->getIf<eve::Value::Object>() : nullptr;
867 const auto *encodedChildren = payloadObject ? stateMember(*payloadObject, "children") : nullptr;
870 if (!payloadObject || !readStringValue(*payloadObject, "kind", kind) || kind != "composite" || !children)
888 auto result = makeArtifact(*parsedId, *type, schemaVersion, *key, bounds, std::move(dependencies),
946 return finiteBounds(bounds) && !shape.empty() && vertices.size() % 3u == 0u && indices.size() % 3u == 0u &&
955 std::find_if(children.begin(), children.end(), [&](const ArtifactPart &part) { return part.role == role; });
985eve::Result<GeneratedArtifact> makeArtifact(ArtifactId id, ArtifactType type, eve::SchemaVersion schemaVersion,
998 return rejectedArtifact(eve::DiagnosticCode::InvalidArgument, "artifact structure or typed payload is invalid");
1029eve::Result<std::vector<ArtifactId>> ArtifactStore::publishBatch(std::vector<GeneratedArtifact> artifacts) {
1032 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "artifact store already has a pending stage"));
1035 eve::DiagnosticCode::InvalidArgument, "artifact publish batch must not be empty", "artifacts"));
1054 eve::DiagnosticCode::InvalidArgument, "artifact structure or typed payload is invalid", "artifact"));
1057 eve::DiagnosticCode::Conflict, "artifact or part identity is already published", "artifact.id"));
1116 eve::DiagnosticCode::Failed, "artifact store allocation failed; batch rolled back", "artifacts"));
1125 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "artifact store already has a pending stage"));
1131 return eve::Result<std::unique_ptr<eve::artifact::PreparedPublication>>::failure(valid.status());
1146 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store stage allocation failed"));
1175 std::find_if(children.begin(), children.end(), [id](const ArtifactPart &part) { return part.id == id; });
1209 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "artifact identity is not published", "artifact.id"));
1231 std::sort(ids.begin(), ids.end(), [](ArtifactId lhs, ArtifactId rhs) { return lhs.format() < rhs.format(); });
1244 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store snapshot allocation failed"));
1251 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "artifact store restore requires an empty store"));
1258 const auto *encodedList = encodedArtifacts ? encodedArtifacts->getIf<eve::Value::Array>() : nullptr;
1259 if (!object || !providerName || *providerName != "procgen.cpu-artifact-store" || !version || *version != 2 ||
1271 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "invalid dense artifact store record"));
1276 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store restore allocation failed"));
1298 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "artifact store restore indexing allocation failed"));
std::map< std::string, std::vector< Key >, std::less<> > channels
Definition AnimCurveLibrary.cpp:21
Owning, backend-neutral products published by procedural generation.
ScriptMotionSinkStore< ScriptMotionSink< MotionColorTraits > > colors
Definition MotionScriptBindings.cpp:218
Share string attribute map operations through the Windows Foundation DLL.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:244
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:150
void rollback() noexcept override
Discard the prepared mutation; idempotent and non-throwing.
Definition GeneratedArtifact.cpp:910
ArtifactStoreStage(ArtifactStore &owner, std::vector< GeneratedArtifact > artifacts)
Definition GeneratedArtifact.cpp:899
void commit() noexcept override
Make the prepared mutation observable; the operation cannot fail.
Definition GeneratedArtifact.cpp:904
~ArtifactStoreStage() override
Definition GeneratedArtifact.cpp:902
In-memory owner and publisher for generated artifacts.
Definition GeneratedArtifact.h:229
std::optional< ArtifactType > typeOf(ArtifactId id) const noexcept
Return the kind of a live identity or composite part.
Definition GeneratedArtifact.cpp:1179
std::size_t partCount() const noexcept
Return the number of indexed composite child products.
Definition GeneratedArtifact.cpp:1224
eve::Result< std::unique_ptr< eve::artifact::PreparedPublication > > stagePublish(GeneratedArtifact artifact)
Prepare one store mutation for a larger provider transaction.
Definition GeneratedArtifact.cpp:1121
const ArtifactPart * findPart(ArtifactId id) const noexcept
Look up a composite child part.
Definition GeneratedArtifact.cpp:1168
eve::Result< ArtifactId > publish(GeneratedArtifact artifact)
Validate and atomically publish one artifact and all composite parts.
Definition GeneratedArtifact.cpp:1022
std::vector< ArtifactId > findByBuildKey(const BuildKey &key) const
Find all identities with a matching deterministic build key.
Definition GeneratedArtifact.cpp:1195
const GeneratedArtifact * find(ArtifactId id) const noexcept
Look up a published artifact.
Definition GeneratedArtifact.cpp:1163
eve::Result< void > restoreState(const eve::Value &state)
Restore complete identity/build-key and typed payload state transactionally.
Definition GeneratedArtifact.cpp:1248
eve::Result< eve::Value > snapshotState() const
Export identity, build-key and complete typed dense payload state.
Definition GeneratedArtifact.cpp:1226
eve::Result< std::vector< ArtifactId > > publishBatch(std::vector< GeneratedArtifact > artifacts)
Validate and atomically publish a dependency-connected batch.
Definition GeneratedArtifact.cpp:1029
eve::Result< void > remove(ArtifactId id)
Remove one artifact; NotFound is returned when absent.
Definition GeneratedArtifact.cpp:1205
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 BuildKey.cpp:27
@ ImageData
@ Collider
@ PointSet
ShapeState * child(const JPH::Body &body, const JPH::SubShapeID &id)
Resolves a native child record for a synchronous callback or query. @ownership Borrowed from the worl...
Definition JoltInternal.h:138
Result< std::vector< float > > decodeColors(const eve::Value::Object &object, std::size_t vertices)
Definition GeneratedArtifactMeshCodec.cpp:60
eve::Value encodeMesh(const MeshBuild &mesh)
Definition GeneratedArtifactMeshCodec.cpp:42
bool validMesh(const MeshBuild &mesh) noexcept
Definition GeneratedArtifactMeshCodec.cpp:26
Definition EvpackPointGraphLoader.h:12
ArtifactType artifactType(const GeneratedArtifact::Payload &payload) noexcept
Return the variant kind for a payload.
Definition GeneratedArtifact.cpp:959
const char * artifactTypeName(ArtifactType type) noexcept
Return the stable textual spelling of an artifact kind.
Definition GeneratedArtifact.cpp:973
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:1002
MeshBuild MeshData
Existing dense CPU mesh type under the artifact vocabulary.
Definition GeneratedArtifact.h:144
ArtifactType
Runtime payload kind; it is checked against the variant on publish.
Definition GeneratedArtifact.h:111
@ 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:147
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:985
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
Definition Widget.cpp:878
@ 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
Result< bool > readBoolValue(const Value &value)
Read a Bool without coercing integers, strings or other kinds.
Definition Value.cpp:50
Result< int > readIntValue(const Value &value)
Read an Int64 value as a range-checked native int without numeric coercion.
Definition Value.cpp:41
Result< std::string > readStringMember(const Value::Object &object, std::string_view name)
Read a required string field, including an empty string, as an owning value.
Definition Value.cpp:25
Result< std::string > readNonEmptyStringMember(const Value::Object &object, std::string_view name)
Read a required nonempty string field as an independent owning value.
Definition Value.cpp:33
Result< std::int64_t > readInt64Value(const Value &value)
Read an Int64 without narrowing or numeric coercion.
Definition Value.cpp:57
Definition Container.h:602
One typed, role-named child product inside a composite artifact.
Definition GeneratedArtifact.h:150
Axis-aligned bounds in the artifact's declared world coordinate space.
Definition GeneratedArtifact.h:95
void include(float x, float y, float z) noexcept
Expand this box to include one point.
Definition GeneratedArtifact.cpp:922
std::vector< std::uint32_t > indices
Definition GeneratedArtifact.h:135
bool isValid() const noexcept
Return whether the collider has complete triangle data.
Definition GeneratedArtifact.cpp:945
A coherent set of products published from one deterministic build.
Definition GeneratedArtifact.h:163
const ArtifactPart * find(std::string_view role) const noexcept
Find a child by its stable role.
Definition GeneratedArtifact.cpp:953
Complete immutable-once-published artifact record.
Definition GeneratedArtifact.h:183
std::variant< Grid2D, PointSet, MeshData, ImageData, Collider, CompositeArtifact > Payload
Definition GeneratedArtifact.h:191
bool isValid() const noexcept
Return whether dimensions and pixel storage describe an image.
Definition GeneratedArtifact.cpp:938