载入中...
搜索中...
未找到
ActionTimeline.cpp
浏览该文件的文档.
12const Value* field(const Value& value, std::string_view name) { return value.find(std::string(name)); }
92Result<ActionAnimationSection> decodeAnimationSection(const Value& value, const std::string& path,
128Result<ActionNotify> decodeNotify(const Value& value, const std::string& path, std::int64_t schemaVersion) {
146 return Result<ActionNotify>::success(ActionNotify{std::move(id).takeValue(), std::move(type).takeValue(),
151Result<ActionNotifyState> decodeState(const Value& value, const std::string& path, std::int64_t schemaVersion) {
172 std::move(id).takeValue(), std::move(type).takeValue(), Duration::fromNanoseconds(start.value()),
177 return includePrevious ? value >= previous && value <= current : value > previous && value <= current;
212 {ActionTrackKind::Animation, ActionTrackKind::Gameplay, ActionTrackKind::Effect, ActionTrackKind::Audio,
213 ActionTrackKind::Camera, ActionTrackKind::Movement, ActionTrackKind::Tag, ActionTrackKind::Custom})
216 Diagnostic::error(DiagnosticCode::InvalidArgument, "unknown action track kind", "tracks.kind"));
222 Diagnostic::error(DiagnosticCode::InvalidArgument, "unsupported action timeline schema version", "schemaVersion"));
224 Diagnostic::error(DiagnosticCode::InvalidArgument, "action timeline requires a valid action id", "actionId"));
226 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline duration must be non-negative", "durationNs"));
229 Diagnostic::error(DiagnosticCode::InvalidArgument, "montage base play rate must be positive and finite", "montage.basePlayRate"));
233 Diagnostic::error(DiagnosticCode::InvalidArgument, "montage blend durations must be non-negative", "montage"));
238 Diagnostic::error(DiagnosticCode::InvalidArgument, "physical section splits must be strictly ordered inside the timeline", "splitTimestampsNs[" + std::to_string(index) + "]"));
246 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section id is invalid", path + ".id"));
248 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", path + ".id"));
250 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section requires a URI", path + ".animationUri"));
253 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section range is invalid", path));
257 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section blend-in is outside its range", path + ".blendInNs"));
261 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation section source trim is invalid", path + ".sourceStartNs"));
266 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation sections must be sorted by start time", path + ".startNs"));
268 Diagnostic::error(DiagnosticCode::InvalidArgument, "animation sections must not overlap", path + ".startNs"));
277 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", path + ".id"));
285 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", itemPath + ".id"));
288 Diagnostic::error(DiagnosticCode::InvalidArgument, "notify time is outside the timeline", itemPath + ".timeNs"));
291 Diagnostic::error(DiagnosticCode::InvalidArgument, "notifies must be sorted by time", itemPath + ".timeNs"));
300 Diagnostic::error(DiagnosticCode::InvalidArgument, "timeline item ids must be unique", itemPath + ".id"));
306 Diagnostic::error(DiagnosticCode::InvalidArgument, "notify states must be sorted by start time", itemPath + ".startNs"));
312Result<std::vector<ActionTimelineEvent>> ActionTimeline::sample(Duration previous, Duration current,
318 Diagnostic::error(DiagnosticCode::InvalidArgument, "sample range is outside the timeline", "sample"));
327 {ActionTimelineEventKind::Notify, track.id, notify.id, notify.type, notify.time, notify.payload});
333 {ActionTimelineEventKind::StateEnter, track.id, state.id, state.type, state.start, state.payload});
336 {ActionTimelineEventKind::StateExit, track.id, state.id, state.type, state.end, state.payload});
353 Diagnostic::error(DiagnosticCode::InvalidArgument, "active-block sample is outside the timeline", "time"));
383 for (const auto& section : animationSections) encodedSections.push_back(encodeAnimationSection(section));
407 root["animationUri"] = animationSections.empty() ? animationUri : animationSections.front().animationUri;
428 Diagnostic::error(DiagnosticCode::InvalidArgument, "expected action timeline object", "timeline"));
433 Diagnostic::error(DiagnosticCode::InvalidArgument, "unexpected action timeline schema", "schema"));
452 if (version.value() < 1 || version.value() > static_cast<std::int64_t>(kActionTimelineSchemaVersion))
454 DiagnosticCode::InvalidArgument, "unsupported action timeline schema version", "schemaVersion"));
473 auto decoded = decodeAnimationSection(sections[index], "animationSections[" + std::to_string(index) + "]",
496 Diagnostic::error(DiagnosticCode::InvalidArgument, "expected montage settings object", "montage"));
504 auto rootHorizontal = boolField(*montageValue, "rootMotionHorizontal", "montage.rootMotionHorizontal");
505 auto rootVertical = boolField(*montageValue, "rootMotionVertical", "montage.rootMotionVertical");
506 auto rootRotation = boolField(*montageValue, "rootMotionRotation", "montage.rootMotionRotation");
507 if (!basePlayRate || (!basePlayRate->isDouble() && !basePlayRate->isInt64()) || !looping || !footIk ||
513 basePlayRate->isDouble() ? basePlayRate->asDouble() : static_cast<double>(basePlayRate->asInt());
548 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={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
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:48
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
bool isValid() const noexcept
Returns whether this value contains a valid namespace and name.
Definition Identity.h:433
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
double asDouble() const
Return the Double payload; the caller must have checked the kind.
Definition Value.cpp:75
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:69
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
Definition AbilityAsset.cpp:9
std::string_view actionTrackKindName(ActionTrackKind kind) noexcept
Stable lowercase protocol spelling for a track kind.
Definition ActionTimeline.cpp:196
std::optional< ActionBlendCurve > actionBlendCurveFromName(std::string_view name) noexcept
Parse a persisted montage cross-fade curve name.
Definition ActionTimeline.cpp:190
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:210
std::string_view actionBlendCurveName(ActionBlendCurve curve) noexcept
Stable persisted name for a montage cross-fade curve.
Definition ActionTimeline.cpp:182
@ StateEnter
ActionTrackKind
Semantic lane kind; hosts choose presentation without changing data.
Definition ActionTimeline.h:82
@ Movement
@ Gameplay
@ Animation
ActionBlendCurve
Built-in deterministic cross-fade curve evaluated without asset callbacks.
Definition ActionTimeline.h:30
@ EaseInOut
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
@ InvalidArgument
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Definition SchemaVersion.h:13
bool rootMotionRotation
Definition ActionTimeline.h:46
bool rootMotionVertical
Definition ActionTimeline.h:45
Duration blendOutOffset
Definition ActionTimeline.h:43
std::uint32_t animationLayer
Definition ActionTimeline.h:40
Duration defaultBlendIn
Definition ActionTimeline.h:41
bool rootMotionHorizontal
Definition ActionTimeline.h:44
Duration defaultBlendOut
Definition ActionTimeline.h:42
Canonical action timeline asset shared by runtime and editor.
Definition ActionTimeline.h:178
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:312
Result< void > validate() const
Validate ids, ranges, uniqueness and deterministic ordering.
Definition ActionTimeline.cpp:219
std::vector< ActionAnimationSection > animationSections
Definition ActionTimeline.h:184
SchemaVersion schemaVersion
Definition ActionTimeline.h:179
std::string animationUri
Compatibility-only single-clip projection; v2 runtime uses animationSections.
Definition ActionTimeline.h:183
std::vector< Duration > splitTimestamps
Sorted objective split timestamps forming N+1 physical sections.
Definition ActionTimeline.h:187
Ordered semantic lane in one action timeline.
Definition ActionTimeline.h:124
std::vector< ActionNotifyState > states
Definition ActionTimeline.h:131
std::vector< ActionNotify > notifies
Definition ActionTimeline.h:130