fix: reseed particles after zoom out
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled

This commit is contained in:
tei
2026-09-23 10:05:01 +09:00
parent 297b912620
commit 4286c16a53
4 changed files with 179 additions and 3 deletions

View File

@@ -12,6 +12,7 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/particle/field/offline_fixture_particle_adapter.hpp>
#include <mbgl/particle/renderer_debug_counters.hpp>
#include <mbgl/renderer/particle_viewport_reseed.hpp>
#include <mbgl/renderer/buckets/heatmap_bucket.hpp>
#include <mbgl/renderer/change_request.hpp>
#include <mbgl/renderer/layer_group.hpp>
@@ -339,6 +340,7 @@ public:
bool trailCameraInvalidated = false;
bool viewportDensityActive = false;
bool viewportDensityLogged = false;
ParticleViewportReseedGesture viewportReseedGesture;
uint64_t lastCameraLogFrame = 0;
std::chrono::steady_clock::time_point lastPlaybackHeartbeat{};
std::chrono::steady_clock::time_point lastSimulationTick{};
@@ -419,6 +421,7 @@ public:
pending = false;
bootstrapPending = false;
staticFreezeLogged = false;
viewportReseedGesture.cancel();
lastSimulationTick = {};
for (const auto& target : stateTargets) {
if (target && target->getLayerGroup(0)) {
@@ -1676,7 +1679,11 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
std::abs(resources->trailCameraZoom - transformState.getZoom()) > 0.0001 ||
std::abs(resources->trailCameraBearing - transformState.getBearing()) > 0.0001 ||
std::abs(resources->trailCameraPitch - transformState.getPitch()) > 0.0001);
bool cameraBecameStable = false;
if (viewportChanged) {
if (transformChanged) {
resources->viewportReseedGesture.begin(resources->trailCameraZoom);
}
const auto previousSize = resources->trailSize;
resources->trailTargets = {};
resources->trailSize = {};
@@ -1690,6 +1697,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
std::to_string(previousSize.height) + " new=" + std::to_string(viewport.width) + "x" +
std::to_string(viewport.height) + " statePreserved=true fieldResubmit=false timelineReset=false");
} else if (transformChanged) {
resources->viewportReseedGesture.begin(resources->trailCameraZoom);
if (!resources->trailCameraInvalidated) {
const auto reason = std::abs(resources->trailCameraZoom - transformState.getZoom()) > 0.0001 ? "zoom"
: std::abs(resources->trailCameraBearing - transformState.getBearing()) > 0.0001
@@ -1707,9 +1715,7 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
} else if (resources->trailCameraInvalidated &&
cameraNow - resources->lastTrailCameraChange >= TrailCameraStableDelay) {
resources->trailCameraInvalidated = false;
Log::Info(
Event::Render,
"ParticleTrail: event=CAMERA_STABLE_RESUME statePreserved=true fieldResubmit=false timelineReset=false");
cameraBecameStable = true;
}
resources->trailCameraKnown = true;
resources->trailCameraLatitude = trailCamera.latitude();
@@ -1724,6 +1730,35 @@ void RenderRasterParticleLayer::update(gfx::ShaderRegistry& shaders,
// lifecycle respawns stay in the full Field. The viewport domain is only
// enabled after the existing stable-camera debounce has completed.
resources->respawnBounds = resources->viewportDensityActive ? respawnDomain.bounds : fieldBounds(resources->field);
if (cameraBecameStable) {
const auto reseedDecision = resources->viewportReseedGesture.finish(transformState.getZoom(),
resources->viewportDensityActive);
if (reseedDecision.action == ParticleViewportReseedAction::Reseed) {
resources->stateSeeded = false;
resources->trailSeeded = false;
const auto& bounds = resources->respawnBounds;
Log::Info(Event::Render,
"ParticleDensity: event=VIEWPORT_RESEED reason=ZOOM_OUT startZoom=" +
std::to_string(reseedDecision.startZoom) + " endZoom=" +
std::to_string(reseedDecision.endZoom) + " respawnBounds=[" +
std::to_string(bounds[0]) + "," + std::to_string(bounds[1]) + "," +
std::to_string(bounds[2]) + "," + std::to_string(bounds[3]) +
"] stateReseed=true trailReseed=true fieldResubmit=false timelineReset=false "
"gpuResourceRebuild=false");
} else if (reseedDecision.action == ParticleViewportReseedAction::SkipInvalidDomain) {
Log::Info(Event::Render,
"ParticleDensity: event=VIEWPORT_RESEED reason=ZOOM_OUT action=SKIP "
"skipReason=INVALID_RESPAWN_DOMAIN startZoom=" +
std::to_string(reseedDecision.startZoom) + " endZoom=" +
std::to_string(reseedDecision.endZoom) +
" stateReseed=false trailReseed=false fieldResubmit=false timelineReset=false "
"gpuResourceRebuild=false");
}
Log::Info(Event::Render,
"ParticleTrail: event=CAMERA_STABLE_RESUME statePreserved=" +
std::string(reseedDecision.action == ParticleViewportReseedAction::Reseed ? "false" : "true") +
" fieldResubmit=false timelineReset=false");
}
if (resources->formalDisplay && !resources->trailCameraInvalidated && !resources->viewportDensityLogged) {
const auto& bounds = resources->respawnBounds;
const auto& currentFieldBounds = fieldBounds(resources->field);