blob: da41a280352709f84561567d11b210bbb55fcd08 (
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
|
#ifndef MBGL_MAP_MAP_DATA
#define MBGL_MAP_MAP_DATA
#include <mbgl/util/chrono.hpp>
#include <mutex>
#include <atomic>
#include <vector>
#include <cassert>
#include <condition_variable>
#include <mbgl/map/mode.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/util/exclusive.hpp>
namespace mbgl {
class MapData {
using Lock = std::lock_guard<std::mutex>;
public:
inline MapData(MapMode mode_, GLContextMode contextMode_, const float pixelRatio_)
: mode(mode_)
, contextMode(contextMode_)
, pixelRatio(pixelRatio_)
, annotationManager(pixelRatio)
, animationTime(Duration::zero()) {
assert(pixelRatio > 0);
}
inline MapDebugOptions getDebug() const {
return debugOptions;
}
inline void cycleDebugOptions() {
if (debugOptions & MapDebugOptions::Collision)
debugOptions = MapDebugOptions::NoDebug;
else if (debugOptions & MapDebugOptions::Timestamps)
debugOptions = debugOptions | MapDebugOptions::Collision;
else if (debugOptions & MapDebugOptions::ParseStatus)
debugOptions = debugOptions | MapDebugOptions::Timestamps;
else if (debugOptions & MapDebugOptions::TileBorders)
debugOptions = debugOptions | MapDebugOptions::ParseStatus;
else
debugOptions = MapDebugOptions::TileBorders;
}
inline void setDebug(MapDebugOptions debugOptions_) {
debugOptions = debugOptions_;
}
inline TimePoint getAnimationTime() const {
// We're casting the TimePoint to and from a Duration because libstdc++
// has a bug that doesn't allow TimePoints to be atomic.
return mode == MapMode::Continuous ? TimePoint(animationTime) : Clock::now();
}
inline void setAnimationTime(const TimePoint& timePoint) {
if (mode == MapMode::Still) {
return;
}
animationTime = timePoint.time_since_epoch();
};
util::exclusive<AnnotationManager> getAnnotationManager() {
return util::exclusive<AnnotationManager>(
&annotationManager,
std::make_unique<std::lock_guard<std::mutex>>(annotationManagerMutex));
}
public:
const MapMode mode;
const GLContextMode contextMode;
const float pixelRatio;
private:
mutable std::mutex annotationManagerMutex;
AnnotationManager annotationManager;
std::atomic<MapDebugOptions> debugOptions { MapDebugOptions::NoDebug };
std::atomic<Duration> animationTime;
// TODO: make private
public:
bool paused = false;
std::mutex mutexPause;
std::condition_variable condPause;
bool loading = false;
};
} // namespace mbgl
#endif
|