载入中...
搜索中...
未找到
ParticleEventJournal.cpp
浏览该文件的文档.
2#include <cmath>
3#include <new>
4namespace eve::particles {
5Result<void> ParticleEventJournal::prepare(std::size_t maximumEvents) {
6 if (!maximumEvents || maximumEvents > 2000000)
8 "invalid particle recording event budget", "particleJournal"));
9 try {
10 std::vector<ParticleRecordEvent> candidate;
11 candidate.reserve(maximumEvents);
12 events_.swap(candidate);
13 limit_ = maximumEvents;
15 return Result<void>::success();
16 } catch (const std::bad_alloc&) {
18 Diagnostic::error(DiagnosticCode::Failed, "particle recording allocation failed", "particleJournal"));
19 }
20}
25 "particle recording already failed", "particleJournal"));
26 bool valid = std::isfinite(event.seconds) && event.seconds >= 0 && event.birthSerial != 0 &&
27 (events_.empty() || event.seconds >= events_.back().seconds) &&
29 const auto& p = event.appearance;
30 for (float value :
31 {p.x, p.y, p.w, p.h, p.rotation, p.color.r, p.color.g, p.color.b, p.color.a, p.u0, p.v0, p.u1, p.v1})
32 valid = valid && std::isfinite(value);
33 if (!valid) {
36 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid particle recording event", "particleJournal"));
37 }
38 if (events_.size() == limit_) {
41 Diagnostic::error(DiagnosticCode::Failed, "particle recording event budget exhausted", "particleJournal"));
42 }
43 events_.push_back(event);
44 return Result<void>::success();
45}
49 DiagnosticCode::PreconditionViolation, "particle recording is not completeable", "particleJournal"));
50 auto result = std::move(events_);
51 events_.clear();
52 limit_ = 0;
54 return Result<std::vector<ParticleRecordEvent>>::success(std::move(result));
55}
62ParticleRecordState ParticleEventJournal::state() const noexcept { return state_; }
63std::span<const ParticleRecordEvent> ParticleEventJournal::events() const noexcept { return events_; }
64} // namespace eve::particles
glm::vec4 p[6]
Poco::JSON::Object::Ptr result
bool valid
Object::Ptr value
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
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
void invalidate() noexcept
Mark active recording invalid after a producer failure; disabled journals remain disabled.
ParticleRecordState state() const noexcept
Current lifecycle and failure state.
std::span< const ParticleRecordEvent > events() const noexcept
Borrow recorded events; valid until prepare, append or journal destruction. @ownership Borrowed view ...
void disable() noexcept
Disable valid recording, preserving sticky failures and owned events for inspection.
Result< void > append(ParticleRecordEvent event)
Append an owning event at a nondecreasing explicit time; never allocates or calls user code.
Result< std::vector< ParticleRecordEvent > > finish()
Finish valid recording and transfer all owning events, disabling further appends. @cost Constant-time...
Result< void > prepare(std::size_t maximumEvents)
Start a new empty journal with a bounded event budget, replacing prior contents only on success....
ParticleRecordState
Journal lifecycle; failures are sticky until an explicit new recording is prepared.
Owning presentation event without simulation or resource references.