载入中...
搜索中...
未找到
RTSCrowdSurfaceRuntime.cpp
浏览该文件的文档.
1#include "crowd/Crowd.h"
3
4#include <algorithm>
5#include <cmath>
6#include <limits>
7
8namespace eve::rts {
10 if (settings.surface.isZero() || settings.movement.isZero() || settings.movementRevision == 0 ||
11 settings.costModelRevision == 0 || !std::isfinite(settings.clearanceRadius) || settings.clearanceRadius < 0.f ||
12 settings.maxInflationChecks < 0 || settings.maxInflationChecks > 10000000)
14 DiagnosticCode::InvalidArgument, "Invalid Crowd surface tracking configuration", "crowdSurfaceTracking"));
15 auto staged = std::make_unique<CrowdSurfaceRuntime>();
16 staged->settings = settings;
17 if (crowdSurfaceRuntime_ && crowdSurfaceRuntime_->publication.surface == settings.surface)
18 staged->publication = crowdSurfaceRuntime_->publication;
19 crowdSurfaceRuntime_ = std::move(staged);
20 return Result<void>::success();
21} catch (const std::exception& error) {
22 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Failed, error.what(), "crowdSurfaceTracking"));
23}
24
25void RTS::clearCrowdSurfaceTracking() noexcept { crowdSurfaceRuntime_.reset(); }
26void RTS::invalidateCrowdSurfaceSource() noexcept {
27 if (crowdSurfaceRuntime_) crowdSurfaceRuntime_->source = nullptr;
28}
29
30Result<void> RTS::synchronizeCrowdSurface() try {
31 if (!crowdSurfaceRuntime_) return Result<void>::success(Status::success(StatusCode::NoOp));
32 if (!pathfinder_ || !crowd_)
34 "Surface tracking requires map and Crowd providers",
35 "crowdSurfaceTracking"));
36 auto& runtime = *crowdSurfaceRuntime_;
37 const auto change = pathfinder_->getNavigationChangeStamp();
38 const auto field = crowd_->getFieldStatus();
39 const bool sameGeometry = runtime.geometry.cellSize == navigationGrid_.cellSize &&
40 runtime.geometry.originX == navigationGrid_.originX &&
41 runtime.geometry.originY == navigationGrid_.originY;
42 const bool sameProvider = runtime.source == pathfinder_;
43 const bool samePublication = runtime.captureRevision != 0 && runtime.publication == field.surface;
44 if (sameProvider && sameGeometry && samePublication && runtime.change == change)
46 auto captured = pathfinder_->captureNavigationGrid();
47 if (!captured) return Result<void>::failure(captured.status());
48 if (sameProvider && sameGeometry && samePublication && runtime.captureRevision == captured.value().revision()) {
49 runtime.change = change;
51 }
52 // Rebinding and geometry changes create a new physical surface revision even when cell content is equal.
53 const auto previous =
54 std::max(field.surface.surface == runtime.settings.surface ? field.surface.surfaceRevision : 0,
55 runtime.publication.surface == runtime.settings.surface ? runtime.publication.surfaceRevision : 0);
56 if (previous == std::numeric_limits<std::uint64_t>::max())
58 Diagnostic::error(DiagnosticCode::Conflict, "Tracked surface revision exhausted", "crowdSurfaceTracking"));
59 const crowd::NavigationSurfaceStamp stamp{
60 runtime.settings.surface, runtime.settings.movement, previous + 1,
61 runtime.settings.movementRevision, runtime.settings.costModelRevision, runtime.settings.clearanceRadius};
62 auto projection =
63 projectCrowdSurface(captured.value(), stamp, navigationGrid_, runtime.settings.maxInflationChecks);
64 if (!projection) return Result<void>::failure(projection.status());
65 auto prepared = crowd_->prepareNavigationSurface(projection.value());
66 if (!prepared) return Result<void>::failure(prepared.status());
67 auto committed = crowd_->commitNavigationSurface(std::move(prepared).takeValue());
68 if (!committed) return committed;
69 runtime.source = pathfinder_;
70 runtime.geometry = navigationGrid_;
71 runtime.change = change;
72 runtime.publication = stamp;
73 runtime.captureRevision = captured.value().revision();
74 return Result<void>::success();
75} catch (const std::exception& error) {
76 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Failed, error.what(), "crowdSurfaceTracking"));
77}
78} // namespace eve::rts
bool committed
OceanWakeSettings settings
std::shared_ptr< const OceanSprayFrame > previous
std::string error
Definition Package.cpp:174
Heightmap stamp
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
FieldObservation getFieldStatus() const noexcept
Observe current field readiness and owner-local revision without rebuilding.
Definition Crowd.cpp:62
Result< void > commitNavigationSurface(SurfacePlan &&plan)
Publish terrain and navigation projection together without allocation.
Result< SurfacePlan > prepareNavigationSurface(const NavigationSurfaceSnapshot &snapshot) const
Validate and copy an immutable surface projection without publishing it.
NavigationChangeStamp getNavigationChangeStamp() const noexcept
Read an O(1) invalidation hint without copying/synchronizing the grid. @ownership Borrows the already...
Result< NavigationGridSnapshot > captureNavigationGrid()
Capture canonical grid inputs into immutable owned storage, without mutating the live grid.
Result< void > configureCrowdSurfaceTracking(CrowdSurfaceTracking settings)
Configure automatic map-to-Crowd surface publication before simulation systems run.
void clearCrowdSurfaceTracking() noexcept
Disable tracking and release its derived cache; retains the last published Crowd surface.
Result< crowd::NavigationSurfaceSnapshot > projectCrowdSurface(const map::NavigationGridSnapshot &source, crowd::NavigationSurfaceStamp stamp, const NavigationGrid &geometry, std::int64_t maxChecks)
Upper-domain adapter; owns output and never retains map spans.
Runtime-owned map projection settings; configure once, rebuild only on source changes....
Definition RTS.h:45