summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-07-01 17:48:09 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-07-02 10:12:04 -0700
commit117322d349d7ff9a1d0028b6f88dd7369027881f (patch)
tree29d9f95818655fffce0f685fa6d71ca7cdc23123 /src
parent1da2c3f840c83cab72a94c7af29bfc1da2f4d9bd (diff)
downloadqtlocation-mapboxgl-117322d349d7ff9a1d0028b6f88dd7369027881f.tar.gz
Don't inherit for code reuse
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/live_tile_data.cpp60
-rw-r--r--src/mbgl/map/live_tile_data.hpp22
-rw-r--r--src/mbgl/map/source.cpp9
-rw-r--r--src/mbgl/map/vector_tile_data.hpp14
4 files changed, 54 insertions, 51 deletions
diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp
index ad28c6c628..ad983343b1 100644
--- a/src/mbgl/map/live_tile_data.cpp
+++ b/src/mbgl/map/live_tile_data.cpp
@@ -1,49 +1,40 @@
#include <mbgl/map/annotation.hpp>
#include <mbgl/map/live_tile_data.hpp>
#include <mbgl/map/live_tile.hpp>
+#include <mbgl/style/style_layer.hpp>
+#include <mbgl/map/source.hpp>
+#include <mbgl/text/collision_tile.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/work_request.hpp>
+#include <mbgl/style/style.hpp>
#include <sstream>
using namespace mbgl;
LiveTileData::LiveTileData(const TileID& id_,
- AnnotationManager& annotationManager_,
+ const LiveTile* tile,
Style& style_,
const SourceInfo& source_,
- float angle_,
- bool collisionDebug_)
- : VectorTileData(id_, style_, source_, angle_, collisionDebug_),
- annotationManager(annotationManager_) {
- // live features are always loaded
+ std::function<void()> callback)
+ : TileData(id_),
+ worker(style_.workers),
+ tileWorker(id_,
+ style_,
+ style_.layers,
+ source_.max_zoom,
+ state,
+ std::make_unique<CollisionTile>(id_.z, 4096,
+ source_.tile_size * id.overscaling,
+ 0, false)) {
state = State::loaded;
-}
-
-LiveTileData::~LiveTileData() {
- cancel();
-}
-bool LiveTileData::reparse(std::function<void()> callback) {
- if (parsing || (state != State::loaded && state != State::partial)) {
- return false;
- }
-
- const LiveTile* tile = annotationManager.getTile(id);
if (!tile) {
state = State::parsed;
- return true;
+ return;
}
- parsing = true;
-
workRequest = worker.parseLiveTile(tileWorker, *tile, [this, callback] (TileParseResult result) {
- parsing = false;
-
- if (state == State::obsolete) {
- return;
- }
-
if (result.is<State>()) {
state = result.get<State>();
} else {
@@ -53,6 +44,21 @@ bool LiveTileData::reparse(std::function<void()> callback) {
callback();
});
+}
+
+LiveTileData::~LiveTileData() {
+ cancel();
+}
+
+Bucket* LiveTileData::getBucket(const StyleLayer& layer) {
+ if (!isReady() || !layer.bucket) {
+ return nullptr;
+ }
+
+ return tileWorker.getBucket(layer);
+}
- return true;
+void LiveTileData::cancel() {
+ state = State::obsolete;
+ workRequest.reset();
}
diff --git a/src/mbgl/map/live_tile_data.hpp b/src/mbgl/map/live_tile_data.hpp
index 2d6b010614..5c4220fd67 100644
--- a/src/mbgl/map/live_tile_data.hpp
+++ b/src/mbgl/map/live_tile_data.hpp
@@ -1,26 +1,32 @@
#ifndef MBGL_MAP_LIVE_TILE_DATA
#define MBGL_MAP_LIVE_TILE_DATA
-#include <mbgl/map/vector_tile_data.hpp>
+#include <mbgl/map/tile_data.hpp>
+#include <mbgl/map/tile_worker.hpp>
namespace mbgl {
-class AnnotationManager;
+class Style;
+class SourceInfo;
+class WorkRequest;
+class LiveTile;
-class LiveTileData : public VectorTileData {
+class LiveTileData : public TileData {
public:
LiveTileData(const TileID&,
- AnnotationManager&,
+ const LiveTile*,
Style&,
const SourceInfo&,
- float angle_,
- bool collisionDebug_);
+ std::function<void ()> callback);
~LiveTileData();
- bool reparse(std::function<void ()> callback) override;
+ void cancel() override;
+ Bucket* getBucket(const StyleLayer&) override;
private:
- AnnotationManager& annotationManager;
+ Worker& worker;
+ TileWorker tileWorker;
+ std::unique_ptr<WorkRequest> workRequest;
};
}
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 7b6a35ed2a..f596296fc3 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -235,7 +235,7 @@ bool Source::handlePartialTile(const TileID& id, Worker&) {
// Note: this uses a raw pointer; we don't want the callback binding to have a
// shared pointer.
- VectorTileData* data = static_cast<VectorTileData*>(it->second.lock().get());
+ VectorTileData* data = dynamic_cast<VectorTileData*>(it->second.lock().get());
if (!data) {
return true;
}
@@ -299,11 +299,8 @@ TileData::State Source::addTile(MapData& data,
tileData->request(transformState.getPixelRatio(), callback);
new_tile.data = tileData;
} else if (info.type == SourceType::Annotations) {
- auto tileData = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
- style, info,
- transformState.getAngle(), data.getCollisionDebug());
- tileData->reparse(callback);
- new_tile.data = tileData;
+ new_tile.data = std::make_shared<LiveTileData>(normalized_id,
+ data.annotationManager.getTile(normalized_id), style, info, callback);
} else {
throw std::runtime_error("source type not implemented");
}
diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp
index b0b5ec6e89..3b73ded0ca 100644
--- a/src/mbgl/map/vector_tile_data.hpp
+++ b/src/mbgl/map/vector_tile_data.hpp
@@ -8,13 +8,10 @@
namespace mbgl {
-class SourceInfo;
-class Request;
-class Bucket;
-class SourceInfo;
-class StyleLayer;
class Style;
+class SourceInfo;
class WorkRequest;
+class Request;
class VectorTileData : public TileData {
public:
@@ -31,23 +28,20 @@ public:
void request(float pixelRatio,
const std::function<void()>& callback);
- virtual bool reparse(std::function<void ()> callback);
+ bool reparse(std::function<void ()> callback);
void redoPlacement(float angle, bool collisionDebug) override;
void cancel() override;
-protected:
+private:
Worker& worker;
TileWorker tileWorker;
std::unique_ptr<WorkRequest> workRequest;
bool parsing = false;
-
-private:
const SourceInfo& source;
Request* req = nullptr;
std::string data;
-
float lastAngle = 0;
float currentAngle;
bool lastCollisionDebug = 0;