summaryrefslogtreecommitdiff
path: root/include/llmr/map/tile.hpp
blob: 86c56fe4908aada77cdc9b7c4ddd1aa5712cca83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef LLMR_MAP_TILE
#define LLMR_MAP_TILE

#include "../geometry/debug_font_buffer.hpp"
#include "../geometry/linevertexbuffer.hpp"
#include "../geometry/fill_buffer.hpp"

#include "layer.hpp"

#include <stdint.h>
#include <forward_list>
#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:
    struct exception : std::exception {};
    struct geometry_too_long_exception : exception {};

public:
    typedef std::shared_ptr<Tile> Ptr;

    typedef vec3<int32_t> ID;

    enum state {
        initial,
        loading,
        ready,
        obsolete
    };

public:
    Tile(ID id, const Style& style);
    ~Tile();

    // Make noncopyable
    Tile(const Tile&) = delete;
    Tile(const Tile&&) = delete;
    Tile& operator=(const Tile&) = delete;
    Tile& operator=(const Tile && ) = delete;

    // Other functions
    void setData(uint8_t *data, uint32_t bytes);
    bool parse();
    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);

    // void (const std::vector<LayerDescription>& child_layers);

    std::shared_ptr<Bucket> createFillBucket(const pbf data, const BucketDescription& bucket_desc);

    void cancel();

    const std::string toString() const;

    static ID parent(const ID& id, int32_t z);
    static std::forward_list<ID> children(const ID& id, int32_t z);

public:
    const ID id;
    state state;

    // Holds the actual geometries in this tile.
    std::shared_ptr<linevertexbuffer> lineVertex;
    std::shared_ptr<debug_font_buffer> debugFontVertex;
    std::shared_ptr<FillBuffer> fillBuffer;

    // 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
    uint8_t *data;
    uint32_t bytes;

    std::mutex mtx;

    const Style& style;
};

}

#endif