break out StyleSource from Source, move getActiveSources and updateSources into Map::Map

This commit is contained in:
Mike Morris
2014-07-10 16:29:49 -07:00
parent 1268fafe0b
commit 53e995acae
12 changed files with 88 additions and 55 deletions

View File

@@ -52,6 +52,7 @@ public:
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height);
// Styling
const std::set<std::shared_ptr<Source>> getActiveSources() const;
void setAppliedClasses(const std::vector<std::string> &classes);
void toggleClass(const std::string &name);
const std::vector<std::string> &getAppliedClasses() const;
@@ -121,6 +122,9 @@ private:
// Setup
void setup();
void updateSources();
void updateSources(const std::shared_ptr<StyleLayerGroup> &group);
void updateTiles();
void updateRenderState();
@@ -172,6 +176,8 @@ private:
int indent = 0;
std::set<std::shared_ptr<Source>> activeSources;
private:
bool async = false;
std::shared_ptr<uv::loop> loop;

View File

@@ -5,6 +5,7 @@
#include <llmr/map/tile_data.hpp>
#include <llmr/util/noncopyable.hpp>
#include <llmr/util/time.hpp>
#include <llmr/style/style_source.hpp>
#include <llmr/style/types.hpp>
#include <list>
@@ -22,6 +23,7 @@ class Texturepool;
class Source : public std::enable_shared_from_this<Source>, private util::noncopyable {
public:
Source(StyleSource style_source);
Source(SourceType type = SourceType::Vector, const std::string &url = "",
uint32_t tile_size = 512, uint32_t min_zoom = 0, uint32_t max_zoom = 22);

View File

@@ -2,6 +2,7 @@
#define LLMR_STYLE_STYLE
#include <llmr/style/property_transition.hpp>
#include <llmr/style/style_source.hpp>
#include <llmr/util/time.hpp>
#include <llmr/util/uv.hpp>
@@ -17,7 +18,6 @@
namespace llmr {
class Sprite;
class Source;
class StyleLayer;
class StyleLayerGroup;
struct BackgroundProperties;
@@ -36,8 +36,6 @@ public:
void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0);
const std::set<std::shared_ptr<Source>> getActiveSources() const;
void setAppliedClasses(const std::vector<std::string> &classes);
const std::vector<std::string> &getAppliedClasses() const;
void toggleClass(const std::string &name);
@@ -57,13 +55,8 @@ public:
std::string sprite_url;
std::string glyph_url;
private:
void updateSources();
void updateSources(const std::shared_ptr<StyleLayerGroup> &group);
private:
std::set<std::shared_ptr<Source>> activeSources;
PropertyTransition defaultTransition;
bool initial_render_complete = false;

View File

@@ -3,6 +3,7 @@
#include <llmr/style/types.hpp>
#include <llmr/style/filter_expression.hpp>
#include <llmr/style/style_source.hpp>
#include <llmr/util/vec.hpp>
#include <llmr/util/variant.hpp>
@@ -11,8 +12,6 @@
namespace llmr {
class Source;
class StyleBucketFill {
public:
WindingType winding = WindingType::Default;
@@ -74,7 +73,7 @@ public:
StyleBucket(StyleLayerType type);
std::string name;
std::shared_ptr<Source> source;
std::shared_ptr<StyleSource> style_source;
std::string source_layer;
FilterExpression filter;
StyleBucketRender render = std::false_type();

View File

@@ -3,7 +3,7 @@
#include <rapidjson/document.h>
#include <llmr/style/style.hpp>
#include <llmr/map/source.hpp>
#include <llmr/style/style_source.hpp>
#include <llmr/style/filter_expression.hpp>
#include <llmr/style/class_properties.hpp>
#include <llmr/style/rasterize_properties.hpp>
@@ -94,7 +94,7 @@ private:
private:
std::unordered_map<std::string, const rapidjson::Value *> constants;
std::unordered_map<std::string, const std::shared_ptr<Source>> sources;
std::unordered_map<std::string, const std::shared_ptr<StyleSource>> sources;
// This stores the root layer.
std::shared_ptr<StyleLayerGroup> root;

View File

@@ -0,0 +1,27 @@
#ifndef LLMR_STYLE_STYLE_SOURCE
#define LLMR_STYLE_STYLE_SOURCE
#include <llmr/style/types.hpp>
namespace llmr {
struct StyleSource {
const SourceType type;
const std::string url;
const uint32_t tile_size;
const int32_t min_zoom;
const int32_t max_zoom;
StyleSource(SourceType type = SourceType::Vector,
const std::string &url = "",
uint32_t tile_size = 512, uint32_t min_zoom = 0,
uint32_t max_zoom = 22)
: type(type),
url(url),
tile_size(tile_size),
min_zoom(min_zoom),
max_zoom(max_zoom) {};
};
};
#endif

View File

@@ -405,8 +405,33 @@ void Map::setDefaultTransitionDuration(uint64_t duration_milliseconds) {
style->setDefaultTransitionDuration(duration_milliseconds);
}
void Map::updateSources() {
activeSources.clear();
updateSources(style->layers);
}
const std::set<std::shared_ptr<Source>> Map::getActiveSources() const {
return activeSources;
}
void Map::updateSources(const std::shared_ptr<StyleLayerGroup> &group) {
if (!group) {
return;
}
for (const std::shared_ptr<StyleLayer> &layer : group->layers) {
if (!layer) continue;
if (layer->bucket) {
if (layer->bucket->style_source) {
activeSources.emplace(std::make_shared<Source>(*layer->bucket->style_source));
}
} else if (layer->layers) {
updateSources(layer->layers);
}
}
}
void Map::updateTiles() {
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
for (const std::shared_ptr<Source> &source : getActiveSources()) {
source->update(*this);
}
}
@@ -414,14 +439,14 @@ void Map::updateTiles() {
void Map::updateRenderState() {
std::forward_list<Tile::ID> ids;
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
for (const std::shared_ptr<Source> &source : getActiveSources()) {
ids.splice_after(ids.before_begin(), source->getIDs());
source->updateMatrices(painter.projMatrix, state);
}
const std::map<Tile::ID, ClipID> clipIDs = computeClipIDs(ids);
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
for (const std::shared_ptr<Source> &source : getActiveSources()) {
source->updateClipIDs(clipIDs);
}
}
@@ -465,6 +490,7 @@ void Map::prepare() {
}
animationTime = util::now();
updateSources();
style->updateProperties(state.getNormalizedZoom(), animationTime);
// Allow the sprite atlas to potentially pull new sprite images if needed.
@@ -489,7 +515,7 @@ void Map::render() {
updateRenderState();
painter.drawClippingMasks(style->getActiveSources());
painter.drawClippingMasks(getActiveSources());
// Actually render the layers
if (debug::renderTree) { std::cout << "{" << std::endl; indent++; }
@@ -500,7 +526,7 @@ void Map::render() {
// This guarantees that we have at least one function per tile called.
// When only rendering layers via the stylesheet, it's possible that we don't
// ever visit a tile during rendering.
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
for (const std::shared_ptr<Source> &source : getActiveSources()) {
source->finishRender(painter);
}
@@ -593,7 +619,7 @@ void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass) {
return;
}
if (!layer_desc->bucket->source) {
if (!layer_desc->bucket->style_source) {
fprintf(stderr, "[WARNING] can't find source for layer '%s'\n", layer_desc->id.c_str());
return;
}
@@ -629,6 +655,8 @@ void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass) {
<< layer_desc->type << ")" << std::endl;
}
layer_desc->bucket->source->render(painter, layer_desc);
// TODO: THIS IS BAD, FIXME
Source source(*layer_desc->bucket->style_source);
source.render(painter, layer_desc);
}
}

View File

@@ -18,6 +18,13 @@
namespace llmr {
Source::Source(StyleSource style_source)
: type(style_source.type),
url(normalizeSourceURL(style_source.url)),
tile_size(style_source.tile_size),
min_zoom(style_source.min_zoom),
max_zoom(style_source.max_zoom) {}
Source::Source(SourceType type, const std::string &url,
uint32_t tile_size, uint32_t min_zoom, uint32_t max_zoom)
: type(type),
@@ -33,8 +40,7 @@ std::string Source::normalizeSourceURL(const std::string &url) {
} else {
return url;
}
}
};
bool Source::update(Map &map) {
if (map.getTime() > updated) {

View File

@@ -108,7 +108,7 @@ void Painter::pushFramebuffer() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glColorMask(false, false, false, false);
drawClippingMasks(map.getStyle()->getActiveSources());
drawClippingMasks(map.getActiveSources());
glColorMask(true, true, true, true);
fbo_depth_stencil_valid = true;

View File

@@ -15,36 +15,9 @@ namespace llmr {
Style::Style() {
}
void Style::updateSources() {
activeSources.clear();
updateSources(layers);
}
const std::set<std::shared_ptr<Source>> Style::getActiveSources() const {
return activeSources;
}
void Style::updateSources(const std::shared_ptr<StyleLayerGroup> &group) {
if (!group) {
return;
}
for (const std::shared_ptr<StyleLayer> &layer : group->layers) {
if (!layer) continue;
if (layer->bucket) {
if (layer->bucket->source) {
activeSources.emplace(layer->bucket->source);
}
} else if (layer->layers) {
updateSources(layer->layers);
}
}
}
void Style::updateProperties(float z, timestamp now) {
uv::writelock lock(mtx);
updateSources();
if (layers) {
layers->updateProperties(z, now);
}

View File

@@ -1,6 +1,5 @@
#include <llmr/style/style_layer.hpp>
#include <llmr/style/style_bucket.hpp>
#include <llmr/map/source.hpp>
#include <llmr/style/style_layer_group.hpp>
#include <llmr/style/property_fallback.hpp>
@@ -251,8 +250,8 @@ void StyleLayer::updateProperties(float z, const timestamp now) {
}
// Accomodate for different tile size.
if (bucket && bucket->source) {
z += std::log(bucket->source->tile_size / 256.0f) / M_LN2;
if (bucket && bucket->style_source) {
z += std::log(bucket->style_source->tile_size / 256.0f) / M_LN2;
}
cleanupAppliedStyleProperties(now);

View File

@@ -169,7 +169,7 @@ void StyleParser::parseSources(JSVal value) {
parseRenderProperty(itr->value, min_zoom, "minZoom");
parseRenderProperty(itr->value, max_zoom, "maxZoom");
sources.emplace(std::move(name), std::make_shared<Source>(type, url, tile_size, min_zoom, max_zoom));
sources.emplace(std::move(name), std::make_shared<StyleSource>(type, url, tile_size, min_zoom, max_zoom));
}
} else {
throw Style::exception("sources must be an object");
@@ -731,7 +731,7 @@ void StyleParser::parseBucket(JSVal value, std::shared_ptr<StyleLayer> &layer) {
const std::string source_name = { value_source.GetString(), value_source.GetStringLength() };
auto source_it = sources.find(source_name);
if (source_it != sources.end()) {
layer->bucket->source = source_it->second;
layer->bucket->style_source = source_it->second;
} else {
fprintf(stderr, "[WARNING] can't find source '%s' required for layer '%s'\n",
source_name.c_str(), layer->id.c_str());