feat: add runtime particle timeline playback
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
This commit is contained in:
@@ -3,7 +3,11 @@
|
||||
#include <mbgl/particle/field/offline_fixture_particle_adapter.hpp>
|
||||
#include <mbgl/style/source.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mbgl {
|
||||
@@ -17,6 +21,65 @@ struct RasterArrayRuntimeFieldDescriptor {
|
||||
std::string fixtureID;
|
||||
std::string metadataURL;
|
||||
std::string fieldURL;
|
||||
// Validation-only logical time in milliseconds. A production adapter owns
|
||||
// its own timeline metadata; this keeps fixtures deterministic.
|
||||
uint64_t timestamp = 0;
|
||||
};
|
||||
|
||||
enum class RasterArrayPlaybackState : uint8_t {
|
||||
Ready,
|
||||
Playing,
|
||||
Paused,
|
||||
Waiting,
|
||||
Ended
|
||||
};
|
||||
|
||||
struct RasterArrayTimelineFrame {
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> t0;
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> t1;
|
||||
float mix = 0.0f;
|
||||
size_t t0Index = 0;
|
||||
size_t t1Index = 0;
|
||||
uint64_t windowRevision = 0;
|
||||
RasterArrayPlaybackState state = RasterArrayPlaybackState::Ready;
|
||||
};
|
||||
|
||||
// Source-owned playback state. Android only sends low-frequency commands;
|
||||
// render frames obtain an immutable T0/T1 pair and scalar mix from Core.
|
||||
class RasterArrayTimelineRuntime {
|
||||
public:
|
||||
struct Entry {
|
||||
std::shared_ptr<const particle::ParticleFieldSnapshot> field;
|
||||
uint64_t timestamp = 0;
|
||||
};
|
||||
|
||||
explicit RasterArrayTimelineRuntime(std::vector<Entry>);
|
||||
RasterArrayTimelineFrame tick();
|
||||
bool play();
|
||||
bool pause();
|
||||
bool setSpeed(float);
|
||||
bool seek(size_t);
|
||||
bool step(int);
|
||||
bool injectGap();
|
||||
bool injectInvalid();
|
||||
bool recover();
|
||||
RasterArrayTimelineFrame frame() const;
|
||||
size_t cacheCapacity() const { return cacheCapacity_; }
|
||||
|
||||
private:
|
||||
RasterArrayTimelineFrame frameLocked() const;
|
||||
bool moveToLocked(size_t);
|
||||
mutable std::mutex mutex;
|
||||
std::vector<Entry> entries;
|
||||
size_t t0 = 0;
|
||||
float mix = 0.0f;
|
||||
float speed = 1.0f;
|
||||
RasterArrayPlaybackState state = RasterArrayPlaybackState::Ready;
|
||||
bool gap = false;
|
||||
bool invalid = false;
|
||||
uint64_t windowRevision = 1;
|
||||
std::chrono::steady_clock::time_point lastTick{};
|
||||
const size_t cacheCapacity_ = 8;
|
||||
};
|
||||
|
||||
enum class RasterArrayRuntimeFieldUpdateResult : uint8_t {
|
||||
@@ -55,6 +118,8 @@ public:
|
||||
// Validation convenience: resubmit the current T1 through the formal
|
||||
// update API. This must return Noop without changing the Source window.
|
||||
RasterArrayRuntimeFieldUpdateResult repeatRuntimeFieldWindow();
|
||||
// Low-frequency JNI commands for the Source-owned validation timeline.
|
||||
bool controlRuntimeTimeline(int command, float value = 0.0f);
|
||||
bool supportsLayerType(const LayerTypeInfo*) const override;
|
||||
mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
@@ -73,6 +138,7 @@ private:
|
||||
|
||||
void tryLoad();
|
||||
void tryLoadRuntimeField(size_t);
|
||||
void tryInitializeTimeline();
|
||||
RasterArrayRuntimeFieldUpdateResult rejectRuntimeFieldUpdate(RasterArrayRuntimeFieldUpdateResult,
|
||||
const std::string& reason) const;
|
||||
|
||||
@@ -87,6 +153,7 @@ private:
|
||||
std::vector<RuntimeFieldCandidate> runtimeFields;
|
||||
size_t nextRuntimeField = 0;
|
||||
uint64_t runtimeUpdateSequence = 0;
|
||||
std::shared_ptr<RasterArrayTimelineRuntime> timeline;
|
||||
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user