Skip to content

Commit

Permalink
Merge pull request #570 from openmobilemaps/bugfix/reduce-updates
Browse files Browse the repository at this point in the history
reduce updates
  • Loading branch information
maurhofer-ubique authored Jan 22, 2024
2 parents 123c264 + cf5af26 commit 4787352
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 6 additions & 3 deletions ios/maps/MCMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -131,6 +133,7 @@ open class MCMapView: MTKView {
public func invalidate() {
isPaused = false
framesToRender = framesToRenderAfterInvalidate
lastInvalidate = Date()
}
}

Expand All @@ -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
}
Expand Down
14 changes: 12 additions & 2 deletions shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ void Tiled2dMapVectorLayer::reloadLocalDataSource(const std::string &sourceName,
source->reloadTiles();
});
}

tilesStillValid.clear();
mapInterface->invalidate();
}

std::shared_ptr<::LayerInterface> Tiled2dMapVectorLayer::asLayerInterface() {
Expand Down Expand Up @@ -538,7 +541,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;

Expand All @@ -553,12 +556,13 @@ 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) {
manager->collisionDetection(*vpMatrix, viewportSize, viewportRotation, enforceUpdate);
});
isAnimating = true;
}
}

Expand Down Expand Up @@ -1000,6 +1004,8 @@ void Tiled2dMapVectorLayer::updateLayerDescriptions(const std::vector<std::share
}
}

tilesStillValid.clear();
mapInterface->invalidate();
}

void Tiled2dMapVectorLayer::updateLayerDescription(std::shared_ptr<VectorLayerDescription> layerDescription) {
Expand Down Expand Up @@ -1048,6 +1054,9 @@ void Tiled2dMapVectorLayer::updateLayerDescription(std::shared_ptr<VectorLayerDe
}
}
}

tilesStillValid.clear();
mapInterface->invalidate();
}

std::optional<std::shared_ptr<FeatureContext>> Tiled2dMapVectorLayer::getFeatureContext(int64_t identifier) {
Expand Down Expand Up @@ -1192,6 +1201,7 @@ void Tiled2dMapVectorLayer::applyGlobalOrFeatureStateIfPossible(StateType type)
}
}

tilesStillValid.clear();
mapInterface->invalidate();
}

Expand Down

0 comments on commit 4787352

Please sign in to comment.