summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-05-12 19:42:05 +0300
committerKonstantin Käfer <mail@kkaefer.com>2015-05-13 09:58:29 +0200
commitaf63b4980d45e40d0cc5302b0f85475be5c1f90e (patch)
tree890469c410b16807d42cbafa7ec8243031501282 /src
parent41d619771e4e0c77c3112f13febeacff9003209e (diff)
downloadqtlocation-mapboxgl-af63b4980d45e40d0cc5302b0f85475be5c1f90e.tar.gz
Move the Collision object from TileParser to VectorTileData
We keep the Collision object alive longer because we need it for the SymbolBuckets yet to be created in case more data resources arrive. When the tile is no longer needed or if it is completely parsed or obsolete (i.e. in a immutable state) we throw the Collision object away.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/tile_parser.cpp5
-rw-r--r--src/mbgl/map/tile_parser.hpp2
-rw-r--r--src/mbgl/map/vector_tile_data.cpp12
-rw-r--r--src/mbgl/map/vector_tile_data.hpp12
4 files changed, 22 insertions, 9 deletions
diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp
index 201e6187ae..86517da420 100644
--- a/src/mbgl/map/tile_parser.cpp
+++ b/src/mbgl/map/tile_parser.cpp
@@ -8,7 +8,6 @@
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/util/constants.hpp>
-#include <mbgl/text/collision.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/style/style.hpp>
@@ -35,10 +34,8 @@ TileParser::TileParser(const GeometryTile& geometryTile_,
glyphStore(glyphStore_),
spriteAtlas(spriteAtlas_),
sprite(sprite_),
- collision(util::make_unique<Collision>(tile.id.z, 4096, tile.source.tile_size, tile.depth)),
partialParse(false) {
assert(sprite);
- assert(collision);
}
bool TileParser::obsolete() const {
@@ -196,7 +193,7 @@ std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer&
return nullptr;
}
- auto bucket = util::make_unique<SymbolBucket>(*collision);
+ auto bucket = util::make_unique<SymbolBucket>(*tile.getCollision());
const float z = tile.id.z;
auto& layout = bucket->layout;
diff --git a/src/mbgl/map/tile_parser.hpp b/src/mbgl/map/tile_parser.hpp
index 18184e27a3..67150bcd4d 100644
--- a/src/mbgl/map/tile_parser.hpp
+++ b/src/mbgl/map/tile_parser.hpp
@@ -29,7 +29,6 @@ class StyleLayoutRaster;
class StyleLayoutLine;
class StyleLayoutSymbol;
class VectorTileData;
-class Collision;
class TileParser : private util::noncopyable {
public:
@@ -69,7 +68,6 @@ private:
SpriteAtlas& spriteAtlas;
util::ptr<Sprite> sprite;
- std::unique_ptr<Collision> collision;
bool partialParse;
};
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp
index 8f5138b582..263ad52b9d 100644
--- a/src/mbgl/map/vector_tile_data.cpp
+++ b/src/mbgl/map/vector_tile_data.cpp
@@ -6,6 +6,7 @@
#include <mbgl/map/source.hpp>
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/platform/log.hpp>
+#include <mbgl/text/collision.hpp>
#include <mbgl/util/pbf.hpp>
using namespace mbgl;
@@ -19,12 +20,13 @@ VectorTileData::VectorTileData(const TileID& id_,
util::ptr<Sprite> sprite_,
const SourceInfo& source_)
: TileData(id_, source_),
+ depth(id_.z >= source_.max_zoom ? mapMaxZoom - id_.z : 1),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),
spriteAtlas(spriteAtlas_),
sprite(sprite_),
style(style_),
- depth(id.z >= source.max_zoom ? mapMaxZoom - id.z : 1) {
+ collision(util::make_unique<Collision>(id_.z, 4096, source_.tile_size, depth)) {
}
VectorTileData::~VectorTileData() {
@@ -91,3 +93,11 @@ void VectorTileData::setBucket(StyleLayer const& layer, std::unique_ptr<Bucket>
buckets[layer.bucket->name] = std::move(bucket);
}
+
+void VectorTileData::setState(const State& state_) {
+ TileData::setState(state_);
+
+ if (isImmutable()) {
+ collision.reset();
+ }
+}
diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp
index 146bc93229..5fe351ca0c 100644
--- a/src/mbgl/map/vector_tile_data.hpp
+++ b/src/mbgl/map/vector_tile_data.hpp
@@ -16,6 +16,7 @@
namespace mbgl {
class Bucket;
+class Collision;
class Painter;
class SourceInfo;
class StyleLayer;
@@ -45,6 +46,14 @@ public:
void setBucket(StyleLayer const &layer_desc, std::unique_ptr<Bucket> bucket);
+ void setState(const State& state) override;
+
+ inline Collision* getCollision() const {
+ return collision.get();
+ }
+
+ const float depth;
+
protected:
// Holds the actual geometries in this tile.
FillVertexBuffer fillVertexBuffer;
@@ -69,8 +78,7 @@ private:
std::unordered_map<std::string, std::unique_ptr<Bucket>> buckets;
mutable std::mutex bucketsMutex;
-public:
- const float depth;
+ std::unique_ptr<Collision> collision;
};
}