载入中...
搜索中...
未找到
ActionTimeline.cpp
浏览该文件的文档.
18const Value* field(const Value& value, std::string_view name) { return value.find(std::string(name)); }
100Result<ActionAnimationSection> decodeAnimationSection(const Value& value, const std::string& path,
144 return invalid<ActionAnimationSection>("unknown animation blend-in curve", path + ".blendInCurve");
146 return invalid<ActionAnimationSection>("unknown animation blend-out curve", path + ".blendOutCurve");
155Result<ActionNotify> decodeNotify(const Value& value, const std::string& path, std::int64_t schemaVersion) {
173 return Result<ActionNotify>::success(ActionNotify{std::move(id).takeValue(), std::move(type).takeValue(),
178Result<ActionNotifyState> decodeState(const Value& value, const std::string& path, std::int64_t schemaVersion) {
199 std::move(id).takeValue(), std::move(type).takeValue(), Duration::fromNanoseconds(start.value()),
204 return includePrevious ? value >= previous && value <= current : value > previous && value <= current;
257 {ActionTrackKind::Animation, ActionTrackKind::Gameplay, ActionTrackKind::Effect, ActionTrackKind::Audio,
258 ActionTrackKind::Camera, ActionTrackKind::Movement, ActionTrackKind::Tag, ActionTrackKind::Custom})
261 Diagnostic::error(DiagnosticCode::InvalidArgument, "unknown action track kind", "tracks.kind"));
267 Diagnostic::error(DiagnosticCode::InvalidArgument, "unsupported action timeline schema version", "schemaVersion"));
269 Diagnostic::error(DiagnosticCode::InvalidArgument, "action timeline requires a valid action id", "actionId"));
271 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline duration must be non-negative", "durationNs"));
274 Diagnostic::error(DiagnosticCode::InvalidArgument, "montage base play rate must be positive and finite", "montage.basePlayRate"));
278 Diagnostic::error(DiagnosticCode::InvalidArgument, "montage blend durations must be non-negative", "montage"));
283 Diagnostic::error(DiagnosticCode::InvalidArgument, "physical section splits must be strictly ordered inside the timeline", "splitTimestampsNs[" + std::to_string(index) + "]"));
291 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section id is invalid", path + ".id"));
293 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", path + ".id"));
295 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section requires a URI", path + ".animationUri"));
298 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section range is invalid", path));
311 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section source trim is invalid", path + ".sourceStartNs"));
316 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation sections must be sorted by start time", path + ".startNs"));
318 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation sections must not overlap", path + ".startNs"));
327 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", path + ".id"));
335 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", itemPath + ".id"));
338 Diagnostic::error(DiagnosticCode::InvalidArgument, "notify time is outside the timeline", itemPath + ".timeNs"));
341 Diagnostic::error(DiagnosticCode::InvalidArgument, "notifies must be sorted by time", itemPath + ".timeNs"));
350 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", itemPath + ".id"));
356 Diagnostic::error(DiagnosticCode::InvalidArgument, "notify states must be sorted by start time", itemPath + ".startNs"));
362Result<std::vector<ActionTimelineEvent>> ActionTimeline::sample(Duration previous, Duration current,
368 Diagnostic::error(DiagnosticCode::InvalidArgument, "sample range is outside the timeline", "sample"));
377 {ActionTimelineEventKind::Notify, track.id, notify.id, notify.type, notify.time, notify.payload});
383 {ActionTimelineEventKind::StateEnter, track.id, state.id, state.type, state.start, state.payload});
386 {ActionTimelineEventKind::StateExit, track.id, state.id, state.type, state.end, state.payload});
403 Diagnostic::error(DiagnosticCode::InvalidArgument, "active-block sample is outside the timeline", "time"));
433 for (const auto& section : animationSections) encodedSections.push_back(encodeAnimationSection(section));
457 root["animationUri"] = animationSections.empty() ? animationUri : animationSections.front().animationUri;
478 Diagnostic::error(DiagnosticCode::InvalidArgument, "expected action timeline object", "timeline"));
483 Diagnostic::error(DiagnosticCode::InvalidArgument, "unexpected action timeline schema", "schema"));
502 if (version.value() < 1 || version.value() > static_cast<std::int64_t>(kActionTimelineSchemaVersion))
504 DiagnosticCode::InvalidArgument, "unsupported action timeline schema version", "schemaVersion"));
523 auto decoded = decodeAnimationSection(sections[index], "animationSections[" + std::to_string(index) + "]",
546 Diagnostic::error(DiagnosticCode::InvalidArgument, "expected montage settings object", "montage"));
554 auto rootHorizontal = boolField(*montageValue, "rootMotionHorizontal", "montage.rootMotionHorizontal");
555 auto rootVertical = boolField(*montageValue, "rootMotionVertical", "montage.rootMotionVertical");
556 auto rootRotation = boolField(*montageValue, "rootMotionRotation", "montage.rootMotionRotation");
557 if (!basePlayRate || (!basePlayRate->isDouble() && !basePlayRate->isInt64()) || !looping || !footIk ||
563 basePlayRate->isDouble() ? basePlayRate->asDouble() : static_cast<double>(basePlayRate->asInt());
602 Diagnostic::error(DiagnosticCode::InvalidArgument, "expected notifies array", path + ".notifies"));
Versioned, deterministic authoring timeline for gameplay actions.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
constexpr std::int64_t nanoseconds() const noexcept
Return the exact signed nanosecond representation.
Definition Time.h:69
static constexpr Duration fromNanoseconds(std::int64_t nanoseconds) noexcept
Construct an exact duration from nanoseconds.
Definition Time.h:55
static std::optional< LogicalId > fromParts(std::string_view namespaceName, std::string_view name)
Builds a logical ID from separate namespace and name components.
Definition Identity.cpp:49
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:37
bool isValid() const noexcept
Returns whether this value contains a valid namespace and name.
Definition Identity.h:436
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
double asDouble() const
Return the Double payload; the caller must have checked the kind.
Definition Value.cpp:195
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:189
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
Definition AbilityAsset.cpp:13
std::string_view actionTrackKindName(ActionTrackKind kind) noexcept
Stable lowercase protocol spelling for a track kind.
Definition ActionTimeline.cpp:241
std::optional< ActionBlendCurve > actionBlendCurveFromName(std::string_view name) noexcept
Parse a persisted montage cross-fade curve name.
Definition ActionTimeline.cpp:220
constexpr std::uint64_t kActionTimelineSchemaVersion
Current action timeline schema version.
Definition ActionTimeline.h:27
constexpr std::string_view kActionTimelineSchemaId
Canonical schema identifier for persisted action timelines.
Definition ActionTimeline.h:25
Result< ActionTrackKind > parseActionTrackKind(std::string_view text)
Parse a stable track kind spelling.
Definition ActionTimeline.cpp:255
std::string_view actionBlendCurveName(ActionBlendCurve curve) noexcept
Stable persisted name for a montage cross-fade curve.
Definition ActionTimeline.cpp:209
@ StateEnter
ActionTrackKind
Semantic lane kind; hosts choose presentation without changing data.
Definition ActionTimeline.h:96
@ Movement
@ Gameplay
@ Animation
ActionBlendCurve
Built-in deterministic cross-fade curve evaluated without asset callbacks.
Definition ActionTimeline.h:30
@ SmoothStep
@ EaseInOut
double evaluateActionBlendCurve(ActionBlendCurve curve, double normalized) noexcept
Evaluate a deterministic built-in blend curve for a normalized input.
Definition ActionTimeline.cpp:229
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
Status invalid(const char *message)
Definition OceanBindingInternal.h:21
@ InvalidArgument
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Definition SchemaVersion.h:13
bool rootMotionRotation
Definition ActionTimeline.h:49
bool rootMotionVertical
Definition ActionTimeline.h:48
Duration blendOutOffset
Definition ActionTimeline.h:46
std::uint32_t animationLayer
Definition ActionTimeline.h:43
Duration defaultBlendIn
Definition ActionTimeline.h:44
bool rootMotionHorizontal
Definition ActionTimeline.h:47
Duration defaultBlendOut
Definition ActionTimeline.h:45
Canonical action timeline asset shared by runtime and editor.
Definition ActionTimeline.h:192
Result< std::vector< ActionTimelineEvent > > sample(Duration previous, Duration current, bool includePrevious=false) const
Sample all boundaries in (previous,current] in stable order.
Definition ActionTimeline.cpp:362
Result< void > validate() const
Validate ids, ranges, uniqueness and deterministic ordering.
Definition ActionTimeline.cpp:264
std::vector< ActionAnimationSection > animationSections
Definition ActionTimeline.h:198
SchemaVersion schemaVersion
Definition ActionTimeline.h:193
std::string animationUri
Compatibility-only single-clip projection; v2 runtime uses animationSections.
Definition ActionTimeline.h:197
std::vector< Duration > splitTimestamps
Sorted objective split timestamps forming N+1 physical sections.
Definition ActionTimeline.h:206
Ordered semantic lane in one action timeline.
Definition ActionTimeline.h:138
std::vector< ActionNotifyState > states
Definition ActionTimeline.h:145
std::vector< ActionNotify > notifies
Definition ActionTimeline.h:144