move Sprite to MapContext

This commit is contained in:
Konstantin Käfer
2015-03-23 17:50:49 +01:00
committed by John Firebaugh
parent 9af7af3109
commit 07525d5d50
2 changed files with 13 additions and 15 deletions

View File

@@ -241,7 +241,6 @@ private:
std::atomic_bool isStopped;
util::ptr<Style> style;
util::ptr<Sprite> sprite;
std::atomic<UpdateType> updated;

View File

@@ -74,12 +74,13 @@ public:
}
public:
std::unique_ptr<GlyphStore> glyphStore;
std::unique_ptr<GlyphAtlas> glyphAtlas;
std::unique_ptr<SpriteAtlas> spriteAtlas;
std::unique_ptr<LineAtlas> lineAtlas;
std::unique_ptr<TexturePool> texturePool;
std::unique_ptr<Painter> painter;
const std::unique_ptr<GlyphStore> glyphStore;
const std::unique_ptr<GlyphAtlas> glyphAtlas;
const std::unique_ptr<SpriteAtlas> spriteAtlas;
const std::unique_ptr<LineAtlas> lineAtlas;
const std::unique_ptr<TexturePool> texturePool;
const std::unique_ptr<Painter> painter;
util::ptr<Sprite> sprite;
};
@@ -107,7 +108,6 @@ Map::~Map() {
"MapandMain");
// Explicitly reset all pointers.
sprite.reset();
style.reset();
workers.reset();
context.reset();
@@ -463,14 +463,13 @@ util::ptr<Sprite> Map::getSprite() {
assert(Environment::currentlyOn(ThreadType::Map));
const float pixelRatio = data->getTransformState().getPixelRatio();
const std::string &sprite_url = style->getSpriteURL();
if (!sprite || !sprite->hasPixelRatio(pixelRatio)) {
sprite = Sprite::Create(sprite_url, pixelRatio, *env);
if (!context->sprite || !context->sprite->hasPixelRatio(pixelRatio)) {
context->sprite = Sprite::Create(sprite_url, pixelRatio, *env);
}
return sprite;
return context->sprite;
}
#pragma mark - Size
void Map::resize(uint16_t width, uint16_t height, float ratio) {
@@ -654,8 +653,8 @@ void Map::setDefaultPointAnnotationSymbol(const std::string& symbol) {
double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) {
assert(Environment::currentlyOn(ThreadType::Main));
return invokeSyncTask([&] {
assert(sprite);
const SpritePosition pos = sprite->getSpritePosition(symbol);
assert(context->sprite);
const SpritePosition pos = context->sprite->getSpritePosition(symbol);
return -pos.height / pos.pixelRatio / 2;
});
}
@@ -810,7 +809,7 @@ void Map::reloadStyle() {
void Map::loadStyleJSON(const std::string& json, const std::string& base) {
assert(Environment::currentlyOn(ThreadType::Map));
sprite.reset();
context->sprite.reset();
style = std::make_shared<Style>();
style->base = base;
style->loadJSON((const uint8_t *)json.c_str());