From a9b20fc09a51d62d471d8234387d07a838b4ca76 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Nov 2014 12:50:34 -0800 Subject: [PATCH 1/4] Remove other rotation constraint (fixes #463) --- src/map/transform.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/map/transform.cpp b/src/map/transform.cpp index 03e06f984..d05d1f744 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -66,12 +66,6 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati constrain(final.scale, final.y); - // Un-rotate when rotated and panning far enough to show off-world in corners. - double w = final.scale * util::tileSize / 2; - double m = std::sqrt(std::pow((current.width / 2), 2) + pow((current.height / 2), 2)); - double x = std::abs(sqrt(std::pow(final.x, 2) + std::pow(final.y, 2))); - if (current.angle && w - x < m) _setAngle(0); - if (duration == 0) { current.x = final.x; current.y = final.y; From 9e971095d3561f7af5b0016614035a8b4e479b81 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 20 Nov 2014 17:13:35 -0800 Subject: [PATCH 2/4] Pass FileSource by reference --- include/mbgl/map/sprite.hpp | 4 ++-- include/mbgl/text/glyph_store.hpp | 9 +++------ src/map/map.cpp | 6 +++--- src/map/sprite.cpp | 8 ++++---- src/text/glyph_store.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp index 454ebd888..d4b54ba1b 100644 --- a/include/mbgl/map/sprite.hpp +++ b/include/mbgl/map/sprite.hpp @@ -34,11 +34,11 @@ public: class Sprite : public std::enable_shared_from_this, private util::noncopyable { private: struct Key {}; - void load(const util::ptr &fileSource); + void load(FileSource& fileSource); public: Sprite(const Key &, const std::string& base_url, float pixelRatio); - static util::ptr Create(const std::string& base_url, float pixelRatio, const util::ptr &fileSource); + static util::ptr Create(const std::string& base_url, float pixelRatio, FileSource& fileSource); const SpritePosition &getSpritePosition(const std::string& name) const; diff --git a/include/mbgl/text/glyph_store.hpp b/include/mbgl/text/glyph_store.hpp index f8a7cb4d0..95ab92f30 100644 --- a/include/mbgl/text/glyph_store.hpp +++ b/include/mbgl/text/glyph_store.hpp @@ -48,7 +48,7 @@ private: class GlyphPBF { public: - GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr &fileSource); + GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource); private: GlyphPBF(const GlyphPBF &) = delete; @@ -71,7 +71,7 @@ private: // Manages Glyphrange PBF loading. class GlyphStore { public: - GlyphStore(const util::ptr &fileSource); + GlyphStore(FileSource& fileSource); // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set &glyphRanges); @@ -86,11 +86,8 @@ private: FontStack &createFontStack(const std::string &fontStack); -public: std::string glyphURL; - -private: - const util::ptr fileSource; + FileSource& fileSource; std::unordered_map>> ranges; std::unordered_map> stacks; std::mutex mtx; diff --git a/src/map/map.cpp b/src/map/map.cpp index 3daaa8798..73867b229 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -346,7 +346,7 @@ void Map::setStyleJSON(std::string newStyleJSON, const std::string &base) { style->loadJSON((const uint8_t *)styleJSON.c_str()); if (!fileSource) { fileSource = std::make_shared(**loop, platform::defaultCacheDatabase()); - glyphStore = std::make_shared(fileSource); + glyphStore = std::make_shared(*fileSource); } fileSource->setBase(base); glyphStore->setURL(util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken())); @@ -370,7 +370,7 @@ util::ptr Map::getSprite() { const float pixelRatio = state.getPixelRatio(); const std::string &sprite_url = style->getSpriteURL(); if (!sprite || sprite->pixelRatio != pixelRatio) { - sprite = Sprite::Create(sprite_url, pixelRatio, fileSource); + sprite = Sprite::Create(sprite_url, pixelRatio, *fileSource); } return sprite; @@ -649,7 +649,7 @@ void Map::updateTiles() { void Map::prepare() { if (!fileSource) { fileSource = std::make_shared(**loop, platform::defaultCacheDatabase()); - glyphStore = std::make_shared(fileSource); + glyphStore = std::make_shared(*fileSource); } if (!style) { diff --git a/src/map/sprite.cpp b/src/map/sprite.cpp index ad1a8e770..82073619d 100644 --- a/src/map/sprite.cpp +++ b/src/map/sprite.cpp @@ -22,7 +22,7 @@ SpritePosition::SpritePosition(uint16_t x_, uint16_t y_, uint16_t width_, uint16 sdf(sdf_) { } -util::ptr Sprite::Create(const std::string& base_url, float pixelRatio, const util::ptr &fileSource) { +util::ptr Sprite::Create(const std::string& base_url, float pixelRatio, FileSource& fileSource) { util::ptr sprite(std::make_shared(Key(), base_url, pixelRatio)); sprite->load(fileSource); return sprite; @@ -51,7 +51,7 @@ Sprite::operator bool() const { // Note: This is a separate function that must be called exactly once after creation // The reason this isn't part of the constructor is that calling shared_from_this() in // the constructor fails. -void Sprite::load(const util::ptr &fileSource) { +void Sprite::load(FileSource& fileSource) { if (!valid) { // Treat a non-existent sprite as a successfully loaded empty sprite. loadedImage = true; @@ -62,7 +62,7 @@ void Sprite::load(const util::ptr &fileSource) { util::ptr sprite = shared_from_this(); - fileSource->request(ResourceType::JSON, jsonURL)->onload([sprite](const Response &res) { + fileSource.request(ResourceType::JSON, jsonURL)->onload([sprite](const Response &res) { if (res.code == 200) { sprite->body = res.data; sprite->parseJSON(); @@ -75,7 +75,7 @@ void Sprite::load(const util::ptr &fileSource) { } }); - fileSource->request(ResourceType::Image, spriteURL)->onload([sprite](const Response &res) { + fileSource.request(ResourceType::Image, spriteURL)->onload([sprite](const Response &res) { if (res.code == 200) { sprite->image = res.data; sprite->parseImage(); diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp index 5619c4f93..737bad35d 100644 --- a/src/text/glyph_store.cpp +++ b/src/text/glyph_store.cpp @@ -137,7 +137,7 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, line); } -GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr &fileSource) +GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource) : future(promise.get_future().share()) { // Load the glyph set URL @@ -148,8 +148,8 @@ GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, Gl }); // The prepare call jumps back to the main thread. - fileSource->prepare([&, url, fileSource] { - auto request = fileSource->request(ResourceType::Glyphs, url); + fileSource.prepare([&, url] { + auto request = fileSource.request(ResourceType::Glyphs, url); request->onload([&, url](const Response &res) { if (res.code != 200) { // Something went wrong with loading the glyph pbf. Pass on the error to the future listeners. @@ -228,7 +228,7 @@ void GlyphPBF::parse(FontStack &stack) { data.clear(); } -GlyphStore::GlyphStore(const util::ptr &fileSource_) : fileSource(fileSource_) {} +GlyphStore::GlyphStore(FileSource& fileSource_) : fileSource(fileSource_) {} void GlyphStore::setURL(const std::string &url) { glyphURL = url; From c3940cf08251f9fc9bfce4911e7b24f5985ae105 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 20 Nov 2014 19:25:38 -0800 Subject: [PATCH 3/4] Eliminate Map::getFileSource --- include/mbgl/map/map.hpp | 1 - include/mbgl/map/source.hpp | 9 +++++---- include/mbgl/map/tile_data.hpp | 3 ++- src/map/map.cpp | 4 ++-- src/map/source.cpp | 16 ++++++++-------- src/map/tile_data.cpp | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index ad33865cd..ab5311741 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -126,7 +126,6 @@ public: public: inline const TransformState &getState() const { return state; } - inline util::ptr getFileSource() const { return fileSource; } inline util::ptr