Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] load parents of missing tiles as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed May 30, 2016
1 parent ddaf3a9 commit 4a0005d
Show file tree
Hide file tree
Showing 3 changed files with 672 additions and 379 deletions.
30 changes: 20 additions & 10 deletions src/mbgl/algorithm/update_renderables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ void updateRenderables(GetTileDataFn getTileData,
const OverscaledTileID idealDataTileID(dataTileZoom, idealRenderTileID.canonical);
auto data = getTileData(idealDataTileID);
if (!data) {
data = createTileData(idealDataTileID, true);
data = createTileData(idealDataTileID);
assert(data);
}

// if (source has the tile and bucket is loaded) {
if (data->isRenderable()) {
retainTileData(*data);
retainTileData(*data, true);
renderTile(idealRenderTileID, *data);
} else {
bool triedPrevious = data->hasTriedOptional();

// The tile isn't loaded yet, but retain it anyway because it's an ideal tile.
retainTileData(*data);
retainTileData(*data, true);
covered = true;
overscaledZ = dataTileZoom + 1;
if (overscaledZ > info.maxZoom) {
// We're looking for an overzoomed child tile.
const auto childDataTileID = idealDataTileID.scaledTo(overscaledZ);
data = getTileData(childDataTileID);
if (data && data->isRenderable()) {
retainTileData(*data);
retainTileData(*data, false);
renderTile(idealRenderTileID, *data);
} else {
covered = false;
Expand All @@ -62,7 +64,7 @@ void updateRenderables(GetTileDataFn getTileData,
const OverscaledTileID childDataTileID(overscaledZ, childTileID);
data = getTileData(childDataTileID);
if (data && data->isRenderable()) {
retainTileData(*data);
retainTileData(*data, false);
renderTile(childDataTileID.unwrapTo(idealRenderTileID.wrap), *data);
} else {
// At least one child tile doesn't exist, so we are going to look for
Expand All @@ -88,11 +90,19 @@ void updateRenderables(GetTileDataFn getTileData,
}

data = getTileData(parentDataTileID);
if (data && data->isRenderable()) {
retainTileData(*data);
renderTile(parentRenderTileID, *data);
// Break parent tile ascent, since we found one.
break;
if (!data && triedPrevious) {
data = createTileData(parentDataTileID);
}

if (data) {
triedPrevious = data->hasTriedOptional();
retainTileData(*data, false);

if (data->isRenderable()) {
renderTile(parentRenderTileID, *data);
// Break parent tile ascent, since we found one.
break;
}
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/mbgl/source/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,16 @@ bool Source::update(const StyleUpdateParameters& parameters) {
// we're actively using, e.g. as a replacement for tile that aren't loaded yet.
std::set<OverscaledTileID> retain;

auto retainTileDataFn = [&retain](const TileData& tileData) -> void {
auto retainTileDataFn = [&retain](TileData& tileData, bool required) -> void {
retain.emplace(tileData.id);
tileData.getTileSource()->setNecessity(required ? TileSource::Necessity::Required
: TileSource::Necessity::Optional);
};
auto getTileDataFn = [this](const OverscaledTileID& dataTileID) -> TileData* {
return getTileData(dataTileID);
};
auto createTileDataFn = [this, &parameters](const OverscaledTileID& dataTileID,
bool required) -> TileData* {
auto createTileDataFn = [this, &parameters](const OverscaledTileID& dataTileID) -> TileData* {
if (auto data = createTile(dataTileID, parameters)) {
if (required) {
data->getTileSource()->setNecessity(TileSource::Necessity::Required);
}
return tileDataMap.emplace(dataTileID, std::move(data)).first->second.get();
} else {
return nullptr;
Expand Down
Loading

0 comments on commit 4a0005d

Please sign in to comment.