[core] Coalesce buckets updates from several tiles

This commit is contained in:
Mikhail Pozdnyakov
2019-09-13 11:21:27 +03:00
parent fc741cdd21
commit 0d9e4afd20
3 changed files with 24 additions and 6 deletions

View File

@@ -367,7 +367,11 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(const UpdatePar
symbolBucketsAdded = symbolBucketsAdded || (result & CrossTileSymbolIndex::AddLayerResult::BucketsAdded);
symbolBucketsChanged = symbolBucketsChanged || (result != CrossTileSymbolIndex::AddLayerResult::NoChanges);
}
renderTreeParameters->placementChanged = !placement->stillRecent(updateParameters.timePoint, updateParameters.transformState.getZoom()) || symbolBucketsAdded;
// We want new symbols to show up faster, however simple setting `placementChanged` to `true` would
// initiate placement too often as new buckets ususally come from several rendered tiles in a row within
// a short period of time. Instead, we squeeze placement update period to coalesce buckets updates from several tiles.
if (symbolBucketsAdded) placement->setMaximumUpdatePeriod(Milliseconds(30));
renderTreeParameters->placementChanged = !placement->stillRecent(updateParameters.timePoint, updateParameters.transformState.getZoom());
std::set<std::string> usedSymbolLayers;
if (renderTreeParameters->placementChanged) {

View File

@@ -964,6 +964,17 @@ float Placement::zoomAdjustment(const float zoom) const {
return std::max(0.0, (placementZoom - zoom) / 1.5);
}
Duration Placement::getUpdatePeriod(const float zoom) const {
// Even if transitionOptions.duration is set to a value < 300ms, we still wait for this default transition duration
// before attempting another placement operation.
const auto fadeDuration = std::max(util::DEFAULT_TRANSITION_DURATION, transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION));
const auto adjustedDuration = std::chrono::duration_cast<Duration>(fadeDuration * (1.0 - zoomAdjustment(zoom)));
if (maximumUpdatePeriod) {
return std::min(*maximumUpdatePeriod, adjustedDuration);
}
return adjustedDuration;
}
bool Placement::hasTransitions(TimePoint now) const {
if (mapMode == MapMode::Continuous && transitionOptions.enablePlacementTransitions) {
return stale || std::chrono::duration<float>(now - fadeStartTime) < transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION);
@@ -973,12 +984,13 @@ bool Placement::hasTransitions(TimePoint now) const {
}
bool Placement::stillRecent(TimePoint now, const float zoom) const {
// Even if transitionOptions.duration is set to a value < 300ms, we still wait for this default transition duration
// before attempting another placement operation.
const auto fadeDuration = std::max(util::DEFAULT_TRANSITION_DURATION, transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION));
return mapMode == MapMode::Continuous &&
transitionOptions.enablePlacementTransitions &&
commitTime + fadeDuration * (1.0 - zoomAdjustment(zoom)) > now;
commitTime + getUpdatePeriod(zoom) > now;
}
void Placement::setMaximumUpdatePeriod(Duration duration) {
maximumUpdatePeriod = duration;
}
void Placement::setStale() {

View File

@@ -110,7 +110,7 @@ public:
const CollisionIndex& getCollisionIndex() const;
bool stillRecent(TimePoint now, const float zoom) const;
void setRecent(TimePoint now);
void setMaximumUpdatePeriod(Duration);
void setStale();
const RetainedQueryData& getQueryData(uint32_t bucketInstanceId) const;
@@ -126,6 +126,7 @@ private:
void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, const SymbolInstance&, style::TextWritingModeType orientation);
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&);
float zoomAdjustment(const float zoom) const;
Duration getUpdatePeriod(const float zoom) const;
CollisionIndex collisionIndex;
@@ -147,6 +148,7 @@ private:
std::unordered_map<uint32_t, RetainedQueryData> retainedQueryData;
CollisionGroups collisionGroups;
std::unique_ptr<Placement> prevPlacement;
optional<Duration> maximumUpdatePeriod;
// Used for debug purposes.
std::unordered_map<const CollisionFeature*, std::vector<ProjectedCollisionBox>> collisionCircles;