Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up first-draw by reducing initial map size #2707

Merged
merged 3 commits into from
Jan 7, 2020
Merged
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
13 changes: 11 additions & 2 deletions src/tiled/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,18 @@ void MapView::fitMapInView()
if (rect.isEmpty())
return;

// Scale and center map to fit in view
// Scale and center map to fit in view, while avoiding to go below the
// minimum scale. For extremely large maps, avoid putting more than about
// 256 * 256 tiles within the view for performance reasons.
qreal desiredScale = std::min(width() / rect.width(),
height() / rect.height()) * 0.95;

auto tileSize = mMapDocument->map()->tileSize();
qreal scale256 = std::min(width() / (256.0 * tileSize.width()),
height() / (256.0 * tileSize.height()));

centerOn(rect.center());
setScale(std::min(width() / rect.width(), height() / rect.height()) * 0.95);
setScale(std::max(std::max(desiredScale, scale256), 0.015625));
}

void MapView::adjustScale(qreal scale)
Expand Down