From 0367dbe8c794d6eaff9f71083f52fbc3e3098405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 15 Apr 2014 12:24:15 -0700 Subject: [PATCH] use unique_ptrs and fix compile on mapnik --- include/llmr/map/map.hpp | 2 +- include/llmr/map/source.hpp | 20 ++++++++------ src/map/map.cpp | 53 +++++++++++++++++++------------------ src/map/source.cpp | 7 ++--- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index fef367386..cb5cad58e 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -82,7 +82,7 @@ private: GlyphAtlas glyphAtlas; Painter painter; - std::map sources; + std::map> sources; int32_t min_zoom; int32_t max_zoom; diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index 8af66ff57..7fa462ac3 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -3,10 +3,11 @@ #include #include +#include #include #include -#include +#include #include namespace llmr { @@ -16,7 +17,7 @@ class Transform; class Painter; class Texturepool; -class Source : public std::enable_shared_from_this { +class Source : public std::enable_shared_from_this, 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 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 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 zooms; + const Type type; + const std::vector 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 tiles; std::forward_list> tile_data; diff --git a/src/map/map.cpp b/src/map/map.cpp index 48d3df041..69a605476 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -32,30 +32,30 @@ void Map::setup() { style.loadJSON(resources::style, resources::style_size); sources.emplace("mapbox streets", - Source(*this, + std::unique_ptr(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(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 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 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 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 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(); diff --git a/src/map/source.cpp b/src/map/source.cpp index 437e322c5..a6e610a40 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -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 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 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();