Files
MapLibreParticleLab/src/mbgl/map/resource_loader.cpp
Thiago Marcos P. Santos aaaf1e4c14 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
2015-05-18 10:42:05 +03:00

134 lines
3.1 KiB
C++

#include <mbgl/map/resource_loader.hpp>
#include <mbgl/geometry/sprite_atlas.hpp>
#include <mbgl/map/environment.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/map/sprite.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/style/style.hpp>
#include <cassert>
namespace mbgl {
ResourceLoader::ResourceLoader() {
assert(Environment::currentlyOn(ThreadType::Map));
}
ResourceLoader::~ResourceLoader() {
assert(Environment::currentlyOn(ThreadType::Map));
for (const auto& source : style_->sources) {
source->setObserver(nullptr);
}
if (sprite_) {
sprite_->setObserver(nullptr);
}
if (glyphStore_) {
glyphStore_->setObserver(nullptr);
}
}
void ResourceLoader::setObserver(Observer* observer) {
assert(Environment::currentlyOn(ThreadType::Map));
assert(!observer_);
observer_ = observer;
}
void ResourceLoader::setStyle(Style* style) {
assert(style);
style_ = style;
for (const auto& source : style->sources) {
source->setObserver(this);
source->load(accessToken_);
}
}
void ResourceLoader::setGlyphStore(GlyphStore* glyphStore) {
assert(glyphStore);
if (glyphStore_) {
glyphStore_->setObserver(nullptr);
}
glyphStore_ = glyphStore;
glyphStore_->setObserver(this);
}
void ResourceLoader::setAccessToken(const std::string& accessToken) {
accessToken_ = accessToken;
}
void ResourceLoader::update(MapData& data,
const TransformState& transform,
GlyphAtlas& glyphAtlas,
SpriteAtlas& spriteAtlas,
TexturePool& texturePool) {
if (!style_) {
return;
}
const float pixelRatio = transform.getPixelRatio();
if (!sprite_ || !sprite_->hasPixelRatio(pixelRatio)) {
sprite_ = util::make_unique<Sprite>(style_->getSpriteURL(), pixelRatio);
sprite_->setObserver(this);
spriteAtlas.resize(pixelRatio);
spriteAtlas.setSprite(sprite_);
}
bool allTilesUpdated = true;
for (const auto& source : style_->sources) {
if (!source->update(data, transform, *style_, glyphAtlas, *glyphStore_,
spriteAtlas, sprite_, texturePool, shouldReparsePartialTiles_)) {
allTilesUpdated = false;
}
}
// We can only stop updating "partial" tiles when all of them
// were notified of the arrival of the new resources.
if (allTilesUpdated) {
shouldReparsePartialTiles_ = false;
}
}
void ResourceLoader::onGlyphRangeLoaded() {
shouldReparsePartialTiles_ = true;
emitTileDataChanged();
}
void ResourceLoader::onSourceLoaded() {
emitTileDataChanged();
}
void ResourceLoader::onTileLoaded(bool isNewTile) {
if (isNewTile) {
shouldReparsePartialTiles_ = true;
}
emitTileDataChanged();
}
void ResourceLoader::onSpriteLoaded() {
shouldReparsePartialTiles_ = true;
emitTileDataChanged();
}
void ResourceLoader::emitTileDataChanged() {
assert(Environment::currentlyOn(ThreadType::Map));
if (observer_) {
observer_->onTileDataChanged();
}
}
}