Eliminate remaining uses of Map in TileData

This commit is contained in:
John Firebaugh
2014-11-25 16:35:27 -08:00
parent 9af3b033bf
commit 23b61f808c
10 changed files with 44 additions and 41 deletions

View File

@@ -7,7 +7,6 @@
namespace mbgl {
class Map;
class Painter;
class SourceInfo;
class StyleLayer;
@@ -17,7 +16,7 @@ class RasterTileData : public TileData {
friend class TileParser;
public:
RasterTileData(Tile::ID const& id, Map &map, Texturepool&, const util::ptr<SourceInfo> &source);
RasterTileData(Tile::ID const& id, Texturepool&, const util::ptr<SourceInfo> &source);
~RasterTileData();
virtual void parse();

View File

@@ -39,7 +39,8 @@ public:
util::ptr<Style>,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&, util::ptr<Sprite>,
Texturepool&, FileSource&);
Texturepool&, FileSource&,
std::function<void ()> callback);
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
void drawClippingMasks(Painter &painter);
@@ -62,14 +63,16 @@ private:
util::ptr<Style>,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&, util::ptr<Sprite>,
Texturepool&, FileSource&);
Texturepool&, FileSource&,
std::function<void ()> callback);
TileData::State addTile(Map&, uv::worker&,
util::ptr<Style>,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&, util::ptr<Sprite>,
FileSource&, Texturepool&,
const Tile::ID&);
const Tile::ID&,
std::function<void ()> callback);
TileData::State hasTile(const Tile::ID& id);

View File

@@ -12,6 +12,7 @@
#include <exception>
#include <iosfwd>
#include <string>
#include <functional>
namespace uv {
class worker;
@@ -45,11 +46,11 @@ public:
};
public:
TileData(Tile::ID const& id, Map &map, const util::ptr<SourceInfo> &source);
TileData(Tile::ID const& id, const util::ptr<SourceInfo> &source);
~TileData();
void request(uv::worker&, FileSource&);
void reparse(uv::worker&);
void request(uv::worker&, FileSource&, float pixelRatio, std::function<void ()> callback);
void reparse(uv::worker&, std::function<void ()> callback);
void cancel();
const std::string toString() const;
@@ -67,9 +68,6 @@ public:
const Tile::ID id;
std::atomic<State> state;
protected:
Map &map;
public:
util::ptr<SourceInfo> source;

View File

