feat: add weather-local render cadence

This commit is contained in:
OpenAI Codex
2026-09-07 14:55:32 +08:00
parent 6d514e3aae
commit b9b3dd2253
13 changed files with 224 additions and 8 deletions

View File

@@ -89,6 +89,17 @@ bool RasterArrayTimelineRuntime::moveToLocked(const size_t nextT0) {
RasterArrayTimelineFrame RasterArrayTimelineRuntime::tick() {
std::lock_guard<std::mutex> lock(mutex);
const auto now = std::chrono::steady_clock::now();
if (targetFps_ != RasterArrayTargetFps::Auto && lastCadenceTick.time_since_epoch().count() != 0) {
const auto interval = std::chrono::duration<double>(1.0 / static_cast<uint8_t>(targetFps_));
if (now - lastCadenceTick < interval) return frameLocked();
}
lastCadenceTick = now;
++cadenceTickCount;
if (lastCadenceLog.time_since_epoch().count() == 0 || now - lastCadenceLog >= std::chrono::seconds(1)) {
lastCadenceLog = now;
Log::Info(Event::Render, "WeatherCadence: targetFps=" + std::to_string(static_cast<uint8_t>(targetFps_)) +
" weatherTicks=" + std::to_string(cadenceTickCount));
}
if (lastTick == std::chrono::steady_clock::time_point{}) {
lastTick = now;
return frameLocked();
@@ -124,6 +135,30 @@ RasterArrayTimelineFrame RasterArrayTimelineRuntime::tick() {
return frameLocked();
}
bool RasterArrayTimelineRuntime::setTargetFps(const RasterArrayTargetFps target) {
std::lock_guard<std::mutex> lock(mutex);
targetFps_ = target;
lastCadenceTick = {};
return true;
}
RasterArrayTargetFps RasterArrayTimelineRuntime::targetFps() const {
std::lock_guard<std::mutex> lock(mutex);
return targetFps_;
}
bool RasterArrayTimelineRuntime::cadenceDue(const std::chrono::steady_clock::time_point now) const {
std::lock_guard<std::mutex> lock(mutex);
if (targetFps_ == RasterArrayTargetFps::Auto || lastCadenceTick.time_since_epoch().count() == 0) return true;
const auto interval = std::chrono::duration<double>(1.0 / static_cast<uint8_t>(targetFps_));
return now - lastCadenceTick >= interval;
}
void RasterArrayTimelineRuntime::markCadenceTick(const std::chrono::steady_clock::time_point now) {
std::lock_guard<std::mutex> lock(mutex);
lastCadenceTick = now;
}
bool RasterArrayTimelineRuntime::play() {
std::lock_guard<std::mutex> lock(mutex);
if (state == RasterArrayPlaybackState::Waiting) {
@@ -509,6 +544,7 @@ void RasterArraySource::tryInitializeTimeline() {
return;
}
timeline = std::make_shared<RasterArrayTimelineRuntime>(std::move(entries));
timeline->setTargetFps(targetFps);
auto updated = makeMutable<Impl>(impl());
updated->timeline = timeline;
baseImpl = std::move(updated);
@@ -537,6 +573,7 @@ void RasterArraySource::tryInitializeTimeline() {
}
try {
timeline = std::make_shared<RasterArrayTimelineRuntime>(std::move(entries));
timeline->setTargetFps(targetFps);
auto updated = makeMutable<Impl>(impl());
updated->timeline = timeline;
baseImpl = std::move(updated);
@@ -754,6 +791,7 @@ RasterArrayHostFieldSubmitResult RasterArraySource::submitHostField(const std::s
entries.push_back({std::make_shared<const particle::ParticleFieldSnapshot>(initialT0), initialT0.validTime});
entries.push_back({std::make_shared<const particle::ParticleFieldSnapshot>(initialT1), initialT1.validTime});
timeline = std::make_shared<RasterArrayTimelineRuntime>(std::move(entries));
timeline->setTargetFps(targetFps);
auto updated = makeMutable<Impl>(impl());
updated->timeline = timeline;
baseImpl = std::move(updated);
@@ -849,6 +887,24 @@ bool RasterArraySource::controlRuntimeTimeline(const int command, const float va
}
}
bool RasterArraySource::setRuntimeTargetFps(const uint8_t requested) {
RasterArrayTargetFps next;
switch (requested) {
case 0: next = RasterArrayTargetFps::Auto; break;
case 30: next = RasterArrayTargetFps::Fps30; break;
case 60: next = RasterArrayTargetFps::Fps60; break;
default: return false;
}
targetFps = next;
if (timeline) timeline->setTargetFps(next);
observer->onSourceChanged(*this);
return true;
}
uint8_t RasterArraySource::runtimeTargetFps() const {
return static_cast<uint8_t>(targetFps);
}
bool RasterArraySource::supportsLayerType(const LayerTypeInfo* info) const {
if (!info) return false;
const std::string type{info->type};