diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index e7dc28ad7..742572a35 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -321,7 +321,7 @@ std::vector Painter::determineRenderOrder(const Style& style) { continue; } - util::ptr source = style.getSource(layer.bucket->source); + Source* source = style.getSource(layer.bucket->source); if (!source) { Log::Warning(Event::Render, "can't find source for layer '%s'", layer.id.c_str()); continue; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 35a94adbc..23d32689e 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -113,7 +113,7 @@ void Style::recalculate(float z, TimePoint now) { continue; } - util::ptr source = getSource(layer->bucket->source); + Source* source = getSource(layer->bucket->source); if (!source) { continue; } @@ -122,12 +122,12 @@ void Style::recalculate(float z, TimePoint now) { } } -util::ptr Style::getSource(const std::string& id) const { - const auto it = std::find_if(sources.begin(), sources.end(), [&](util::ptr source) { +Source* Style::getSource(const std::string& id) const { + const auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) { return source->info.source_id == id; }); - return it != sources.end() ? *it : nullptr; + return it != sources.end() ? it->get() : nullptr; } void Style::setDefaultTransitionDuration(Duration duration) { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 003183e3c..d96833da2 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -62,7 +62,7 @@ public: return lastError; } - util::ptr getSource(const std::string& id) const; + Source* getSource(const std::string& id) const; std::unique_ptr glyphStore; std::unique_ptr glyphAtlas; @@ -70,7 +70,7 @@ public: std::unique_ptr spriteAtlas; std::unique_ptr lineAtlas; - std::vector> sources; + std::vector> sources; std::vector> layers; private: diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index dba737828..53313a548 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -39,11 +39,11 @@ void StyleParser::parse(JSVal document) { // create shape annotations source const std::string& shapeID = AnnotationManager::ShapeLayerID; - util::ptr shapeAnnotationsSource = std::make_shared(); - sourcesMap.emplace(shapeID, shapeAnnotationsSource); - sources.emplace_back(shapeAnnotationsSource); + std::unique_ptr shapeAnnotationsSource = std::make_unique(); shapeAnnotationsSource->info.type = SourceType::Annotations; shapeAnnotationsSource->info.source_id = shapeID; + sourcesMap.emplace(shapeID, shapeAnnotationsSource.get()); + sources.emplace_back(std::move(shapeAnnotationsSource)); // create point annotations layer const std::string& pointID = AnnotationManager::PointLayerID; @@ -70,12 +70,12 @@ void StyleParser::parse(JSVal document) { parseLayout(iconOverlap, pointBucket); // create point annotations source & connect to bucket & layer - util::ptr pointAnnotationsSource = std::make_shared(); - sourcesMap.emplace(pointID, pointAnnotationsSource); - sources.emplace_back(pointAnnotationsSource); + std::unique_ptr pointAnnotationsSource = std::make_unique(); pointAnnotationsSource->info.type = SourceType::Annotations; pointAnnotationsSource->info.source_id = pointID; pointAnnotationsLayer->bucket = pointBucket; + sourcesMap.emplace(pointID, pointAnnotationsSource.get()); + sources.emplace_back(std::move(pointAnnotationsSource)); } if (document.HasMember("sprite")) { @@ -227,14 +227,14 @@ void StyleParser::parseSources(JSVal value) { rapidjson::Value::ConstMemberIterator itr = value.MemberBegin(); for (; itr != value.MemberEnd(); ++itr) { std::string name { itr->name.GetString(), itr->name.GetStringLength() }; - util::ptr source = std::make_shared(); + std::unique_ptr source = std::make_unique(); parseRenderProperty(itr->value, source->info.type, "type"); parseRenderProperty(itr->value, source->info.url, "url"); parseRenderProperty(itr->value, source->info.tile_size, "tileSize"); source->info.source_id = name; source->info.parseTileJSONProperties(itr->value); - sources.emplace_back(source); - sourcesMap.emplace(name, source); + sourcesMap.emplace(name, source.get()); + sources.emplace_back(std::move(source)); } } else { Log::Warning(Event::ParseStyle, "sources must be an object"); diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 0cbc3a136..2daa5e14d 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -35,8 +35,8 @@ public: void parse(JSVal document); - std::vector> getSources() { - return sources; + std::vector>&& getSources() { + return std::move(sources); } std::vector> getLayers() { @@ -103,10 +103,10 @@ private: private: std::unordered_map constants; - std::vector> sources; + std::vector> sources; std::vector> layers; - std::unordered_map> sourcesMap; + std::unordered_map sourcesMap; std::unordered_map>> layersMap; // Store a stack of layers we're parsing right now. This is to prevent reference cycles.