Eliminate Map::getFileSource
This commit is contained in:
@@ -126,7 +126,6 @@ public:
|
||||
|
||||
public:
|
||||
inline const TransformState &getState() const { return state; }
|
||||
inline util::ptr<FileSource> getFileSource() const { return fileSource; }
|
||||
inline util::ptr<Style> getStyle() const { return style; }
|
||||
inline GlyphAtlas & getGlyphAtlas() { return glyphAtlas; }
|
||||
inline util::ptr<GlyphStore> getGlyphStore() { return glyphStore; }
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
class FileSource;
|
||||
class Painter;
|
||||
class StyleLayer;
|
||||
class TransformState;
|
||||
@@ -27,9 +28,9 @@ class Source : public std::enable_shared_from_this<Source>, private util::noncop
|
||||
public:
|
||||
Source(const util::ptr<SourceInfo>& info);
|
||||
|
||||
void load(Map &map);
|
||||
void load(Map&, FileSource&);
|
||||
bool update(Map&, FileSource&);
|
||||
|
||||
bool update(Map &map);
|
||||
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
|
||||
void drawClippingMasks(Painter &painter);
|
||||
size_t getTileCount() const;
|
||||
@@ -47,9 +48,9 @@ private:
|
||||
int32_t coveringZoomLevel(const TransformState&) const;
|
||||
std::forward_list<Tile::ID> coveringTiles(const TransformState&) const;
|
||||
|
||||
bool updateTiles(Map &map);
|
||||
bool updateTiles(Map&, FileSource&);
|
||||
|
||||
TileData::State addTile(Map &map, const Tile::ID& id);
|
||||
TileData::State addTile(Map&, FileSource&, const Tile::ID&);
|
||||
TileData::State hasTile(const Tile::ID& id);
|
||||
|
||||
double getZoom(const TransformState &state) const;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
class Map;
|
||||
class FileSource;
|
||||
class Painter;
|
||||
class SourceInfo;
|
||||
class StyleLayer;
|
||||
@@ -43,7 +44,7 @@ public:
|
||||
TileData(Tile::ID const& id, Map &map, const util::ptr<SourceInfo> &source);
|
||||
~TileData();
|
||||
|
||||
void request();
|
||||
void request(FileSource&);
|
||||
void cancel();
|
||||
void reparse();
|
||||
const std::string toString() const;
|
||||
|
||||
@@ -607,7 +607,7 @@ void Map::updateSources() {
|
||||
if (style_source->enabled) {
|
||||
if (!style_source->source) {
|
||||
style_source->source = std::make_shared<Source>(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<StyleLayerGroup> &group) {
|
||||
|
||||
void Map::updateTiles() {
|
||||
for (const util::ptr<StyleSource> &source : getActiveSources()) {
|
||||
source->source->update(*this);
|
||||
source->source->update(*this, *fileSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Source::Source(const util::ptr<SourceInfo>& 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> 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
|
||||
|
||||
@@ -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<TileData> 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<TileData> tile = weak_tile.lock();
|
||||
if (!tile || tile->state == State::obsolete) {
|
||||
|
||||
Reference in New Issue
Block a user