Files
MapLibreParticleLab/include/mbgl/style/sources/raster_array_source.hpp
OpenAI Codex 4e31163516
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
test: add runtime field duplicate noop control
2026-09-03 19:02:21 +08:00

100 lines
3.7 KiB
C++

#pragma once
#include <mbgl/particle/field/offline_fixture_particle_adapter.hpp>
#include <mbgl/style/source.hpp>
#include <optional>
#include <vector>
namespace mbgl {
class AsyncRequest;
namespace style {
// A Source-owned, preloaded validation candidate. Production runtimes can use
// updateRuntimeFieldWindow() directly with an already decoded snapshot instead.
struct RasterArrayRuntimeFieldDescriptor {
std::string fixtureID;
std::string metadataURL;
std::string fieldURL;
};
enum class RasterArrayRuntimeFieldUpdateResult : uint8_t {
Applied,
Noop,
RejectedNotLoaded,
RejectedInvalidSnapshot,
RejectedIncompatibleSnapshot,
RejectedNonMonotonicGeneration,
RejectedCandidateNotReady,
RejectedNoCandidate,
};
class RasterArraySource final : public Source {
public:
RasterArraySource(std::string id,
std::string fixtureID,
std::string metadataURL,
std::string fieldURL,
std::string nextFixtureID = {},
std::string nextMetadataURL = {},
std::string nextFieldURL = {},
std::vector<RasterArrayRuntimeFieldDescriptor> runtimeFields = {});
~RasterArraySource() override;
class Impl;
const Impl& impl() const;
void loadDescription(FileSource&) override;
// Advances the authoritative Source time window from T0/T1 to T1/newT1.
// The caller transfers an immutable, already decoded Field snapshot; the
// renderer observes the resulting Source change and owns GPU reuse/upload.
RasterArrayRuntimeFieldUpdateResult updateRuntimeFieldWindow(particle::ParticleFieldSnapshot newT1);
// Validation convenience: advance using the next Source-owned preloaded
// candidate. Android supplies no T0/T1 state and no GPU resource here.
RasterArrayRuntimeFieldUpdateResult advanceRuntimeFieldWindow();
// Validation convenience: resubmit the current T1 through the formal
// update API. This must return Noop without changing the Source window.
RasterArrayRuntimeFieldUpdateResult repeatRuntimeFieldWindow();
bool supportsLayerType(const LayerTypeInfo*) const override;
mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
protected:
Mutable<Source::Impl> createMutable() const noexcept override;
private:
struct RuntimeFieldCandidate {
RasterArrayRuntimeFieldDescriptor descriptor;
std::unique_ptr<AsyncRequest> metadataRequest;
std::unique_ptr<AsyncRequest> fieldRequest;
std::optional<std::string> metadata;
std::optional<std::vector<char>> fieldBytes;
std::optional<particle::ParticleFieldSnapshot> snapshot;
};
void tryLoad();
void tryLoadRuntimeField(size_t);
RasterArrayRuntimeFieldUpdateResult rejectRuntimeFieldUpdate(RasterArrayRuntimeFieldUpdateResult,
const std::string& reason) const;
std::unique_ptr<AsyncRequest> metadataRequest;
std::unique_ptr<AsyncRequest> fieldRequest;
std::unique_ptr<AsyncRequest> nextMetadataRequest;
std::unique_ptr<AsyncRequest> nextFieldRequest;
std::optional<std::string> metadata;
std::optional<std::vector<char>> fieldBytes;
std::optional<std::string> nextMetadata;
std::optional<std::vector<char>> nextFieldBytes;
std::vector<RuntimeFieldCandidate> runtimeFields;
size_t nextRuntimeField = 0;
uint64_t runtimeUpdateSequence = 0;
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
};
template <>
inline bool Source::is<RasterArraySource>() const {
return getType() == SourceType::RasterArray;
}
} // namespace style
} // namespace mbgl