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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
#pragma once
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/renderer/transition_parameters.hpp>
#include <mbgl/renderer/possibly_evaluated_property_value.hpp>
#include <mbgl/renderer/property_evaluation_parameters.hpp>
#include <mbgl/renderer/transition_parameters.hpp>
#include <mbgl/util/indexed_tuple.hpp>
#include <mbgl/util/ignore.hpp>
#include <bitset>
namespace mbgl {
class GeometryTileFeature;
namespace style {
template <class Value>
class Transitioning {
public:
Transitioning() = default;
explicit Transitioning(Value value_)
: value(std::move(value_)) {
}
Transitioning(Value value_,
Transitioning<Value> prior_,
TransitionOptions transition,
TimePoint now)
: begin(now + transition.delay.value_or(Duration::zero())),
end(begin + transition.duration.value_or(Duration::zero())),
value(std::move(value_)) {
if (transition.isDefined()) {
prior = { std::move(prior_) };
}
}
template <class Evaluator>
auto evaluate(const Evaluator& evaluator, TimePoint now) const {
auto finalValue = value.evaluate(evaluator);
if (!prior) {
// No prior value.
return finalValue;
} else if (now >= end) {
// Transition from prior value is now complete.
prior = {};
return finalValue;
} else if (value.isDataDriven()) {
// Transitions to data-driven properties are not supported.
// We snap immediately to the data-driven value so that, when we perform layout,
// we see the data-driven function and can use it to populate vertex buffers.
prior = {};
return finalValue;
} else if (now < begin) {
// Transition hasn't started yet.
return prior->get().evaluate(evaluator, now);
} else {
// Interpolate between recursively-calculated prior value and final.
float t = std::chrono::duration<float>(now - begin) / (end - begin);
return util::interpolate(prior->get().evaluate(evaluator, now), finalValue,
util::DEFAULT_TRANSITION_EASE.solve(t, 0.001));
}
}
bool hasTransition() const {
return bool(prior);
}
bool isUndefined() const {
return value.isUndefined();
}
const Value& getValue() const {
return value;
}
private:
mutable optional<mapbox::util::recursive_wrapper<Transitioning<Value>>> prior;
TimePoint begin;
TimePoint end;
Value value;
};
template <class Value>
class Transitionable {
public:
Value value;
TransitionOptions options;
Transitioning<Value> transition(const TransitionParameters& params, Transitioning<Value> prior) const {
return Transitioning<Value>(value,
std::move(prior),
options.reverseMerge(params.transition),
params.now);
}
};
template <class P>
struct IsDataDriven : std::integral_constant<bool, P::IsDataDriven> {};
template <class P>
struct IsOverridable : std::integral_constant<bool, P::IsOverridable> {};
template <class Ps>
struct ConstantsMask;
template <class... Ps>
struct ConstantsMask<TypeList<Ps...>> {
template <class Properties>
static unsigned long getMask(const Properties& properties) {
std::bitset<sizeof... (Ps)> result;
util::ignore({
result.set(TypeIndex<Ps, Ps...>::value,
properties.template get<Ps>().isConstant())...
});
return result.to_ulong();
}
};
template <class... Ps>
class Properties {
public:
/*
For style properties we implement a two step evaluation process: if you have a zoom level,
you can evaluate a set of unevaluated property values, producing a set of possibly evaluated
values, where undefined, constant, or camera function values have been fully evaluated, and
source or composite function values have not.
Once you also have a particular feature, you can evaluate that set of possibly evaluated values
fully, producing a set of fully evaluated values.
This is in theory maximally efficient in terms of avoiding repeated evaluation of camera
functions, though it's more of a historical accident than a purposeful optimization.
*/
using PropertyTypes = TypeList<Ps...>;
using TransitionableTypes = TypeList<typename Ps::TransitionableType...>;
using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
using PossiblyEvaluatedTypes = TypeList<typename Ps::PossiblyEvaluatedType...>;
using EvaluatedTypes = TypeList<typename Ps::Type...>;
using DataDrivenProperties = FilteredTypeList<PropertyTypes, IsDataDriven>;
using OverridableProperties = FilteredTypeList<PropertyTypes, IsOverridable>;
template <class TypeList>
using Tuple = IndexedTuple<PropertyTypes, TypeList>;
class Evaluated : public Tuple<EvaluatedTypes> {
public:
template <class... Us>
Evaluated(Us&&... us)
: Tuple<EvaluatedTypes>(std::forward<Us>(us)...) {
}
};
class PossiblyEvaluated : public Tuple<PossiblyEvaluatedTypes> {
public:
template <class... Us>
PossiblyEvaluated(Us&&... us)
: Tuple<PossiblyEvaluatedTypes>(std::forward<Us>(us)...) {
}
template <class T>
static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) {
return t;
}
template <class T>
static T evaluate(float z, const GeometryTileFeature& feature,
const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) {
return v.match(
[&] (const T& t) {
return t;
},
[&] (const PropertyExpression<T>& t) {
return t.evaluate(z, feature, defaultValue);
});
}
template <class T>
static T evaluate(float z, const GeometryTileFeature& feature, const FeatureState& state,
const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) {
return v.match([&](const T& t) { return t; },
[&](const PropertyExpression<T>& t) { return t.evaluate(z, feature, state, defaultValue); });
}
template <class P>
auto evaluate(float z, const GeometryTileFeature& feature) const {
return evaluate(z, feature, this->template get<P>(), P::defaultValue());
}
template <class P>
auto evaluate(float z, const GeometryTileFeature& feature, const FeatureState& state) const {
return evaluate(z, feature, state, this->template get<P>(), P::defaultValue());
}
Evaluated evaluate(float z, const GeometryTileFeature& feature) const {
return Evaluated {
evaluate<Ps>(z, feature)...
};
}
unsigned long constantsMask() const {
return ConstantsMask<DataDrivenProperties>::getMask(*this);
}
};
class Unevaluated : public Tuple<UnevaluatedTypes> {
public:
template <class... Us>
Unevaluated(Us&&... us)
: Tuple<UnevaluatedTypes>(std::forward<Us>(us)...) {
}
bool hasTransition() const {
bool result = false;
util::ignore({ result |= this->template get<Ps>().hasTransition()... });
return result;
}
template <class P>
auto evaluate(const PropertyEvaluationParameters& parameters) const {
using Evaluator = typename P::EvaluatorType;
return this->template get<P>()
.evaluate(Evaluator(parameters, P::defaultValue()), parameters.now);
}
PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const {
return PossiblyEvaluated {
evaluate<Ps>(parameters)...
};
}
template <class Writer>
void stringify(Writer& writer) const {
writer.StartObject();
util::ignore({ (conversion::stringify<Ps>(writer, this->template get<Ps>()), 0)... });
writer.EndObject();
}
};
class Transitionable : public Tuple<TransitionableTypes> {
public:
template <class... Us>
Transitionable(Us&&... us)
: Tuple<TransitionableTypes>(std::forward<Us>(us)...) {
}
Unevaluated transitioned(const TransitionParameters& parameters, Unevaluated&& prior) const {
return Unevaluated {
this->template get<Ps>()
.transition(parameters, std::move(prior.template get<Ps>()))...
};
}
Unevaluated untransitioned() const {
return Unevaluated {
typename Ps::UnevaluatedType(this->template get<Ps>().value)...
};
}
bool hasDataDrivenPropertyDifference(const Transitionable& other) const {
bool result = false;
util::ignore({ (result |= this->template get<Ps>().value.hasDataDrivenPropertyDifference(other.template get<Ps>().value))... });
return result;
}
};
};
template <class... Ps>
using ConcatenateProperties = typename TypeListConcat<typename Ps::PropertyTypes...>::template ExpandInto<Properties>;
} // namespace style
} // namespace mbgl
|