From c3940cf08251f9fc9bfce4911e7b24f5985ae105 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 20 Nov 2014 19:25:38 -0800 Subject: Eliminate Map::getFileSource --- src/map/map.cpp | 4 ++-- src/map/source.cpp | 16 ++++++++-------- src/map/tile_data.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/map/map.cpp b/src/map/map.cpp index 73867b2298..4ed1b6465d 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -607,7 +607,7 @@ void Map::updateSources() { if (style_source->enabled) { if (!style_source->source) { style_source->source = std::make_shared(style_source->info); - style_source->source->load(*this); + style_source->source->load(*this, *fileSource); } } else { style_source->source.reset(); @@ -642,7 +642,7 @@ void Map::updateSources(const util::ptr &group) { void Map::updateTiles() { for (const util::ptr &source : getActiveSources()) { - source->source->update(*this); + source->source->update(*this, *fileSource); } } diff --git a/src/map/source.cpp b/src/map/source.cpp index 9c0f7caf28..957afd6fd3 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -30,7 +30,7 @@ Source::Source(const util::ptr& info_) // Note: This is a separate function that must be called exactly once after creation // The reason this isn't part of the constructor is that calling shared_from_this() in // the constructor fails. -void Source::load(Map& map) { +void Source::load(Map& map, FileSource& fileSource) { if (info->url.empty()) { loaded = true; return; @@ -39,7 +39,7 @@ void Source::load(Map& map) { std::string url = util::mapbox::normalizeSourceURL(info->url, map.getAccessToken()); util::ptr source = shared_from_this(); - map.getFileSource()->request(ResourceType::JSON, url)->onload([source, &map](const Response &res) { + fileSource.request(ResourceType::JSON, url)->onload([source, &map](const Response &res) { if (res.code != 200) { Log::Warning(Event::General, "failed to load source TileJSON"); return; @@ -61,9 +61,9 @@ void Source::load(Map& map) { }); } -bool Source::update(Map &map) { +bool Source::update(Map& map, FileSource& fileSource) { if (loaded && map.getTime() > updated) { - return updateTiles(map); + return updateTiles(map, fileSource); } else { return false; } @@ -159,7 +159,7 @@ TileData::State Source::hasTile(const Tile::ID& id) { return TileData::State::invalid; } -TileData::State Source::addTile(Map &map, const Tile::ID& id) { +TileData::State Source::addTile(Map& map, FileSource& fileSource, const Tile::ID& id) { const TileData::State state = hasTile(id); if (state != TileData::State::invalid) { @@ -194,7 +194,7 @@ TileData::State Source::addTile(Map &map, const Tile::ID& id) { throw std::runtime_error("source type not implemented"); } - new_tile.data->request(); + new_tile.data->request(fileSource); tile_data.emplace(new_tile.data->id, new_tile.data); } @@ -281,7 +281,7 @@ bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std:: return false; } -bool Source::updateTiles(Map &map) { +bool Source::updateTiles(Map& map, FileSource& fileSource) { bool changed = false; int32_t zoom = std::floor(getZoom(map.getState())); @@ -298,7 +298,7 @@ bool Source::updateTiles(Map &map) { // Add existing child/parent tiles if the actual tile is not yet loaded for (const Tile::ID& id : required) { - const TileData::State state = addTile(map, id); + const TileData::State state = addTile(map, fileSource, id); if (state != TileData::State::parsed) { // The tile we require is not yet loaded. Try to find a parent or diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index 44628e8b3e..9ff694bf3a 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -28,7 +28,7 @@ const std::string TileData::toString() const { return util::sprintf<32>("[tile %d/%d/%d]", id.z, id.x, id.y); } -void TileData::request() { +void TileData::request(FileSource& fileSource) { if (source->tiles.empty()) return; @@ -45,7 +45,7 @@ void TileData::request() { // Note: Somehow this feels slower than the change to request_http() std::weak_ptr weak_tile = shared_from_this(); - req = map.getFileSource()->request(ResourceType::Tile, url); + req = fileSource.request(ResourceType::Tile, url); req->onload([weak_tile, url](const Response &res) { util::ptr tile = weak_tile.lock(); if (!tile || tile->state == State::obsolete) { -- cgit v1.2.1