Skip to content

Commit

Permalink
ignore animations that are only cached symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
maerki committed Jan 13, 2024
1 parent 8ebf024 commit a972ec6
Show file tree
Hide file tree
Showing 9 changed files with 77 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 @@ -538,7 +538,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*0 || 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 @@ -553,7 +555,7 @@ void Tiled2dMapVectorLayer::update() {
newIsAnimating |= a;
}
isAnimating = newIsAnimating;
if (now - lastCollitionCheck > 2000*0 || 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,17 @@ class SymbolAnimationCoordinator {
}

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

}
if (isIconAnimating() || isStretchIconAnimating() || isTextAnimating()) {
// printf("Animate %p: %d, %d, %d, %d: %f|%f\n", static_cast<void*>(this), isIconAnimating(), isStretchIconAnimating(), isTextAnimating(), isUsed(), coordinate.x, coordinate.y);
return true;
}
else {
return false;
}
}

bool isIconAnimating() {
Expand Down Expand Up @@ -83,6 +93,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 +130,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 @@ -161,6 +161,32 @@ Tiled2dMapVectorSymbolObject::Tiled2dMapVectorSymbolObject(const std::weak_ptr<M
isStyleStateDependant = usedKeys.isStateDependant();
}

Tiled2dMapVectorSymbolObject::~Tiled2dMapVectorSymbolObject() {
if (animationCoordinator) {
if (isCoordinateOwner) {
animationCoordinator->isOwned.clear();
isCoordinateOwner = false;
}
animationCoordinator->decreaseUsage();
}
}

void Tiled2dMapVectorSymbolObject::placedInCache() {
if (animationCoordinator) {
if (isCoordinateOwner) {
animationCoordinator->isOwned.clear();
isCoordinateOwner = false;
}
animationCoordinator->increaseCache();
}
}

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

void Tiled2dMapVectorSymbolObject::updateLayerDescription(const std::shared_ptr<SymbolVectorLayerDescription> layerDescription, const UsedKeysCollection &usedKeys) {
this->description = layerDescription;
if (labelObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Tiled2dMapVectorSymbolObject {
}
}

void removeFromCache();

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

const SymbolObjectInstanceCounts getInstanceCounts() const;
Expand Down

0 comments on commit a972ec6

Please sign in to comment.