载入中...
搜索中...
未找到
PcgTerrainStreaming.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4
5#include <cmath>
6
7namespace eve::procgen {
8
10 if (authority_) cap::removeListener<IPhotoModeFieldSink>(this);
11}
12
14 if (!std::isfinite(worldUnitsPerSample) || worldUnitsPerSample <= 0.f) {
16 "world units per sample must be positive and finite", {}, {}, "procgen.pcgTerrainStreaming"));
17 }
18 cache_ = cache;
19 state_.worldUnitsPerSample = worldUnitsPerSample;
20 return Result<void>::success();
21}
22
24 if (enabled == authority_) return;
25 if (enabled) cap::addListener<IPhotoModeFieldSink>(this);
26 else cap::removeListener<IPhotoModeFieldSink>(this);
27 authority_ = enabled;
28}
29
35
37 const auto* value = std::get_if<float>(&assignment.value);
38 if (!value || !std::isfinite(*value) || *value < 0.f || *value > 5000.f) {
40 "streaming range must be finite in [0,5000]", assignment.field, {},
41 "procgen.pcgTerrainStreaming"));
42 }
43 auto next = state_;
44 if (assignment.field == "m_pcgLoadRange") next.regularRange = *value;
45 else if (assignment.field == "m_pcgImpostorRange") next.impostorRange = *value;
46 else {
48 "unsupported streaming photo-mode field", assignment.field, {}, "procgen.pcgTerrainStreaming"));
49 }
50 state_ = next;
51 return Result<void>::success();
52}
53
54int PcgTerrainStreamingAuthority::rangeToChunks(float range) const noexcept {
55 if (!cache_) return 0;
56 const int chunkSize = cache_->asset().getChunkSize();
57 if (chunkSize <= 0) return 0;
58 return static_cast<int>(std::ceil(range / (state_.worldUnitsPerSample * static_cast<float>(chunkSize))));
59}
60
62 return rangeToChunks(state_.regularRange);
63}
64
66 return rangeToChunks(state_.impostorRange);
67}
68
70 int worldSampleX, int worldSampleY, int maxLoads) {
71 if (!cache_) {
73 "terrain streaming cache is unavailable", {}, {}, "procgen.pcgTerrainStreaming"));
74 }
75 if (maxLoads < 0) {
77 "maximum loads must be non-negative", {}, {}, "procgen.pcgTerrainStreaming"));
78 }
80 cache_->streamAround(worldSampleX, worldSampleY, regularRadiusChunks(), maxLoads));
81}
82
84 if (!std::isfinite(worldDistance) || worldDistance < 0.f) return PcgTerrainStreamingTier::Unloaded;
85 if (worldDistance <= state_.regularRange) return PcgTerrainStreamingTier::Regular;
86 if (worldDistance <= state_.impostorRange) return PcgTerrainStreamingTier::Impostor;
88}
89
90} // namespace eve::procgen
double value
Range range
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
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
PcgTerrainStreamingTier tierForDistance(float worldDistance) const noexcept
Select the runtime representation for a world-space distance.
void setAuthority(bool enabled)
Register or revoke the unique Streaming-domain PhotoMode authority.
int regularRadiusChunks() const noexcept
Return the regular residency radius after conversion to chunks.
int impostorRadiusChunks() const noexcept
Return the impostor visibility radius after conversion to chunks.
Result< void > setTarget(TerrainStreamingCache *cache, float worldUnitsPerSample)
Attach a borrowed cache and define the world size of one terrain sample.
~PcgTerrainStreamingAuthority() override
Pcg terrain streaming authority.
Result< void > applyPhotoModeField(const PhotoModeAssignment &assignment) override
Applies photo mode field.
PhotoModeFieldAcceptance acceptsPhotoModeField(const PhotoModeAssignment &assignment) const noexcept override
Accepts photo mode field.
Result< TerrainStreamStats > streamAround(int worldSampleX, int worldSampleY, int maxLoads=0)
Stream full terrain chunks around a world-space sample coordinate.
Runtime decoded-chunk cache for an EVTR terrain asset.
TerrainStreamStats streamAround(int worldX, int worldY, int radiusChunks, int maxLoads=0, std::string *error=nullptr)
Stream chunks around a world-space sample coordinate.
PcgTerrainStreamingTier
Runtime representation selected by Pcg's regular and impostor ranges.
PhotoModeFieldAcceptance
Capability implemented by the composition root that routes assignments to domain owners.
bool enabled
One reversible field assignment in a photo-mode transaction.