feat: add Android host weather runtime facade

This commit is contained in:
OpenAI Codex
2026-09-07 10:43:11 +08:00
parent faf7548220
commit a81b464d9b
26 changed files with 614 additions and 46 deletions

View File

@@ -10,6 +10,7 @@
#include <mbgl/util/logging.hpp>
#include <atomic>
#include <algorithm>
#include <cmath>
namespace mbgl::style {
@@ -182,6 +183,34 @@ bool RasterArrayTimelineRuntime::seek(const size_t index) {
std::to_string(t0) + " t1Index=" + std::to_string(t0 + 1) + " mix=" + std::to_string(mix));
return true;
}
bool RasterArrayTimelineRuntime::seekTimestamp(const uint64_t timestamp) {
std::lock_guard<std::mutex> lock(mutex);
if (gap || invalid || entries.size() < 2 || timestamp < entries.front().timestamp || timestamp > entries.back().timestamp) return false;
const auto previousT0 = t0;
const auto previousState = state;
const auto upper = std::upper_bound(entries.begin(), entries.end(), timestamp, [](uint64_t value, const Entry& entry) {
return value < entry.timestamp;
});
if (upper == entries.begin()) return false;
if (upper == entries.end()) {
t0 = entries.size() - 2;
mix = 1.0f;
state = RasterArrayPlaybackState::Ended;
} else {
t0 = static_cast<size_t>(std::distance(entries.begin(), upper) - 1);
const auto duration = static_cast<float>(entries[t0 + 1].timestamp - entries[t0].timestamp);
mix = duration > 0.0f ? static_cast<float>(timestamp - entries[t0].timestamp) / duration : 0.0f;
state = previousState == RasterArrayPlaybackState::Playing ? RasterArrayPlaybackState::Playing
: RasterArrayPlaybackState::Paused;
}
if (t0 != previousT0) ++windowRevision;
lastTick = std::chrono::steady_clock::now();
Log::Info(Event::Render, "ParticleTimeline: event=PLAYBACK_SEEK_TIMESTAMP timestamp=" + std::to_string(timestamp) +
" t0Index=" + std::to_string(t0) + " t1Index=" + std::to_string(t0 + 1) +
" mix=" + std::to_string(mix));
return true;
}
bool RasterArrayTimelineRuntime::step(const int direction) {
std::lock_guard<std::mutex> lock(mutex);
const auto target = direction < 0 ? (t0 == 0 ? 0 : t0 - 1) : std::min(t0 + 1, entries.size() - 2);
@@ -756,6 +785,41 @@ RasterArrayHostFieldSubmitResult RasterArraySource::submitHostField(const std::s
return RasterArrayHostFieldSubmitResult::AcceptedNextSnapshot;
}
bool RasterArraySource::clearHostFields() {
if (!impl().hostFieldSubmission) {
Log::Warning(Event::Render, "WeatherRuntime: event=FIELD_WINDOW_CLEAR_REJECTED reason=SOURCE_MODE sourceId=" + getID());
return false;
}
if (timeline) timeline->pause();
Log::Info(Event::Render, "WeatherRuntime: event=TIMELINE_STOP sourceId=" + getID());
pendingHostField.reset();
timeline.reset();
auto updated = makeMutable<Impl>(impl());
updated->timeline.reset();
updated->field.reset();
updated->nextField.reset();
baseImpl = std::move(updated);
loaded = true; // An empty Host ingress is loaded; it has no drawable field.
runtimeUpdateSequence = 0;
observer->onSourceChanged(*this);
Log::Info(Event::Render, "WeatherRuntime: event=FIELD_WINDOW_CLEAR sourceId=" + getID());
Log::Info(Event::Render, "WeatherRuntime: event=SNAPSHOT_CLEAR sourceId=" + getID());
return true;
}
bool RasterArraySource::seekRuntimeTimelineToTimestamp(const uint64_t timestamp) {
if (!timeline) {
Log::Warning(Event::Render, "WeatherRuntime: event=SEEK_TIMESTAMP_REJECTED reason=TIMELINE_NOT_READY sourceId=" + getID());
return false;
}
const bool accepted = timeline->seekTimestamp(timestamp);
if (!accepted) {
Log::Warning(Event::Render, "WeatherRuntime: event=SEEK_TIMESTAMP_REJECTED reason=OUT_OF_RANGE sourceId=" + getID() +
" timestamp=" + std::to_string(timestamp));
}
return accepted;
}
bool RasterArraySource::controlRuntimeTimeline(const int command, const float value) {
if (!timeline) {
Log::Warning(Event::Render, "ParticleTimeline: event=REJECTED reason=TIMELINE_NOT_READY sourceId=" + getID());