@@ -16,7 +16,6 @@
namespace mbgl {
class Bucket;
class Map;
class Painter;
class SourceInfo;
class StyleLayer;
@@ -32,8 +31,8 @@ class VectorTileData : public TileData {
friend class TileParser;
public:
VectorTileData(Tile::ID const&, Map&,
util::ptr<Style>,
VectorTileData(Tile::ID const&,
float mapMaxZoom, util::ptr<Style>,
GlyphAtlas&, GlyphStore&,
SpriteAtlas&, util::ptr<Sprite>,
Texturepool&,

View File

@@ -144,8 +144,8 @@ private:
template <typename T>
class work {
public:
typedef void (*work_callback)(T &object);
typedef void (*after_work_callback)(T &object);
typedef std::function<void (T&)> work_callback;
typedef std::function<void (T&)> after_work_callback;
template<typename... Args>
work(worker &worker, work_callback work_cb_, after_work_callback after_work_cb_, Args&&... args)

View File

@@ -645,7 +645,7 @@ void Map::updateTiles() {
source->source->update(*this, getWorker(),
style, glyphAtlas, *glyphStore,
spriteAtlas, getSprite(),
*texturepool, *fileSource);
*texturepool, *fileSource, [this](){ update(); });
}
}

View File

@@ -5,8 +5,8 @@
using namespace mbgl;
RasterTileData::RasterTileData(Tile::ID const& id_, Map &map_, Texturepool& texturepool, const util::ptr<SourceInfo> &source_)
: TileData(id_, map_, source_),
RasterTileData::RasterTileData(Tile::ID const& id_, Texturepool& texturepool, const util::ptr<SourceInfo> &source_)
: TileData(id_, source_),
bucket(texturepool, properties) {
}

View File

@@ -65,12 +65,14 @@ bool Source::update(Map& map, uv::worker& worker,
util::ptr<Style> style,
GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite,
Texturepool& texturepool, FileSource& fileSource) {
Texturepool& texturepool, FileSource& fileSource,
std::function<void ()> callback) {
if (loaded && map.getTime() > updated) {
return updateTiles(map, worker, style,
glyphAtlas, glyphStore,
spriteAtlas, sprite,
texturepool, fileSource);
texturepool, fileSource,
callback);
} else {
return false;
}
@@ -171,7 +173,8 @@ TileData::State Source::addTile(Map& map, uv::worker& worker,
GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite,
FileSource& fileSource, Texturepool& texturepool,
const Tile::ID& id) {
const Tile::ID& id,
std::function<void ()> callback) {
const TileData::State state = hasTile(id);
if (state != TileData::State::invalid) {
@@ -199,17 +202,17 @@ 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) {
new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, style,
new_tile.data = std::make_shared<VectorTileData>(normalized_id, map.getMaxZoom(), style,
glyphAtlas, glyphStore,
spriteAtlas, sprite,
texturepool, info);
} else if (info->type == SourceType::Raster) {
new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, texturepool, info);
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturepool, info);
} else {
throw std::runtime_error("source type not implemented");
}
new_tile.data->request(worker, fileSource);
new_tile.data->request(worker, fileSource, map.getState().getPixelRatio(), callback);
tile_data.emplace(new_tile.data->id, new_tile.data);
}
@@ -299,7 +302,8 @@ bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::
bool Source::updateTiles(Map& map, uv::worker& worker, util::ptr<Style> style,
GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite,
Texturepool& texturepool, FileSource& fileSource) {
Texturepool& texturepool, FileSource& fileSource,
std::function<void ()> callback) {
bool changed = false;
int32_t zoom = std::floor(getZoom(map.getState()));
@@ -320,7 +324,7 @@ bool Source::updateTiles(Map& map, uv::worker& worker, util::ptr<Style> style,
glyphAtlas, glyphStore,
spriteAtlas, sprite,
fileSource, texturepool,
id);
id, callback);
if (state != TileData::State::parsed) {
// The tile we require is not yet loaded. Try to find a parent or

View File

@@ -9,10 +9,9 @@
using namespace mbgl;
TileData::TileData(Tile::ID const& id_, Map &map_, const util::ptr<SourceInfo> &source_)
TileData::TileData(Tile::ID const& id_, const util::ptr<SourceInfo> &source_)
: id(id_),
state(State::initial),
map(map_),
source(source_),
debugBucket(debugFontBuffer) {
// Initialize tile debug coordinates
@@ -28,7 +27,8 @@ const std::string TileData::toString() const {
return util::sprintf<32>("[tile %d/%d/%d]", id.z, id.x, id.y);
}
void TileData::request(uv::worker& worker, FileSource& fileSource) {
void TileData::request(uv::worker& worker, FileSource& fileSource,
float pixelRatio, std::function<void ()> callback) {
if (source->tiles.empty())
return;
@@ -43,7 +43,7 @@ void TileData::request(uv::worker& worker, FileSource& fileSource) {
prefix[1] = "0123456789abcdef"[id.y % 16];
return prefix;
}
if (token == "ratio") return (map.getState().getPixelRatio() > 1.0 ? "@2x" : "");
if (token == "ratio") return pixelRatio > 1.0 ? "@2x" : "";
return "";
});
@@ -52,7 +52,7 @@ void TileData::request(uv::worker& worker, FileSource& fileSource) {
// Note: Somehow this feels slower than the change to request_http()
std::weak_ptr<TileData> weak_tile = shared_from_this();
req = fileSource.request(ResourceType::Tile, url);
req->onload([weak_tile, url, &worker](const Response &res) {
req->onload([weak_tile, url, callback, &worker](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
@@ -69,7 +69,7 @@ void TileData::request(uv::worker& worker, FileSource& fileSource) {
tile->data = res.data;
// Schedule tile parsing in another thread
tile->reparse(worker);
tile->reparse(worker, callback);
} else {
#if defined(DEBUG)
fprintf(stderr, "[%s] tile loading failed: %ld, %s\n", url.c_str(), res.code, res.message.c_str());
@@ -88,17 +88,17 @@ void TileData::cancel() {
}
}
void TileData::reparse(uv::worker& worker)
void TileData::reparse(uv::worker& worker, std::function<void()> callback)
{
// We're creating a new work request. The work request deletes itself after it executed
// the after work handler
new uv::work<util::ptr<TileData>>(
worker,
[](util::ptr<TileData> &tile) {
[](util::ptr<TileData>& tile) {
tile->parse();
},
[](util::ptr<TileData> &tile) {
tile->map.update();
[callback](util::ptr<TileData>&) {
callback();
},
shared_from_this());
}

View File

@@ -8,20 +8,20 @@
using namespace mbgl;
VectorTileData::VectorTileData(Tile::ID const& id_, Map &map_,
util::ptr<Style> style_,
VectorTileData::VectorTileData(Tile::ID const& id_,
float mapMaxZoom, util::ptr<Style> style_,
GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_,
SpriteAtlas& spriteAtlas_, util::ptr<Sprite> sprite_,
Texturepool& texturepool_,
const util::ptr<SourceInfo> &source_)
: TileData(id_, map_, source_),
: TileData(id_, source_),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),
spriteAtlas(spriteAtlas_),
sprite(sprite_),
texturepool(texturepool_),
style(style_),
depth(id.z >= source->max_zoom ? map.getMaxZoom() - id.z : 1) {
depth(id.z >= source->max_zoom ? mapMaxZoom - id.z : 1) {
}
VectorTileData::~VectorTileData() {