diff options
Diffstat (limited to 'src/mbgl/style/paint_property.hpp')
-rw-r--r-- | src/mbgl/style/paint_property.hpp | 75 |
1 files changed, 7 insertions, 68 deletions
diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 7f7018748c..dd8d6c0b50 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/style/transitioning_property.hpp> #include <mbgl/style/class_dictionary.hpp> #include <mbgl/style/property_value.hpp> #include <mbgl/style/data_driven_property_value.hpp> @@ -24,68 +25,6 @@ class GeometryTileFeature; namespace style { template <class Value> -class UnevaluatedPaintProperty { -public: - UnevaluatedPaintProperty() = default; - - UnevaluatedPaintProperty(Value value_, - UnevaluatedPaintProperty<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) { - 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: - optional<mapbox::util::recursive_wrapper<UnevaluatedPaintProperty<Value>>> prior; - TimePoint begin; - TimePoint end; - Value value; -}; - -template <class Value> class CascadingPaintProperty { public: bool isUndefined() const { @@ -112,8 +51,8 @@ public: transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition; } - template <class UnevaluatedPaintProperty> - UnevaluatedPaintProperty cascade(const CascadeParameters& params, UnevaluatedPaintProperty prior) const { + template <class TransitioningProperty> + TransitioningProperty cascade(const CascadeParameters& params, TransitioningProperty prior) const { TransitionOptions transition; Value value; @@ -131,7 +70,7 @@ public: } } - return UnevaluatedPaintProperty(std::move(value), + return TransitioningProperty(std::move(value), std::move(prior), transition.reverseMerge(params.transition), params.now); @@ -147,7 +86,7 @@ class PaintProperty { public: using ValueType = PropertyValue<T>; using CascadingType = CascadingPaintProperty<ValueType>; - using UnevaluatedType = UnevaluatedPaintProperty<ValueType>; + using UnevaluatedType = TransitioningProperty<ValueType>; using EvaluatorType = PropertyEvaluator<T>; using EvaluatedType = T; static constexpr bool IsDataDriven = false; @@ -158,7 +97,7 @@ class DataDrivenPaintProperty { public: using ValueType = DataDrivenPropertyValue<T>; using CascadingType = CascadingPaintProperty<ValueType>; - using UnevaluatedType = UnevaluatedPaintProperty<ValueType>; + using UnevaluatedType = TransitioningProperty<ValueType>; using EvaluatorType = DataDrivenPropertyEvaluator<T>; using EvaluatedType = PossiblyEvaluatedPropertyValue<T>; static constexpr bool IsDataDriven = true; @@ -172,7 +111,7 @@ class CrossFadedPaintProperty { public: using ValueType = PropertyValue<T>; using CascadingType = CascadingPaintProperty<ValueType>; - using UnevaluatedType = UnevaluatedPaintProperty<ValueType>; + using UnevaluatedType = TransitioningProperty<ValueType>; using EvaluatorType = CrossFadedPropertyEvaluator<T>; using EvaluatedType = Faded<T>; static constexpr bool IsDataDriven = false; |