Keep a pointer to GlyphStore on ResourceLoader
For now, keep a pointer so we can subscribe/unsubscribe to events. In the future, we should move this object completely to ResourceLoader, but we can't do it now because we delete the ResourceLoader when changing the style.
This commit is contained in:
@@ -134,6 +134,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
|
||||
resourceLoader->setAccessToken(data.getAccessToken());
|
||||
resourceLoader->setObserver(this);
|
||||
resourceLoader->setStyle(style.get());
|
||||
resourceLoader->setGlyphStore(glyphStore.get());
|
||||
|
||||
triggerUpdate(Update::Zoom);
|
||||
}
|
||||
@@ -141,8 +142,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
|
||||
void MapContext::updateTiles() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
|
||||
resourceLoader->update(data, transformState, *glyphAtlas, *glyphStore,
|
||||
*spriteAtlas, *texturePool);
|
||||
resourceLoader->update(data, transformState, *glyphAtlas, *spriteAtlas, *texturePool);
|
||||
}
|
||||
|
||||
void MapContext::updateAnnotationTiles(const std::vector<TileID>& ids) {
|
||||
|
||||
@@ -25,6 +25,10 @@ ResourceLoader::~ResourceLoader() {
|
||||
if (sprite_) {
|
||||
sprite_->setObserver(nullptr);
|
||||
}
|
||||
|
||||
if (glyphStore_) {
|
||||
glyphStore_->setObserver(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceLoader::setObserver(Observer* observer) {
|
||||
@@ -45,6 +49,18 @@ void ResourceLoader::setStyle(Style* style) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -52,7 +68,6 @@ void ResourceLoader::setAccessToken(const std::string& accessToken) {
|
||||
void ResourceLoader::update(MapData& data,
|
||||
const TransformState& transform,
|
||||
GlyphAtlas& glyphAtlas,
|
||||
GlyphStore& glyphStore,
|
||||
SpriteAtlas& spriteAtlas,
|
||||
TexturePool& texturePool) {
|
||||
if (!style_) {
|
||||
@@ -69,8 +84,8 @@ void ResourceLoader::update(MapData& data,
|
||||
}
|
||||
|
||||
for (const auto& source : style_->sources) {
|
||||
source->update(
|
||||
data, transform, *style_, glyphAtlas, glyphStore, spriteAtlas, sprite_, texturePool);
|
||||
source->update(data, transform, *style_, glyphAtlas, *glyphStore_,
|
||||
spriteAtlas, sprite_, texturePool);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,13 +43,17 @@ public:
|
||||
// a new style we will go through all of them and try to load.
|
||||
void setStyle(Style* style);
|
||||
|
||||
// TODO: Move GlyphStore to ResourceLoader. We cannot do it now
|
||||
// because we reset the ResourceLoader every time we change the
|
||||
// style.
|
||||
void setGlyphStore(GlyphStore* glyphStore);
|
||||
|
||||
// Set the access token to be used for loading the tile data.
|
||||
void setAccessToken(const std::string& accessToken);
|
||||
|
||||
// Fetch the tiles needed by the current viewport and emit a signal when
|
||||
// a tile is ready so observers can render the tile.
|
||||
void update(MapData&, const TransformState&, GlyphAtlas&, GlyphStore&,
|
||||
SpriteAtlas&, TexturePool&);
|
||||
void update(MapData&, const TransformState&, GlyphAtlas&, SpriteAtlas&, TexturePool&);
|
||||
|
||||
// FIXME: There is probably a better place for this.
|
||||
inline util::ptr<Sprite> getSprite() const {
|
||||
@@ -71,7 +75,10 @@ private:
|
||||
|
||||
std::string accessToken_;
|
||||
util::ptr<Sprite> sprite_;
|
||||
|
||||
GlyphStore* glyphStore_ = nullptr;
|
||||
Style* style_ = nullptr;
|
||||
|
||||
Observer* observer_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user