From 41e90b4150ba8302c0c6f9bec0f53059483fea9e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 25 Nov 2014 17:50:19 -0800 Subject: [PATCH] Pass SourceInfo as reference --- include/mbgl/map/raster_tile_data.hpp | 2 +- include/mbgl/map/source.hpp | 4 ++-- include/mbgl/map/tile_data.hpp | 4 ++-- include/mbgl/map/vector_tile_data.hpp | 2 +- src/map/map.cpp | 2 +- src/map/raster_tile_data.cpp | 2 +- src/map/source.cpp | 22 +++++++++++----------- src/map/tile_data.cpp | 6 +++--- src/map/tile_parser.cpp | 4 ++-- src/map/vector_tile_data.cpp | 4 ++-- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/mbgl/map/raster_tile_data.hpp b/include/mbgl/map/raster_tile_data.hpp index c3bd2fbe3..cbbd864aa 100644 --- a/include/mbgl/map/raster_tile_data.hpp +++ b/include/mbgl/map/raster_tile_data.hpp @@ -16,7 +16,7 @@ class RasterTileData : public TileData { friend class TileParser; public: - RasterTileData(Tile::ID const& id, Texturepool&, const util::ptr &source); + RasterTileData(Tile::ID const& id, Texturepool&, const SourceInfo&); ~RasterTileData(); virtual void parse(); diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp index 635623879..299c7acca 100644 --- a/include/mbgl/map/source.hpp +++ b/include/mbgl/map/source.hpp @@ -32,7 +32,7 @@ struct box; class Source : public std::enable_shared_from_this, private util::noncopyable { public: - Source(const util::ptr& info); + Source(SourceInfo&); void load(Map&, FileSource&); bool update(Map&, uv::worker&, @@ -78,7 +78,7 @@ private: double getZoom(const TransformState &state) const; - util::ptr info; + SourceInfo& info; bool loaded = false; // Stores the time when this source was most recently updated. diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index 7fbb5d506..c8a13b83d 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -46,7 +46,7 @@ public: }; public: - TileData(Tile::ID const& id, const util::ptr &source); + TileData(Tile::ID const& id, const SourceInfo&); ~TileData(); void request(uv::worker&, FileSource&, float pixelRatio, std::function callback); @@ -69,7 +69,7 @@ public: std::atomic state; public: - util::ptr source; + const SourceInfo& source; protected: std::unique_ptr req; diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index 53dbb7eeb..0a0569f2e 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -36,7 +36,7 @@ public: GlyphAtlas&, GlyphStore&, SpriteAtlas&, util::ptr, Texturepool&, - const util::ptr&); + const SourceInfo&); ~VectorTileData(); virtual void parse(); diff --git a/src/map/map.cpp b/src/map/map.cpp index eb0a48d8d..2df3e068f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -606,7 +606,7 @@ void Map::updateSources() { for (const util::ptr &style_source : activeSources) { if (style_source->enabled) { if (!style_source->source) { - style_source->source = std::make_shared(style_source->info); + style_source->source = std::make_shared(*style_source->info); style_source->source->load(*this, *fileSource); } } else { diff --git a/src/map/raster_tile_data.cpp b/src/map/raster_tile_data.cpp index b2d0cf6a6..8b29fedcd 100644 --- a/src/map/raster_tile_data.cpp +++ b/src/map/raster_tile_data.cpp @@ -5,7 +5,7 @@ using namespace mbgl; -RasterTileData::RasterTileData(Tile::ID const& id_, Texturepool& texturepool, const util::ptr &source_) +RasterTileData::RasterTileData(Tile::ID const& id_, Texturepool& texturepool, const SourceInfo& source_) : TileData(id_, source_), bucket(texturepool, properties) { } diff --git a/src/map/source.cpp b/src/map/source.cpp index d617d2cde..5b32cbafb 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -22,7 +22,7 @@ namespace mbgl { -Source::Source(const util::ptr& info_) +Source::Source(SourceInfo& info_) : info(info_) { } @@ -31,12 +31,12 @@ Source::Source(const util::ptr& info_) // The reason this isn't part of the constructor is that calling shared_from_this() in // the constructor fails. void Source::load(Map& map, FileSource& fileSource) { - if (info->url.empty()) { + if (info.url.empty()) { loaded = true; return; } - std::string url = util::mapbox::normalizeSourceURL(info->url, map.getAccessToken()); + std::string url = util::mapbox::normalizeSourceURL(info.url, map.getAccessToken()); util::ptr source = shared_from_this(); fileSource.request(ResourceType::JSON, url)->onload([source, &map](const Response &res) { @@ -53,7 +53,7 @@ void Source::load(Map& map, FileSource& fileSource) { return; } - source->info->parseTileJSONProperties(d); + source->info.parseTileJSONProperties(d); source->loaded = true; map.update(); @@ -201,12 +201,12 @@ TileData::State Source::addTile(Map& map, uv::worker& worker, if (!new_tile.data) { // If we don't find working tile data, we're just going to load it. - if (info->type == SourceType::Vector) { + if (info.type == SourceType::Vector) { new_tile.data = std::make_shared(normalized_id, map.getMaxZoom(), style, glyphAtlas, glyphStore, spriteAtlas, sprite, texturepool, info); - } else if (info->type == SourceType::Raster) { + } else if (info.type == SourceType::Raster) { new_tile.data = std::make_shared(normalized_id, texturepool, info); } else { throw std::runtime_error("source type not implemented"); @@ -220,7 +220,7 @@ TileData::State Source::addTile(Map& map, uv::worker& worker, } double Source::getZoom(const TransformState& state) const { - double offset = std::log(util::tileSize / info->tile_size) / std::log(2); + double offset = std::log(util::tileSize / info.tile_size) / std::log(2); offset += (state.getPixelRatio() > 1.0 ? 1 :0); return state.getZoom() + offset; } @@ -232,8 +232,8 @@ int32_t Source::coveringZoomLevel(const TransformState& state) const { std::forward_list Source::coveringTiles(const TransformState& state) const { int32_t z = coveringZoomLevel(state); - if (z < info->min_zoom) return {{}}; - if (z > info->max_zoom) z = info->max_zoom; + if (z < info.min_zoom) return {{}}; + if (z > info.max_zoom) z = info.max_zoom; // Map four viewport corners to pixel coordinates box points = state.cornersToBox(z); @@ -310,8 +310,8 @@ bool Source::updateTiles(Map& map, uv::worker& worker, util::ptr