summaryrefslogtreecommitdiff
path: root/include/mbgl/map/sprite.hpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-07-31 18:14:26 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-07-31 18:14:26 +0200
commit75c079adb16a24cbd8b8111993a67313fd52718a (patch)
tree400207782ad718fa605414a6132dcfa20a09415d /include/mbgl/map/sprite.hpp
parentfa3a41136ca6345f34b53a1f211926cc1bd8649c (diff)
downloadqtlocation-mapboxgl-75c079adb16a24cbd8b8111993a67313fd52718a.tar.gz
move sprite to a use future loading
Diffstat (limited to 'include/mbgl/map/sprite.hpp')
-rw-r--r--include/mbgl/map/sprite.hpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp
index 3f8d5611a4..40d37d5da1 100644
--- a/include/mbgl/map/sprite.hpp
+++ b/include/mbgl/map/sprite.hpp
@@ -2,6 +2,7 @@
#define MBGL_STYLE_SPRITE
#include <mbgl/util/image.hpp>
+#include <mbgl/util/noncopyable.hpp>
#include <cstdint>
#include <atomic>
@@ -9,6 +10,7 @@
#include <memory>
#include <string>
#include <unordered_map>
+#include <future>
namespace mbgl {
@@ -28,37 +30,43 @@ public:
uint8_t pixelRatio = 1;
};
-class Sprite : public std::enable_shared_from_this<Sprite> {
-public:
- Sprite(Map &map, float pixelRatio = 1);
+class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable {
+private:
+ struct Key {};
+ void load();
- void load(const std::string& base_url);
+public:
+ Sprite(const Key &, const std::string& base_url, float pixelRatio);
+ static std::shared_ptr<Sprite> Create(const std::string& base_url, float pixelRatio);
const SpritePosition &getSpritePosition(const std::string& name) const;
+ void waitUntilLoaded() const;
bool isLoaded() const;
+ operator bool() const;
+
public:
const float pixelRatio;
+ const std::string url;
std::unique_ptr<util::Image> raster;
private:
- void asyncParseJSON();
- void asyncParseImage();
-
- static void parseJSON(std::shared_ptr<Sprite> &sprite);
- static void parseImage(std::shared_ptr<Sprite> &sprite);
- static void complete(std::shared_ptr<Sprite> &sprite);
+ void parseJSON();
+ void parseImage();
+ void complete();
private:
- Map &map;
- std::string url;
std::string body;
std::string image;
std::atomic<bool> loadedImage;
std::atomic<bool> loadedJSON;
std::unordered_map<std::string, SpritePosition> pos;
const SpritePosition empty;
+
+ std::promise<void> promise;
+ std::future<void> future;
+
};
}