载入中...
搜索中...
未找到
RigidRecording.cpp
浏览该文件的文档.
2#include <new>
3#include <utility>
6namespace eve::physics {
10 std::size_t budget;
11 std::size_t samples = 0;
12 std::vector<RigidTrackFrame> frames;
18};
19namespace {
20Diagnostic allocationFailure() {
21 return Diagnostic::error(DiagnosticCode::Failed, "rigid recording allocation failed", "rigidRecording");
22}
23} // namespace
24RigidRecording::RigidRecording(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {}
26RigidRecording::RigidRecording(RigidRecording&&) noexcept = default;
27RigidRecording& RigidRecording::operator=(RigidRecording&&) noexcept = default;
29 if (sampleBudget == 0 || sampleBudget > 2000000)
31 DiagnosticCode::InvalidArgument, "rigid recording sample budget must be in [1,2000000]", "rigidRecording"));
32 try {
33 auto encoded = recipe.encode();
34 if (!encoded) return Result<RigidRecording>::failure(encoded.status());
35 return Result<RigidRecording>::success(RigidRecording(std::make_unique<Impl>(recipe, sampleBudget)));
36 } catch (const std::bad_alloc&) {
37 return Result<RigidRecording>::failure(allocationFailure());
38 }
39}
41 if (frame.samples.size() > impl_->budget - impl_->samples || impl_->frames.size() >= 2000000)
43 "rigid recording sample budget exceeded", "rigidRecording"));
44 auto timing = impl_->recipe.validateSampleTime(static_cast<std::uint32_t>(impl_->frames.size()), frame.seconds);
45 if (!timing) return timing;
46 const std::span<const RigidTrackSample> roster =
47 impl_->frames.empty() ? std::span<const RigidTrackSample>{} : impl_->frames.front().samples;
48 auto valid = bake_detail::validateRigidFrame(impl_->space, frame, roster,
49 impl_->frames.empty() ? -1 : impl_->frames.back().seconds);
50 if (!valid) return valid;
51 const auto count = frame.samples.size();
52 try {
53 impl_->frames.push_back(std::move(frame));
54 } catch (const std::bad_alloc&) {
55 return Result<void>::failure(allocationFailure());
56 }
57 impl_->samples += count;
58 return Result<void>::success();
59}
61 try {
62 return RigidPoseTrack::prepare(impl_->space, impl_->frames, impl_->recipe);
63 } catch (const std::bad_alloc&) {
64 return Result<RigidPoseTrack>::failure(allocationFailure());
65 }
66}
67RigidTrackSpace RigidRecording::space() const noexcept { return impl_->space; }
68std::size_t RigidRecording::frameCount() const noexcept { return impl_->frames.size(); }
69std::size_t RigidRecording::sampleCount() const noexcept { return impl_->samples; }
70} // namespace eve::physics
void * impl
bool valid
ssq::Object frame
BakeRecipe recipe
Object::Ptr value
int count
int limit
Definition TreeMesh.cpp:166
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Bounded provenance builder for explicit-coordinate baked recordings. @ownership Owns names and conten...
Definition BakeRecipe.h:21
static Result< RigidPoseTrack > prepare(RigidTrackSpace space, std::vector< RigidTrackFrame > frames)
Validate, normalize and freeze a bounded recording with stable sorted track identities....
Bounded owning recorder of stable-identity rigid frames, without simulation dependencies....
RigidTrackSpace space() const noexcept
Coordinate space fixed by the admitted recipe.
Result< void > append(RigidTrackFrame frame)
Validate, identity-sort and normalize an owning candidate at the next recipe sample time....
RigidRecording(RigidRecording &&) noexcept
std::size_t frameCount() const noexcept
Number of accepted frames.
Result< RigidPoseTrack > freeze() const
Freeze an independent immutable track; continued recording cannot mutate it. @cost Linear copy/valida...
static Result< RigidRecording > prepare(const BakeRecipe &recipe, std::size_t sampleBudget)
Prepare from complete provenance and total pose-sample budget in [1,2000000].
std::size_t sampleCount() const noexcept
Number of accepted poses across all frames.
Result< void > validateRigidFrame(RigidTrackSpace space, RigidTrackFrame &frame, std::span< const RigidTrackSample > roster, float previous)
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
RigidTrackSpace
Explicit sample coordinates; planar pixels preserve the producer's XY axes without implicit Y flip.
BakeCoordinates
Explicit source coordinates; planar pixels preserve XY axes without an implicit flip.
Definition BakeRecipe.h:11
Impl(const BakeRecipe &value, std::size_t limit)
std::vector< RigidTrackFrame > frames
Owning frame at an explicit finite simulation time, starting at zero.