载入中...
搜索中...
未找到
CrowdSnapshot.cpp
浏览该文件的文档.
2
3#include <new>
4
5namespace eve::crowd {
8Crowd::RestorePlan::RestorePlan(RestorePlan&&) noexcept = default;
9Crowd::RestorePlan& Crowd::RestorePlan::operator=(RestorePlan&&) noexcept = default;
10
11Result<Crowd::Snapshot> Crowd::captureSnapshot() const try {
12 if (impl_->budgetActive)
14 Diagnostic::error(DiagnosticCode::Conflict, "Cannot capture during Crowd advancement", "snapshot"));
16 auto state = std::make_shared<Impl>(*impl_);
17 state->workScheduler.reset();
18 state->execution = CrowdExecution::Serial;
19 snapshot.state_ = std::move(state);
20 return Result<Snapshot>::success(std::move(snapshot));
21} catch (const std::bad_alloc&) {
23 Diagnostic::error(DiagnosticCode::Failed, "Cannot allocate Crowd checkpoint", "snapshot"));
24}
25
27 if (!snapshot.state_ || impl_->budgetActive)
29 Diagnostic::error(DiagnosticCode::Conflict, "Invalid snapshot or active Crowd step", "snapshot"));
30 RestorePlan plan;
31 plan.state_ = std::make_unique<Impl>();
32 const auto owner = plan.state_->owner;
33 *plan.state_ = *snapshot.state_;
34 plan.state_->owner = owner;
35 for (auto& lease : plan.state_->flows)
36 if (lease.field_) lease.owner_ = owner;
37 plan.state_->budgetActive = false;
38 plan.state_->spatialIndex.clear();
39 plan.state_->contactPairs.clear();
40 plan.state_->contactDeltas.clear();
41 plan.state_->predictionNeighbors.clear();
42 plan.state_->preferredNeighbors.clear();
43 plan.state_->preferredStarts.clear();
44 plan.state_->preferredCounts.clear();
45 plan.state_->preferredFlows.clear();
46 plan.state_->incidentStarts.clear();
47 plan.state_->incidentPairs.clear();
48 plan.state_->workReport = {};
49 plan.targetOwner_ = impl_->owner;
50 return Result<RestorePlan>::success(std::move(plan));
51} catch (const std::exception& error) {
53}
54
56 if (!plan.state_ || plan.targetOwner_ != impl_->owner || impl_->budgetActive)
58 Diagnostic::error(DiagnosticCode::Conflict, "Empty, foreign or stale Crowd restore plan", "snapshot"));
59 plan.state_->execution = impl_->execution;
60 plan.state_->workScheduler = impl_->workScheduler;
61 impl_.swap(plan.state_);
62 clearNavigationRequests();
63 plan.state_.reset();
64 plan.targetOwner_ = 0;
66}
67} // namespace eve::crowd
Snapshot snapshot
std::shared_ptr< OceanGpuSpectrum > owner
std::string error
Definition Package.cpp:174
PrefabLease lease
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
Prepared restore workspace; owns allocations until commit or destruction.
Definition Crowd.h:391
RestorePlan()
Construct an empty, noncommittable plan.
~RestorePlan()
Release staged state.
Immutable in-process checkpoint; not a persistent or cross-process format.
Definition Crowd.h:386
群体行为模块:连续流场寻路 + 海量单位移动/转向/行动 + Boids 鸟群。
Definition Crowd.h:266
Result< RestorePlan > prepareRestore(const Snapshot &snapshot) const
Allocate complete restored state and fresh handle ownership before publication.
Result< void > commitRestore(RestorePlan &&plan)
Publish a prepared restore without allocation; consumes plan on success.