diff options
Diffstat (limited to 'src/map/tile_data.cpp')
-rw-r--r-- | src/map/tile_data.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index 57afb8dadb..44e3826bf5 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -4,12 +4,12 @@ #include <mbgl/util/token.hpp> #include <mbgl/util/string.hpp> -#include <mbgl/util/filesource.hpp> +#include <mbgl/storage/file_source.hpp> #include <mbgl/util/uv_detail.hpp> using namespace mbgl; -TileData::TileData(Tile::ID id, Map &map, const SourceInfo &source) +TileData::TileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source) : id(id), state(State::initial), map(map), @@ -29,10 +29,10 @@ const std::string TileData::toString() const { } void TileData::request() { - if (source.tiles.empty()) + if (source->tiles.empty()) return; - std::string url = source.tiles[(id.x + id.y) % source.tiles.size()]; + std::string url = source->tiles[(id.x + id.y) % source->tiles.size()]; url = util::replaceTokens(url, [&](const std::string &token) -> std::string { if (token == "z") return std::to_string(id.z); if (token == "x") return std::to_string(id.x); @@ -45,21 +45,28 @@ void TileData::request() { // Note: Somehow this feels slower than the change to request_http() std::weak_ptr<TileData> weak_tile = shared_from_this(); - map.getFileSource()->load(ResourceType::Tile, url, [weak_tile, url](platform::Response *res) { - std::shared_ptr<TileData> tile = weak_tile.lock(); + req = map.getFileSource()->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) { // noop. Tile is obsolete and we're now just waiting for the refcount // to drop to zero for destruction. - } else if (res->code == 200) { + return; + } + + // Clear the request object. + tile->req.reset(); + + if (res.code == 200) { tile->state = State::loaded; - tile->data.swap(res->body); + tile->data = res.data; // Schedule tile parsing in another thread tile->reparse(); } else { #if defined(DEBUG) - fprintf(stderr, "[%s] tile loading failed: %d, %s\n", url.c_str(), res->code, res->error_message.c_str()); + fprintf(stderr, "[%s] tile loading failed: %ld, %s\n", url.c_str(), res.code, res.message.c_str()); #endif } }); @@ -68,7 +75,7 @@ void TileData::request() { void TileData::cancel() { if (state != State::obsolete) { state = State::obsolete; - platform::cancel_request_http(req.lock()); + req.reset(); } } @@ -79,12 +86,12 @@ void TileData::reparse() { // We're creating a new work request. The work request deletes itself after it executed // the after work handler - new uv::work<std::shared_ptr<TileData>>( - map.getLoop(), - [](std::shared_ptr<TileData> &tile) { + new uv::work<util::ptr<TileData>>( + map.getWorker(), + [](util::ptr<TileData> &tile) { tile->parse(); }, - [](std::shared_ptr<TileData> &tile) { + [](util::ptr<TileData> &tile) { tile->afterParse(); tile->map.update(); }, |