载入中...
搜索中...
未找到
PixelWorldStreaming.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <limits>
5#include <vector>
6
8namespace {
9
10using Coord = std::pair<int, int>;
11
12Coord coord(const eve::pixelworld::PixelChunkSnapshot& chunk) { return {chunk.y, chunk.x}; }
13
14bool contains(eve::pixelworld::PixelChunkRegion region, Coord value) noexcept {
15 const auto [y, x] = value;
16 return x >= region.minX && x <= region.maxX && y >= region.minY && y <= region.maxY;
17}
18
19} // namespace
20
23 auto all = source.snapshotChunksInRegion(interest, 0);
24 if (!all) return eve::Result<PixelChunkStreamUpdate>::failure(all.status());
25
26 const auto link = source.worldLink();
27 const bool fullResync = source_.world == 0 || source_ != link;
28 std::set<Coord> nextKnown;
29 std::set<Coord> emitted;
30 std::vector<eve::pixelworld::PixelChunkSnapshot> output;
31 output.reserve(all.value().size() + known_.size());
33 update.fullResync = fullResync;
34
35 for (const auto& chunk : all.value()) {
36 const Coord key = coord(chunk);
37 if (chunk.removed) {
38 if (fullResync || known_.contains(key)) {
39 output.push_back(chunk);
40 emitted.insert(key);
41 }
42 continue;
43 }
44 nextKnown.insert(key);
45 if (fullResync || !known_.contains(key) || chunk.revision > revision_) {
46 output.push_back(chunk);
47 emitted.insert(key);
48 if (!known_.contains(key)) ++update.chunksEntered;
49 }
50 }
51
52 for (const Coord& key : known_) {
53 if (nextKnown.contains(key) || emitted.contains(key)) continue;
54 ++update.chunksEvicted;
55 if (fullResync || contains(interest, key)) continue;
56 const auto [y, x] = key;
57 output.push_back({x, y, source.revision(), true, {}});
58 }
59 std::sort(output.begin(), output.end(), [](const auto& left, const auto& right) {
60 return coord(left) < coord(right);
61 });
62
63 update.batch.catalogFingerprint = source.materialCatalogFingerprint();
64 update.batch.sourceSeed = source.seed();
65 update.batch.sourceRevision = source.revision();
66 update.batch.sourceTick = eve::SimulationTick(source.tickValue());
67 update.batch.sourceLastEditSequence = source.lastEditSequence();
68 update.batch.fullResync = fullResync;
69 update.batch.chunks = std::move(output);
70
71 source_ = link;
72 revision_ = source.revision();
73 known_ = std::move(nextKnown);
74 return eve::Result<PixelChunkStreamUpdate>::success(std::move(update));
75}
76
78 source_ = {};
79 revision_ = 0;
80 known_.clear();
81}
82
83} // namespace eve::pixelworld_streaming
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::string output
std::uint32_t key
HexVec3 left
HexVec3 right
const UnitySourceAsset & source
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
Sparse, chunked, deterministic 2D falling-material world.
Definition PixelWorld.h:224
eve::Result< PixelChunkStreamUpdate > capture(const eve::pixelworld::PixelWorld &source, eve::pixelworld::PixelChunkRegion interest)
Capture changed/entered Chunks and eviction tombstones for an interest region.
void reset() noexcept
Forget consumer projection state so the next capture is a full resync.
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31
bool fullResync
Replace the replica projection instead of applying an incremental correction.
Definition PixelWorld.h:96
std::vector< PixelChunkSnapshot > chunks
Definition PixelWorld.h:97
eve::SimulationTick sourceTick
Definition PixelWorld.h:93
Inclusive finite rectangle expressed in Chunk coordinates.
Definition PixelWorld.h:104
Owning, immutable projection of one authoritative simulation chunk.
Definition PixelWorld.h:77
One interest-stream update suitable for persistence or network transport.
bool fullResync
Mirrors batch.fullResync for capture diagnostics.