summaryrefslogtreecommitdiff
path: root/src/mbgl/style/light_impl.hpp
blob: d1825090fce1ff51dbc75573f83a6ec8b247ee4d (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
#pragma once

#include <mbgl/style/light.hpp>
#include <mbgl/style/transitioning_property.hpp>
#include <mbgl/style/cascade_parameters.hpp>
#include <mbgl/style/property_evaluator.hpp>
#include <mbgl/style/property_evaluation_parameters.hpp>
#include <mbgl/util/ignore.hpp>

namespace mbgl {
namespace style {

template <class TypeList>
class Transitioning;

template <class... Ps>
class Transitioning<TypeList<Ps...>> : public IndexedTuple<
    TypeList<Ps...>,
    TypeList<TransitioningProperty<typename Ps::ValueType>...>>
{
private:
    using Properties = TypeList<Ps...>;
    using Raw = IndexedTuple<Properties, Properties>;
    using Super = IndexedTuple<
        TypeList<Ps...>,
        TypeList<TransitioningProperty<typename Ps::ValueType>...>>;

public:
    Transitioning() = default;
    Transitioning(const Raw& raw, Transitioning&& prior, const CascadeParameters& params)
        : Super {
            TransitioningProperty<typename Ps::ValueType>(
                raw.template get<Ps>().value,
                std::move(prior.template get<Ps>()),
                raw.template get<Ps>().transition.reverseMerge(params.transition),
                params.now)...
        } {}

    bool hasTransition() const {
        bool result = false;
        util::ignore({ result |= this->template get<Ps>().hasTransition()... });
        return result;
    }
};

template <class TypeList>
class Evaluated;

template <class... Ps>
class Evaluated<TypeList<Ps...>> : public IndexedTuple<
    TypeList<Ps...>,
    TypeList<typename Ps::Type...>>
{
private:
    using Properties = TypeList<Ps...>;
    using TransitioningPs = Transitioning<Properties>;
    using Super = IndexedTuple<
        TypeList<Ps...>,
        TypeList<typename Ps::Type...>>;

public:
    Evaluated() = default;
    Evaluated(TransitioningPs& transitioning, const PropertyEvaluationParameters& params)
        : Super {
            transitioning.template get<Ps>()
                .evaluate(PropertyEvaluator<typename Ps::Type>(params, Ps::defaultValue()), params.now)...
        } {}
};

using TransitioningLight = Transitioning<LightProperties>;
using EvaluatedLight     = Evaluated<LightProperties>;

} // namespace style
} // namespace mbgl