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.
This commit is contained in:
committed by
Konstantin Käfer
parent
41d619771e
commit
af63b4980d
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user