From be32e441103060a633f43fa439ab8d98d3135538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A4rki?= Date: Fri, 12 Jan 2024 21:19:25 +0100 Subject: [PATCH 1/4] reduce updates --- shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp index 28ae93869..97ac1effa 100644 --- a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp +++ b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp @@ -538,7 +538,7 @@ 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) { + if (abs(newZoom-lastDataManagerZoom) / std::max(newZoom, 1.0) > 0.001 || now - lastDataManagerUpdate > 1000 || isAnimating || tilesChanged) { lastDataManagerUpdate = now; lastDataManagerZoom = newZoom; @@ -553,7 +553,7 @@ void Tiled2dMapVectorLayer::update() { newIsAnimating |= a; } isAnimating = newIsAnimating; - if (now - lastCollitionCheck > 2000*0 || tilesChanged) { + if (now - lastCollitionCheck > 2000 || tilesChanged) { lastCollitionCheck = now; bool enforceUpdate = !prevCollisionStillValid.test_and_set(); collisionManager.syncAccess([&vpMatrix, &viewportSize, viewportRotation, enforceUpdate](const auto &manager) { From 6fe509c0b27edf7231f7e17991573713c831493a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A4rki?= Date: Sun, 14 Jan 2024 10:24:24 +0100 Subject: [PATCH 2/4] invalidate after geosource and style change --- .../src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp index 97ac1effa..f2ac0cb95 100644 --- a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp +++ b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp @@ -510,6 +510,9 @@ void Tiled2dMapVectorLayer::reloadLocalDataSource(const std::string &sourceName, source->reloadTiles(); }); } + + tilesStillValid.clear(); + mapInterface->invalidate(); } std::shared_ptr<::LayerInterface> Tiled2dMapVectorLayer::asLayerInterface() { @@ -1048,6 +1051,9 @@ void Tiled2dMapVectorLayer::updateLayerDescription(std::shared_ptrinvalidate(); } std::optional> Tiled2dMapVectorLayer::getFeatureContext(int64_t identifier) { From 4fb8bdf41b0624b36f77e4af228d8107ede422b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A4rki?= Date: Sun, 14 Jan 2024 10:25:00 +0100 Subject: [PATCH 3/4] render at least 3 seconds --- ios/maps/MCMapView.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ios/maps/MCMapView.swift b/ios/maps/MCMapView.swift index 2e32fb50f..e953506e7 100644 --- a/ios/maps/MCMapView.swift +++ b/ios/maps/MCMapView.swift @@ -22,8 +22,10 @@ open class MCMapView: MTKView { private var saveDrawable = false private lazy var renderToImageQueue = DispatchQueue(label: "io.openmobilemaps.renderToImagQueue", qos: .userInteractive) - private var framesToRender: UInt = 1 - private let framesToRenderAfterInvalidate: UInt = 25 + private var framesToRender: Int = 1 + private let framesToRenderAfterInvalidate: Int = 25 + private var lastInvalidate = Date() + private let renderAfterInvalidate: TimeInterval = 3 // Collision detection might be delayed 3s private let touchHandler: MCMapViewTouchHandler private let callbackHandler = MCMapViewCallbackHandler() @@ -131,6 +133,7 @@ open class MCMapView: MTKView { public func invalidate() { isPaused = false framesToRender = framesToRenderAfterInvalidate + lastInvalidate = Date() } } @@ -145,7 +148,7 @@ extension MCMapView: MTKViewDelegate { return // don't execute metal calls in background } - guard framesToRender != 0 else { + guard framesToRender > 0 || -lastInvalidate.timeIntervalSinceNow < renderAfterInvalidate else { isPaused = true return } From cf5af26f1c102fda854126f14d61852069aff0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A4rki?= Date: Sun, 14 Jan 2024 11:14:21 +0100 Subject: [PATCH 4/4] ensure update and animation triggered after data change --- shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp index f2ac0cb95..09dbe7115 100644 --- a/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp +++ b/shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp @@ -562,6 +562,7 @@ void Tiled2dMapVectorLayer::update() { collisionManager.syncAccess([&vpMatrix, &viewportSize, viewportRotation, enforceUpdate](const auto &manager) { manager->collisionDetection(*vpMatrix, viewportSize, viewportRotation, enforceUpdate); }); + isAnimating = true; } } @@ -1003,6 +1004,8 @@ void Tiled2dMapVectorLayer::updateLayerDescriptions(const std::vectorinvalidate(); } void Tiled2dMapVectorLayer::updateLayerDescription(std::shared_ptr layerDescription) { @@ -1198,6 +1201,7 @@ void Tiled2dMapVectorLayer::applyGlobalOrFeatureStateIfPossible(StateType type) } } + tilesStillValid.clear(); mapInterface->invalidate(); }