use unique_ptrs and fix compile on mapnik

This commit is contained in:
Konstantin Käfer
2014-04-15 12:24:15 -07:00
parent 5792b04496
commit 0367dbe8c7
4 changed files with 44 additions and 38 deletions

View File

@@ -82,7 +82,7 @@ private:
GlyphAtlas glyphAtlas;
Painter painter;
std::map<std::string, Source> sources;
std::map<std::string, const std::unique_ptr<Source>> sources;
int32_t min_zoom;
int32_t max_zoom;

View File

@@ -3,10 +3,11 @@
#include <llmr/map/tile.hpp>
#include <llmr/map/tile_data.hpp>
#include <llmr/util/noncopyable.hpp>
#include <forward_list>
#include <memory>
#include <list>
#include <vector>
#include <string>
namespace llmr {
@@ -16,7 +17,7 @@ class Transform;
class Painter;
class Texturepool;
class Source : public std::enable_shared_from_this<Source> {
class Source : public std::enable_shared_from_this<Source>, private util::noncopyable {
public:
enum class Type {
vector,
@@ -24,7 +25,10 @@ public:
};
public:
Source(Map& map, Transform& transform, Painter& painter, Texturepool& texturepool, const char *url = "", Type type = Type::vector, std::list<uint32_t> zooms = {0}, uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 14, bool enabled = true);
Source(Map &map, Transform &transform, Painter &painter, Texturepool &texturepool,
const char *url = "", Type type = Type::vector, std::vector<uint32_t> zooms = {{0}},
uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 14,
bool enabled = true);
bool update();
void prepare_render(bool is_baselayer = false);
@@ -51,12 +55,12 @@ private:
Painter& painter;
Texturepool& texturepool;
Type type;
std::list<uint32_t> zooms;
const Type type;
const std::vector<uint32_t> zooms;
const std::string url;
uint32_t tile_size;
uint32_t min_zoom;
uint32_t max_zoom;
const uint32_t tile_size;
const uint32_t min_zoom;
const uint32_t max_zoom;
std::forward_list<Tile> tiles;
std::forward_list<std::weak_ptr<TileData>> tile_data;

View File

@@ -32,30 +32,30 @@ void Map::setup() {
style.loadJSON(resources::style, resources::style_size);
sources.emplace("mapbox streets",
Source(*this,
std::unique_ptr<Source>(new Source(*this,
transform,
painter,
texturepool,
"http://a.gl-api-us-east-1.tilestream.net/v3/mapbox.mapbox-streets-v4/%d/%d/%d.gl.pbf",
Source::Type::vector,
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14},
{{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }},
512,
0,
14,
true));
true)));
sources.emplace("satellite",
Source(*this,
std::unique_ptr<Source>(new Source(*this,
transform,
painter,
texturepool,
"https://a.tiles.mapbox.com/v3/justin.hh0gkdfm/%d/%d/%d%s.png256",
Source::Type::raster,
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21},
{{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 }},
256,
0,
21,
false));
false)));
}
void Map::loadStyle(const uint8_t *const data, uint32_t bytes) {
@@ -261,20 +261,21 @@ void Map::toggleDebug() {
void Map::toggleRaster() {
auto it = sources.find("satellite");
std::pair<std::string, Source&> pair = *it;
Source& satellite_source = pair.second;
if (it != sources.end()) {
Source &satellite_source = *it->second;
if (satellite_source.enabled) {
satellite_source.enabled = false;
style.appliedClasses.erase(style.appliedClasses.find("satellite"));
} else {
satellite_source.enabled = true;
style.appliedClasses.insert("satellite");
if (satellite_source.enabled) {
satellite_source.enabled = false;
style.appliedClasses.erase(style.appliedClasses.find("satellite"));
} else {
satellite_source.enabled = true;
style.appliedClasses.insert("satellite");
}
style.cascade(transform.getNormalizedZoom());
update();
}
style.cascade(transform.getNormalizedZoom());
update();
}
void Map::cancelAnimations() {
@@ -295,8 +296,8 @@ void Map::update() {
bool Map::updateTiles() {
bool changed = false;
for (std::pair<std::string, Source&> pair : sources) {
Source& source = pair.second;
for (auto &pair : sources) {
Source &source = *pair.second;
if (source.enabled) {
changed = source.update() || changed;
}
@@ -333,10 +334,10 @@ bool Map::render() {
bool is_baselayer = true;
for (std::pair<std::string, Source&> pair : sources) {
Source& source = pair.second;
for (auto &pair : sources) {
Source &source = *pair.second;
source.prepare_render(is_baselayer);
is_baselayer = source.enabled ? false : (true && is_baselayer);
is_baselayer = source.enabled ? false : (true && is_baselayer);
}
painter.finishClippingMask();
@@ -346,10 +347,10 @@ bool Map::render() {
is_baselayer = true;
for (std::pair<std::string, Source&> pair : sources) {
Source& source = pair.second;
for (auto &pair : sources) {
Source &source = *pair.second;
source.render(animationTime, is_baselayer);
is_baselayer = source.enabled ? false : (true && is_baselayer);
is_baselayer = source.enabled ? false : (true && is_baselayer);
}
painter.renderMatte();

View File

@@ -11,7 +11,9 @@
using namespace llmr;
Source::Source(Map& map, Transform& transform, Painter& painter, Texturepool& texturepool, const char *url, Source::Type type, std::list<uint32_t> zooms, uint32_t tile_size, uint32_t min_zoom, uint32_t max_zoom, bool enabled)
Source::Source(Map &map, Transform &transform, Painter &painter, Texturepool &texturepool,
const char *url, Source::Type type, std::vector<uint32_t> zooms, uint32_t tile_size,
uint32_t min_zoom, uint32_t max_zoom, bool enabled)
: enabled(enabled),
map(map),
transform(transform),
@@ -22,8 +24,7 @@ Source::Source(Map& map, Transform& transform, Painter& painter, Texturepool& te
url(url),
tile_size(tile_size),
min_zoom(min_zoom),
max_zoom(max_zoom) {
}
max_zoom(max_zoom) {}
bool Source::update() {
return updateTiles();