Skip to content

Commit

Permalink
Merge pull request #571 from openmobilemaps/bugfix/ignore-animations-…
Browse files Browse the repository at this point in the history
…in-cache

ignore animations that are only cached symbols
  • Loading branch information
maurhofer-ubique authored Jan 24, 2024
2 parents 633e5cf + 47cec33 commit 196aca9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shared/public/Tiled2dMapSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Tiled2dMapSource :
float screenDensityPpi;
std::set<Tiled2dMapTileInfo> readyTiles;

size_t lastVisibleTilesHash;
size_t lastVisibleTilesHash = -1;

void onVisibleTilesChanged(const std::vector<VisibleTilesLayer> &pyramid, int keepZoomLevelOffset = 0);

Expand Down
5 changes: 4 additions & 1 deletion shared/public/Tiled2dMapSourceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ void Tiled2dMapSource<T, L, R>::onVisibleBoundsChanged(const ::RectCoord &visibl
if (!zoomInfo.underzoom
&& (zoomLevelInfos.empty() || zoomLevelInfos[0].zoom * zoomInfo.zoomLevelScaleFactor * screenScaleFactor < zoom)
&& (zoomLevelInfos.empty() || zoomLevelInfos[0].zoomLevelIdentifier != 0)) { // enable underzoom if the first zoomLevel is zoomLevelIdentifier == 0
onVisibleTilesChanged({});
if (lastVisibleTilesHash != 0) {
lastVisibleTilesHash = 0;
onVisibleTilesChanged({});
}
return;
}

Expand Down
6 changes: 4 additions & 2 deletions shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ void Tiled2dMapVectorLayer::update() {
auto now = DateHelper::currentTimeMillis();
bool newIsAnimating = false;
bool tilesChanged = !tilesStillValid.test_and_set();
if (abs(newZoom-lastDataManagerZoom) / std::max(newZoom, 1.0) > 0.001 || now - lastDataManagerUpdate > 1000 || isAnimating || tilesChanged) {
double zoomChange = abs(newZoom-lastDataManagerZoom) / std::max(newZoom, 1.0);
double timeDiff = now - lastDataManagerUpdate;
if (zoomChange > 0.001 || timeDiff > 2000 || isAnimating || tilesChanged) {
lastDataManagerUpdate = now;
lastDataManagerZoom = newZoom;

Expand All @@ -556,7 +558,7 @@ void Tiled2dMapVectorLayer::update() {
newIsAnimating |= a;
}
isAnimating = newIsAnimating;
if (now - lastCollitionCheck > 2000 || tilesChanged) {
if (now - lastCollitionCheck > 3000 || tilesChanged) {
lastCollitionCheck = now;
bool enforceUpdate = !prevCollisionStillValid.test_and_set();
collisionManager.syncAccess([&vpMatrix, &viewportSize, viewportRotation, enforceUpdate](const auto &manager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ class SymbolAnimationCoordinator {
}

bool isAnimating() {
return isIconAnimating() || isStretchIconAnimating() || isTextAnimating();
if (cacheCount >= usageCount) {
return false;

}
if (isIconAnimating() || isStretchIconAnimating() || isTextAnimating()) {
return true;
}
else {
return false;
}
}

bool isIconAnimating() {
Expand Down Expand Up @@ -83,6 +92,14 @@ class SymbolAnimationCoordinator {
return --usageCount;
}

int increaseCache() {;
return ++cacheCount;
}

int decreaseCache() {
return --cacheCount;
}

std::atomic_flag isOwned = ATOMIC_FLAG_INIT;

// returns true if the value was changed
Expand Down Expand Up @@ -112,6 +129,7 @@ class SymbolAnimationCoordinator {
float lastTextAlpha = 0;

std::atomic_int usageCount = 0;
std::atomic_int cacheCount = 0;

bool collides = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,18 @@ void Tiled2dMapVectorSourceSymbolDataManager::updateSymbolGroups() {
if (tileStateIt == tileStateMap.end()) {
tileStateMap[tile] = state;
} else {
if (tileStateIt->second == TileState::CACHED && state != TileState::CACHED) {
auto tileSymbolGroupMapIt = tileSymbolGroupMap.find(tile);
if (tileSymbolGroupMapIt != tileSymbolGroupMap.end()) {
for (const auto &[layerIdentifier, symbolGroups]: tileSymbolGroupMapIt->second) {
for (auto &symbolGroup: std::get<1>(symbolGroups)) {
symbolGroup.syncAccess([&](auto group) {
group->removeFromCache();
});
}
}
}
}
tileStateIt->second = state;
}
if (state == TileState::CACHED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ void Tiled2dMapVectorSymbolGroup::placedInCache() {
}
}

void Tiled2dMapVectorSymbolGroup::removeFromCache() {
for (auto const object: symbolObjects) {
object->removeFromCache();
}
}


std::vector<std::shared_ptr< ::RenderObjectInterface>> Tiled2dMapVectorSymbolGroup::getRenderObjects() {
std::vector<std::shared_ptr< ::RenderObjectInterface>> renderObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class Tiled2dMapVectorSymbolGroup : public ActorObject, public std::enable_share

void placedInCache();

void removeFromCache();

void clear();

void updateLayerDescription(const std::shared_ptr<SymbolVectorLayerDescription> layerDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ void Tiled2dMapVectorSymbolObject::placedInCache() {
animationCoordinator->isOwned.clear();
isCoordinateOwner = false;
}
animationCoordinator->increaseCache();
}
}

void Tiled2dMapVectorSymbolObject::removeFromCache() {
if (animationCoordinator) {
animationCoordinator->decreaseCache();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Tiled2dMapVectorSymbolObject {

void placedInCache();

void removeFromCache();

struct SymbolObjectInstanceCounts { int icons, textCharacters, stretchedIcons; };

const SymbolObjectInstanceCounts getInstanceCounts() const;
Expand Down

0 comments on commit 196aca9

Please sign in to comment.