Welcome to mirror list, hosted at ThFree Co, Russian Federation.

traffic_generator.hpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c36b8bcd45cd51ea203c3b7edba16579707afb8 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once

#include "drape_frontend/tile_key.hpp"

#include "drape/color.hpp"
#include "drape/glsl_types.hpp"
#include "drape/glstate.hpp"
#include "drape/overlay_handle.hpp"
#include "drape/render_bucket.hpp"
#include "drape/texture_manager.hpp"

#include "geometry/polyline2d.hpp"

#include "std/map.hpp"
#include "std/set.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
#include "std/unordered_map.hpp"

namespace df
{

enum TrafficSpeedBucket
{
  Normal = 3,
  Slow = 2,
  VerySlow = 1
};

struct TrafficSegmentData
{
  uint64_t m_id;
  TrafficSpeedBucket m_speedBucket;

  TrafficSegmentData() = default;
  TrafficSegmentData(uint64_t id, TrafficSpeedBucket const & speedBucket)
    : m_id(id)
    , m_speedBucket(speedBucket)
  {}
};

struct TrafficRenderData
{
  dp::GLState m_state;
  drape_ptr<dp::RenderBucket> m_bucket;
  TileKey m_tileKey;
  TrafficRenderData(dp::GLState const & state) : m_state(state) {}
};

struct TrafficStaticVertex
{
  using TPosition = glsl::vec3;
  using TNormal = glsl::vec4;

  TrafficStaticVertex() = default;
  TrafficStaticVertex(TPosition const & position, TNormal const & normal)
    : m_position(position)
    , m_normal(normal)
  {}

  TPosition m_position;
  TNormal m_normal;
};

struct TrafficDynamicVertex
{
  using TTexCoord = glsl::vec2;

  TrafficDynamicVertex() = default;
  TrafficDynamicVertex(TTexCoord const & color)
    : m_colorTexCoord(color)
  {}

  TTexCoord m_colorTexCoord;
};

class TrafficHandle : public dp::OverlayHandle
{
  using TBase = dp::OverlayHandle;

public:
  TrafficHandle(uint64_t segmentId, glsl::vec2 const & texCoord, size_t verticesCount);

  void GetAttributeMutation(ref_ptr<dp::AttributeBufferMutator> mutator) const override;
  bool Update(ScreenBase const & screen) override;
  bool IndexesRequired() const override;
  m2::RectD GetPixelRect(ScreenBase const & screen, bool perspective) const override;
  void GetPixelShape(ScreenBase const & screen, bool perspective, Rects & rects) const override;

  void SetTexCoord(glsl::vec2 const & texCoord);
  uint64_t GetSegmentId() const;

private:
  uint64_t m_segmentId;
  vector<glsl::vec2> m_buffer;
  mutable bool m_needUpdate;
};

class TrafficGenerator final
{
public:
  TrafficGenerator() = default;

  void AddSegment(uint64_t segmentId, m2::PolylineD const & polyline);

  vector<TrafficSegmentData> GetSegmentsToUpdate(vector<TrafficSegmentData> const & trafficData) const;

  void GetTrafficGeom(ref_ptr<dp::TextureManager> textures,
                      vector<TrafficSegmentData> const & trafficData,
                      vector<TrafficRenderData> & data);

  void ClearCache();

  bool IsColorsCacheRefreshed() const { return m_colorsCacheRefreshed; }
  unordered_map<int, glsl::vec2> ProcessCacheRefreshing();

private:
  using TSegmentCollection = map<uint64_t, m2::PolylineD>;

  void GenerateSegment(dp::TextureManager::ColorRegion const & colorRegion,
                       m2::PolylineD const & polyline, m2::PointD const & tileCenter,
                       vector<TrafficStaticVertex> & staticGeometry,
                       vector<TrafficDynamicVertex> & dynamicGeometry);
  void FillColorsCache(ref_ptr<dp::TextureManager> textures);

  TSegmentCollection m_segments;

  set<uint64_t> m_segmentsCache;
  unordered_map<int, dp::TextureManager::ColorRegion> m_colorsCache;
  bool m_colorsCacheRefreshed = false;
};

} // namespace df