Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] make symbols fade out faster while zooming out #15416

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mbgl/renderer/render_orchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(const UpdatePar
}

bool symbolBucketsChanged = false;
const bool placementChanged = !placement->stillRecent(updateParameters.timePoint);
const bool placementChanged = !placement->stillRecent(updateParameters.timePoint, updateParameters.transformState.getZoom());
std::set<std::string> usedSymbolLayers;
if (placementChanged) {
placement = std::make_unique<Placement>(
Expand All @@ -381,7 +381,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(const UpdatePar
}

if (placementChanged) {
placement->commit(updateParameters.timePoint);
placement->commit(updateParameters.timePoint, updateParameters.transformState.getZoom());
crossTileSymbolIndex.pruneUnusedLayers(usedSymbolLayers);
for (const auto& entry : renderSources) {
entry.second->updateFadingTiles();
Expand Down
26 changes: 17 additions & 9 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Placement::Placement(const TransformState& state_, MapMode mapMode_, style::Tran
: collisionIndex(state_)
, mapMode(mapMode_)
, transitionOptions(std::move(transitionOptions_))
, placementZoom(state_.getZoom())
, collisionGroups(crossSourceCollisions)
, prevPlacement(std::move(prevPlacement_))
{
Expand Down Expand Up @@ -438,17 +439,15 @@ void Placement::placeBucket(
std::forward_as_tuple(bucket.bucketInstanceId, params.featureIndex, overscaledID));
}

void Placement::commit(TimePoint now) {
void Placement::commit(TimePoint now, const double zoom) {
assert(prevPlacement);
commitTime = now;

bool placementChanged = false;

float increment = mapMode == MapMode::Continuous &&
transitionOptions.enablePlacementTransitions &&
transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) > Milliseconds(0) ?
std::chrono::duration<float>(commitTime - prevPlacement->commitTime) / transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) :
1.0;
prevZoomAdjustment = prevPlacement->zoomAdjustment(zoom);

float increment = prevPlacement->symbolFadeChange(commitTime);

// add the opacities from the current placement, and copy their current values from the previous placement
for (auto& jointPlacement : placements) {
Expand Down Expand Up @@ -855,12 +854,20 @@ void Placement::markUsedOrientation(SymbolBucket& bucket, style::TextWritingMode
float Placement::symbolFadeChange(TimePoint now) const {
if (mapMode == MapMode::Continuous && transitionOptions.enablePlacementTransitions &&
transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) > Milliseconds(0)) {
return std::chrono::duration<float>(now - commitTime) / transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION);
return std::chrono::duration<float>(now - commitTime) / transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION) + prevZoomAdjustment;
} else {
return 1.0;
}
}

float Placement::zoomAdjustment(const float zoom) const {
// When zooming out labels can overlap each other quickly. This
// adjustment is used to reduce the fade duration for symbols while zooming out quickly.
// It is also used to reduce the interval between placement calculations. Reducing the
// interval between placements means collisions are discovered and eliminated sooner.
return std::max(0.0, (placementZoom - zoom) / 1.5);
}

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);
Expand All @@ -869,12 +876,13 @@ bool Placement::hasTransitions(TimePoint now) const {
}
}

bool Placement::stillRecent(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 + std::max(util::DEFAULT_TRANSITION_DURATION, transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION)) > now;
commitTime + fadeDuration * (1.0 - zoomAdjustment(zoom)) > now;
}

void Placement::setStale() {
Expand Down
7 changes: 5 additions & 2 deletions src/mbgl/text/placement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ class Placement {
public:
Placement(const TransformState&, MapMode, style::TransitionOptions, const bool crossSourceCollisions, std::unique_ptr<Placement> prevPlacementOrNull = nullptr);
void placeLayer(const RenderLayer&, const mat4&, bool showCollisionBoxes);
void commit(TimePoint);
void commit(TimePoint, const double zoom);
void updateLayerBuckets(const RenderLayer&, const TransformState&, bool updateOpacities);
float symbolFadeChange(TimePoint now) const;
bool hasTransitions(TimePoint now) const;

const CollisionIndex& getCollisionIndex() const;

bool stillRecent(TimePoint now) const;
bool stillRecent(TimePoint now, const float zoom) const;
void setRecent(TimePoint now);
void setStale();

Expand All @@ -125,6 +125,7 @@ class Placement {
void updateBucketOpacities(SymbolBucket&, const TransformState&, std::set<uint32_t>&);
void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, const SymbolInstance&, style::TextWritingModeType orientation);
void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&);
float zoomAdjustment(const float zoom) const;

CollisionIndex collisionIndex;

Expand All @@ -133,6 +134,8 @@ class Placement {

TimePoint fadeStartTime;
TimePoint commitTime;
float placementZoom;
float prevZoomAdjustment = 0;

std::unordered_map<uint32_t, JointPlacement> placements;
std::unordered_map<uint32_t, JointOpacityState> opacities;
Expand Down