diff options
Diffstat (limited to 'include/llmr')
-rw-r--r-- | include/llmr/map/layer.hpp | 44 | ||||
-rw-r--r-- | include/llmr/map/map.hpp | 2 | ||||
-rw-r--r-- | include/llmr/map/tile.hpp | 29 | ||||
-rw-r--r-- | include/llmr/renderer/fill_bucket.hpp | 4 | ||||
-rw-r--r-- | include/llmr/renderer/painter.hpp | 2 | ||||
-rw-r--r-- | include/llmr/resources/style.hpp | 15 | ||||
-rw-r--r-- | include/llmr/style/bucket_description.hpp | 51 | ||||
-rw-r--r-- | include/llmr/style/class_description.hpp | 32 | ||||
-rw-r--r-- | include/llmr/style/layer_description.hpp | 20 | ||||
-rw-r--r-- | include/llmr/style/properties.hpp | 42 | ||||
-rw-r--r-- | include/llmr/style/style.hpp | 66 | ||||
-rw-r--r-- | include/llmr/style/value.hpp | 15 | ||||
-rw-r--r-- | include/llmr/util/pbf.hpp | 31 |
13 files changed, 276 insertions, 77 deletions
diff --git a/include/llmr/map/layer.hpp b/include/llmr/map/layer.hpp index c6a10b9218..2e4db2997a 100644 --- a/include/llmr/map/layer.hpp +++ b/include/llmr/map/layer.hpp @@ -2,29 +2,33 @@ #define LLMR_MAP_LAYER #include <string> +#include <forward_list> namespace llmr { -class Bucket; -class Tile; - -class Layer { -public: - Layer(const std::string& name, const std::shared_ptr<Bucket>& bucket) - : name(name), - bucket(bucket) {} - -public: - std::string name; - std::shared_ptr<Bucket> bucket; - -private: - // Make noncopyable - Layer(const Layer&) = delete; - Layer(const Layer&&) = delete; - Layer& operator=(const Layer&) = delete; - Layer& operator=(const Layer && ) = delete; -}; +// class Bucket; + +// class Layer { +// public: +// Layer(const std::string& name, const std::shared_ptr<Bucket>& bucket) +// : name(name), +// bucket(bucket) {} + +// Layer(const std::string& name) +// : name(name) {} + +// public: +// std::string name; +// std::shared_ptr<Bucket> bucket; +// std::forward_list<Layer> child_layers; + +// private: +// // Make noncopyable +// // Layer(const Layer&) = delete; +// // Layer(const Layer&&) = delete; +// // Layer& operator=(const Layer&) = delete; +// // Layer& operator=(const Layer && ) = delete; +// }; } diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 512830713b..1007ca9871 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -25,7 +25,7 @@ public: Map &operator=(const Map&&) = delete; void setup(); - void loadStyle(const uint8_t *data, uint32_t bytes); + void loadStyle(const uint8_t *const data, uint32_t bytes); void loadSettings(); void resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb_height); diff --git a/include/llmr/map/tile.hpp b/include/llmr/map/tile.hpp index 5cc8065994..86c56fe490 100644 --- a/include/llmr/map/tile.hpp +++ b/include/llmr/map/tile.hpp @@ -12,10 +12,15 @@ #include <mutex> #include <llmr/util/vec.hpp> #include <string> +#include <map> namespace llmr { struct pbf; +class Style; +class Bucket; +class LayerDescription; +class BucketDescription; class Tile { public: @@ -35,7 +40,7 @@ public: }; public: - Tile(ID id); + Tile(ID id, const Style& style); ~Tile(); // Make noncopyable @@ -47,9 +52,13 @@ public: // Other functions void setData(uint8_t *data, uint32_t bytes); bool parse(); - void parseLayer(const pbf layer); + void parseLayers(const pbf& tile, const std::vector<LayerDescription>& layers); + std::shared_ptr<Bucket> createBucket(const pbf& tile, const BucketDescription& bucket_desc); + // void parseLayer(const pbf layer); - std::shared_ptr<Bucket> createFillBucket(const pbf data); + // void (const std::vector<LayerDescription>& child_layers); + + std::shared_ptr<Bucket> createFillBucket(const pbf data, const BucketDescription& bucket_desc); void cancel(); @@ -61,12 +70,16 @@ public: public: const ID id; state state; - linevertexbuffer lineVertex; - debug_font_buffer debugFontVertex; - FillBuffer fillBuffer; + // Holds the actual geometries in this tile. + std::shared_ptr<linevertexbuffer> lineVertex; + std::shared_ptr<debug_font_buffer> debugFontVertex; + std::shared_ptr<FillBuffer> fillBuffer; - std::forward_list<Layer> layers; + // Holds the buckets of this tile. + // They contain the location offsets in the buffers stored above + std::map<std::string, std::shared_ptr<Bucket>> buckets; + // std::forward_list<Layer> layers; private: // Source data @@ -74,6 +87,8 @@ private: uint32_t bytes; std::mutex mtx; + + const Style& style; }; } diff --git a/include/llmr/renderer/fill_bucket.hpp b/include/llmr/renderer/fill_bucket.hpp index 71764af4fd..e90f51772c 100644 --- a/include/llmr/renderer/fill_bucket.hpp +++ b/include/llmr/renderer/fill_bucket.hpp @@ -13,7 +13,7 @@ struct pbf; class FillBucket : public Bucket { public: - FillBucket(FillBuffer& buffer); + FillBucket(const std::shared_ptr<FillBuffer>& buffer); virtual void render(Painter& painter, const std::string& layer_name); @@ -22,7 +22,7 @@ public: void drawVertices(int32_t attrib); private: - FillBuffer& buffer; + std::shared_ptr<FillBuffer> buffer; struct group { uint32_t vertex_length; diff --git a/include/llmr/renderer/painter.hpp b/include/llmr/renderer/painter.hpp index 715098bd77..c2e7b8d614 100644 --- a/include/llmr/renderer/painter.hpp +++ b/include/llmr/renderer/painter.hpp @@ -12,6 +12,7 @@ namespace llmr { class Settings; class Transform; class Style; +class LayerDescription; class FillBucket; struct FillProperties; @@ -32,6 +33,7 @@ public: void clear(); void render(const std::shared_ptr<Tile>& tile); + void renderLayers(const std::shared_ptr<Tile>& tile, const std::vector<LayerDescription>& layers); void renderDebug(const std::shared_ptr<Tile>& tile); void renderBackground(); diff --git a/include/llmr/resources/style.hpp b/include/llmr/resources/style.hpp new file mode 100644 index 0000000000..684de3d546 --- /dev/null +++ b/include/llmr/resources/style.hpp @@ -0,0 +1,15 @@ +// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. + +#ifndef LLMR_RESOURCE_STYLE +#define LLMR_RESOURCE_STYLE + +namespace llmr { +namespace resources { + +extern const unsigned char style[]; +extern const unsigned long style_size; + +} +} + +#endif diff --git a/include/llmr/style/bucket_description.hpp b/include/llmr/style/bucket_description.hpp new file mode 100644 index 0000000000..c8933d4190 --- /dev/null +++ b/include/llmr/style/bucket_description.hpp @@ -0,0 +1,51 @@ +#ifndef LLMR_STYLE_BUCKET_DESCRIPTION +#define LLMR_STYLE_BUCKET_DESCRIPTION + +#include <string> +#include <vector> + +#include "value.hpp" + +namespace llmr { + +enum class BucketType { + None = 0, + Fill = 1, + Line = 2, + Point = 3 +}; + +enum class CapType { + None = 0, + Round = 1, +}; + +enum class JoinType { + None = 0, + Butt = 1, + Bevel = 2 +}; + + +class BucketDescription { +public: + BucketType type = BucketType::None; + + // Specify what data to pull into this bucket + std::string source_name; + std::string source_layer; + std::string source_field; + std::vector<Value> source_value; + + // Specifies how the geometry for this bucket should be created + CapType cap = CapType::None; + JoinType join = JoinType::None; + std::string font; + float font_size = 0.0f; +}; + +std::ostream& operator<<(std::ostream&, const BucketDescription& bucket); + +} + +#endif diff --git a/include/llmr/style/class_description.hpp b/include/llmr/style/class_description.hpp new file mode 100644 index 0000000000..a63dc8d041 --- /dev/null +++ b/include/llmr/style/class_description.hpp @@ -0,0 +1,32 @@ +#ifndef LLMR_STYLE_CLASS_DESCRIPTION +#define LLMR_STYLE_CLASS_DESCRIPTION + +#include <string> +#include <vector> +#include <map> +#include "properties.hpp" + +namespace llmr { + + +class WidthDescription { +public: + std::string scaling; + std::vector<float> value; +}; + + +class LayerStyleDescription { +public: + Color color = {{ 0, 0, 0, 0 }}; + bool antialias = false; + WidthDescription width; +}; + +typedef std::map<std::string, LayerStyleDescription> ClassDescription; + +std::ostream& operator<<(std::ostream&, const ClassDescription& layer); + +} + +#endif diff --git a/include/llmr/style/layer_description.hpp b/include/llmr/style/layer_description.hpp new file mode 100644 index 0000000000..405c884e52 --- /dev/null +++ b/include/llmr/style/layer_description.hpp @@ -0,0 +1,20 @@ +#ifndef LLMR_STYLE_LAYER_DESCRIPTION +#define LLMR_STYLE_LAYER_DESCRIPTION + +#include <string> +#include <vector> + +namespace llmr { + +class LayerDescription { +public: + std::string name; + std::string bucket_name; + std::vector<LayerDescription> child_layer; +}; + +std::ostream& operator<<(std::ostream&, const LayerDescription& layer); + +} + +#endif diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp new file mode 100644 index 0000000000..8eb0969c71 --- /dev/null +++ b/include/llmr/style/properties.hpp @@ -0,0 +1,42 @@ +#ifndef LLMR_STYLE_PROPERTIES +#define LLMR_STYLE_PROPERTIES + +#include <array> + +namespace llmr { + +typedef std::array<float, 4> Color; + +enum Winding { + EvenOdd = 1, + NonZero = 2 +}; + +// enum LineCap { +// Round = 1 +// }; + +// enum LineJoin { +// Butt = 1, +// Bevel = 2 +// }; + + +struct StrokeProperties { + bool enabled = false; + Color line_color = {{ 0, 0, 0, 1 }}; + float line_width = 1; +}; + +struct FillProperties { + bool enabled = false; + Winding winding = NonZero; + bool antialiasing = true; + Color fill_color = {{ 0, 0, 0, 1 }}; + Color stroke_color = {{ 0, 0, 0, 1 }}; + float stroke_width = 1; +}; + +} + +#endif diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index 3324e01dc1..ee99ff2243 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -1,54 +1,52 @@ #ifndef LLMR_STYLE_STYLE #define LLMR_STYLE_STYLE -#include <array> #include <map> +#include <vector> +#include <set> #include "../util/pbf.hpp" -namespace llmr { - -typedef std::array<float, 4> Color; - -enum Winding { - EvenOdd = 1, - NonZero = 2 -}; +#include "value.hpp" +#include "properties.hpp" +#include "bucket_description.hpp" +#include "layer_description.hpp" +#include "class_description.hpp" -// enum LineCap { -// Round = 1 -// }; - -// enum LineJoin { -// Butt = 1, -// Bevel = 2 -// }; - - -struct StrokeProperties { - Color line_color = {{ 0, 0, 0, 1 }}; - float line_width = 1; -}; - -struct FillProperties { - Winding winding = NonZero; - bool antialiasing = true; - Color fill_color = {{ 0, 0, 0, 1 }}; - Color stroke_color = {{ 0, 0, 0, 1 }}; - float stroke_width = 1; -}; +namespace llmr { class Style { public: Style(); void reset(); - void load(pbf data); + void load(const uint8_t *const data, uint32_t bytes); + + void cascade(); + +private: + static std::pair<std::string, BucketDescription> loadBucket(pbf data); + static LayerDescription loadLayer(pbf data); + static std::pair<std::string, ClassDescription> loadClass(pbf data); + static std::pair<std::string, LayerStyleDescription> loadLayerStyle(pbf data); + static WidthDescription loadWidth(pbf data); public: - std::map<std::string, FillProperties> computedFills; - std::map<std::string, StrokeProperties> computedStrokes; + // This is static information parsed from the stylesheet. + std::map<std::string, BucketDescription> buckets; + std::vector<LayerDescription> layers; + std::map<std::string, ClassDescription> classes; + + + // This are applied settings. + std::set<std::string> appliedClasses; + struct { + std::map<std::string, FillProperties> fills; + std::map<std::string, StrokeProperties> strokes; + } computed; }; } + + #endif
\ No newline at end of file diff --git a/include/llmr/style/value.hpp b/include/llmr/style/value.hpp new file mode 100644 index 0000000000..f0d594b764 --- /dev/null +++ b/include/llmr/style/value.hpp @@ -0,0 +1,15 @@ +#ifndef LLMR_STYLE_VALUE +#define LLMR_STYLE_VALUE + +#include <boost/variant.hpp> +#include <llmr/util/pbf.hpp> + +namespace llmr { + +typedef boost::variant<std::string, double, int64_t, uint64_t, bool> Value; + +Value parseValue(pbf data); + +} + +#endif diff --git a/include/llmr/util/pbf.hpp b/include/llmr/util/pbf.hpp index 3fe851a7d4..fbf45e6a1f 100644 --- a/include/llmr/util/pbf.hpp +++ b/include/llmr/util/pbf.hpp @@ -31,9 +31,12 @@ struct pbf { inline bool next(); template <typename T = uint32_t> inline T varint(); template <typename T = uint32_t> inline T svarint(); - inline std::string string(); + + template <typename T = uint32_t, int bytes = 4> inline T fixed(); inline float float32(); inline double float64(); + + inline std::string string(); inline bool boolean(); inline pbf message(); @@ -99,25 +102,27 @@ T pbf::svarint() { return (n >> 1) ^ -(T)(n & 1); } -std::string pbf::string() { - uint32_t bytes = (uint32_t)varint(); - const char *string = (const char *)data; +template <typename T, int bytes> +T pbf::fixed() { skipBytes(bytes); - return std::string(string, bytes); + T result; + memcpy(&result, data - bytes, bytes); + return result; } float pbf::float32() { - skipBytes(4); - float result; - memcpy(&result, data - 4, 4); - return result; + return fixed<float, 4>(); } double pbf::float64() { - skipBytes(8); - double result; - memcpy(&result, data - 8, 8); - return result; + return fixed<double, 8>(); +} + +std::string pbf::string() { + uint32_t bytes = (uint32_t)varint(); + const char *string = (const char *)data; + skipBytes(bytes); + return std::string(string, bytes); } bool pbf::boolean() { |