Only emit tile updated signals when the tile really changes

We only emit signals when the number of buckets increase (i.e. the
new data that arrived added a new bucket to the tile).

Also, if we try to reparse a partial tile but it is not possible, we
keep the flag up for trying to reparse it again on the next update,
because the data might have arrived after the bucket that is waiting
for the data was processed but before the end of the parsing.

Fixes #1458
This commit is contained in:
Thiago Marcos P. Santos
2015-05-11 18:41:44 +03:00
parent 4e7c97466c
commit aaaf1e4c14
7 changed files with 59 additions and 17 deletions

View File

@@ -219,21 +219,30 @@ TileData::State Source::hasTile(const TileID& id) {
return TileData::State::invalid;
}
void Source::handlePartialTile(const TileID& id, Worker& worker) {
bool Source::handlePartialTile(const TileID& id, Worker& worker) {
const TileID normalized_id = id.normalized();
auto it = tile_data.find(normalized_id);
if (it == tile_data.end()) {
return;
return true;
}
util::ptr<TileData> data = it->second.lock();
if (!data) {
return;
return true;
}
auto callback = std::bind(&Source::emitTileLoaded, this, false);
data->reparse(worker, callback);
// The signal is only emitted if there was an actual change on the tile. The
// tile can be in a "partial" state waiting for resources and get reparsed on
// the arrival of new resources that were needed by another tile.
size_t bucketCount = static_cast<VectorTileData*>(data.get())->countBuckets();
auto callback = [this, data, bucketCount]() {
if (static_cast<VectorTileData*>(data.get())->countBuckets() > bucketCount) {
emitTileLoaded(false);
}
};
return data->reparse(worker, callback);
}
TileData::State Source::addTile(MapData& data,
@@ -377,7 +386,7 @@ bool Source::findLoadedParent(const TileID& id, int32_t minCoveringZoom, std::fo
return false;
}
void Source::update(MapData& data,
bool Source::update(MapData& data,
const TransformState& transformState,
Style& style,
GlyphAtlas& glyphAtlas,
@@ -386,8 +395,10 @@ void Source::update(MapData& data,
util::ptr<Sprite> sprite,
TexturePool& texturePool,
bool shouldReparsePartialTiles) {
bool allTilesUpdated = true;
if (!loaded || data.getAnimationTime() <= updated) {
return;
return allTilesUpdated;
}
int32_t zoom = std::floor(getZoom(transformState));
@@ -408,8 +419,11 @@ void Source::update(MapData& data,
switch (state) {
case TileData::State::partial:
if (shouldReparsePartialTiles)
handlePartialTile(id, style.workers);
if (shouldReparsePartialTiles) {
if (!handlePartialTile(id, style.workers)) {
allTilesUpdated = false;
}
}
break;
case TileData::State::invalid:
state = addTile(data, transformState, style, glyphAtlas, glyphStore,
@@ -484,6 +498,8 @@ void Source::update(MapData& data,
updateTilePtrs();
updated = data.getAnimationTime();
return allTilesUpdated;
}
void Source::invalidateTiles(const std::vector<TileID>& ids) {