Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] delegate light changes to render light
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed May 8, 2017
1 parent 0a0cba8 commit d70a047
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/style/conversion/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct Converter<Light> {
return {};
}
}
return { light };
return { std::move(light) };
};
};

Expand Down
15 changes: 8 additions & 7 deletions include/mbgl/style/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>

namespace mbgl {

class RenderLight;
#include <memory>

namespace mbgl {
namespace style {

class Light {
public:

class Impl;

Light();
~Light();

static LightAnchorType getDefaultAnchor();
PropertyValue<LightAnchorType> getAnchor() const;
void setAnchor(PropertyValue<LightAnchorType>);
Expand All @@ -38,10 +42,7 @@ class Light {
void setIntensityTransition(const TransitionOptions&);
TransitionOptions getIntensityTransition() const;

private:
IndexedTuple<LightProperties, LightProperties> properties;

friend class mbgl::RenderLight;
std::shared_ptr<Impl> impl;
};

} // namespace style
Expand Down
15 changes: 8 additions & 7 deletions include/mbgl/style/light.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>

namespace mbgl {

class RenderLight;
#include <memory>

namespace mbgl {
namespace style {

class Light {
public:

class Impl;

Light();
~Light();

<% for (const property of properties) { -%>
static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>();
<%- propertyValueType(property) %> get<%- camelize(property.name) %>() const;
Expand All @@ -25,10 +29,7 @@ public:
TransitionOptions get<%- camelize(property.name) %>Transition() const;
<% } -%>
private:
IndexedTuple<LightProperties, LightProperties> properties;
friend class mbgl::RenderLight;
std::shared_ptr<Impl> impl;
};
} // namespace style
Expand Down
15 changes: 12 additions & 3 deletions src/mbgl/renderer/render_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

namespace mbgl {

RenderLight::RenderLight(const style::Light light_)
: light(std::move(light_)) {
RenderLight::RenderLight(std::shared_ptr<const style::Light::Impl> impl_)
: impl(std::move(impl_)) {
}

RenderLight::RenderLight(std::shared_ptr<const style::Light::Impl> impl_, const TransitioningLight transitioning_)
: impl(std::move(impl_))
, transitioning(transitioning_) {
}

std::unique_ptr<RenderLight> RenderLight::copy(std::shared_ptr<const style::Light::Impl> impl_) const {
return std::make_unique<RenderLight>(std::move(impl_), transitioning);
}

void RenderLight::transition(const CascadeParameters& parameters) {
transitioning = TransitioningLight(light.properties, std::move(transitioning), parameters);
transitioning = TransitioningLight(impl->properties, std::move(transitioning), parameters);
}

void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) {
Expand Down
18 changes: 15 additions & 3 deletions src/mbgl/renderer/render_light.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once

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

#include <memory>

namespace mbgl {

template <class TypeList>
Expand Down Expand Up @@ -71,18 +74,27 @@ using EvaluatedLight = Evaluated<style::LightProperties>;

class RenderLight {
public:
RenderLight(const style::Light);
RenderLight(std::shared_ptr<const style::Light::Impl>);

// Creates a copy intitalized with previous transitioning light
RenderLight(std::shared_ptr<const style::Light::Impl>, const TransitioningLight);

// creates a copy initialized with previous transitioning
// values
std::unique_ptr<RenderLight> copy(std::shared_ptr<const style::Light::Impl>) const;

void transition(const CascadeParameters&);
void evaluate(const PropertyEvaluationParameters&);
bool hasTransition() const;

const EvaluatedLight& getEvaluated() const;

const std::shared_ptr<const style::Light::Impl> impl;

private:

TransitioningLight transitioning;
EvaluatedLight evaluated;
style::Light light;
};

} // namespace mbgl
71 changes: 31 additions & 40 deletions src/mbgl/style/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,109 +7,100 @@
namespace mbgl {
namespace style {

Light::Light()
: impl(std::make_unique<Impl>()) {
}

Light::~Light() = default;

LightAnchorType Light::getDefaultAnchor() {
return LightAnchor::defaultValue();
}

PropertyValue<LightAnchorType> Light::getAnchor() const {
return properties.get<LightAnchor>().value;
return impl->properties.template get<LightAnchor>().value;
}

void Light::setAnchor(PropertyValue<LightAnchorType> property) {
properties.get<LightAnchor>().value = property;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightAnchor>().value = property;
impl->observer->onLightChanged(*this);
}

void Light::setAnchorTransition(const TransitionOptions& transition) {
properties.get<LightAnchor>().transition = transition;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightAnchor>().transition = transition;
impl->observer->onLightChanged(*this);
}

TransitionOptions Light::getAnchorTransition() const {
return properties.get<LightAnchor>().transition;
return impl->properties.template get<LightAnchor>().transition;
}

Position Light::getDefaultPosition() {
return LightPosition::defaultValue();
}

PropertyValue<Position> Light::getPosition() const {
return properties.get<LightPosition>().value;
return impl->properties.template get<LightPosition>().value;
}

void Light::setPosition(PropertyValue<Position> property) {
properties.get<LightPosition>().value = property;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightPosition>().value = property;
impl->observer->onLightChanged(*this);
}

void Light::setPositionTransition(const TransitionOptions& transition) {
properties.get<LightPosition>().transition = transition;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightPosition>().transition = transition;
impl->observer->onLightChanged(*this);
}

TransitionOptions Light::getPositionTransition() const {
return properties.get<LightPosition>().transition;
return impl->properties.template get<LightPosition>().transition;
}

Color Light::getDefaultColor() {
return LightColor::defaultValue();
}

PropertyValue<Color> Light::getColor() const {
return properties.get<LightColor>().value;
return impl->properties.template get<LightColor>().value;
}

void Light::setColor(PropertyValue<Color> property) {
properties.get<LightColor>().value = property;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightColor>().value = property;
impl->observer->onLightChanged(*this);
}

void Light::setColorTransition(const TransitionOptions& transition) {
properties.get<LightColor>().transition = transition;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightColor>().transition = transition;
impl->observer->onLightChanged(*this);
}

TransitionOptions Light::getColorTransition() const {
return properties.get<LightColor>().transition;
return impl->properties.template get<LightColor>().transition;
}

float Light::getDefaultIntensity() {
return LightIntensity::defaultValue();
}

PropertyValue<float> Light::getIntensity() const {
return properties.get<LightIntensity>().value;
return impl->properties.template get<LightIntensity>().value;
}

void Light::setIntensity(PropertyValue<float> property) {
properties.get<LightIntensity>().value = property;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightIntensity>().value = property;
impl->observer->onLightChanged(*this);
}

void Light::setIntensityTransition(const TransitionOptions& transition) {
properties.get<LightIntensity>().transition = transition;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<LightIntensity>().transition = transition;
impl->observer->onLightChanged(*this);
}

TransitionOptions Light::getIntensityTransition() const {
return properties.get<LightIntensity>().transition;
return impl->properties.template get<LightIntensity>().transition;
}


} // namespace style
} // namespace mbgl
23 changes: 13 additions & 10 deletions src/mbgl/style/light.cpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,36 @@
namespace mbgl {
namespace style {

Light::Light()
: impl(std::make_unique<Impl>()) {
}

Light::~Light() = default;

<% for (const property of properties) { -%>
<%- evaluatedType(property) %> Light::getDefault<%- camelize(property.name) %>() {
return Light<%- camelize(property.name) %>::defaultValue();
}
<%- propertyValueType(property) %> Light::get<%- camelize(property.name) %>() const {
return properties.get<Light<%- camelize(property.name) %>>().value;
return impl->properties.template get<Light<%- camelize(property.name) %>>().value;
}
void Light::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> property) {
properties.get<Light<%- camelize(property.name) %>>().value = property;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<Light<%- camelize(property.name) %>>().value = property;
impl->observer->onLightChanged(*this);
}

void Light::set<%- camelize(property.name) %>Transition(const TransitionOptions& transition) {
properties.get<Light<%- camelize(property.name) %>>().transition = transition;
if (observer) {
observer->onLightChanged(*this);
}
impl->properties.template get<Light<%- camelize(property.name) %>>().transition = transition;
impl->observer->onLightChanged(*this);
}

TransitionOptions Light::get<%- camelize(property.name) %>Transition() const {
return properties.get<Light<%- camelize(property.name) %>>().transition;
return impl->properties.template get<Light<%- camelize(property.name) %>>().transition;
}

<% } -%>

} // namespace style
} // namespace mbgl
11 changes: 11 additions & 0 deletions src/mbgl/style/light_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <mbgl/style/light_impl.hpp>

namespace mbgl {
namespace style {

void Light::Impl::setObserver(LightObserver* observer_) {
observer = observer_;
}

} // namespace style
} // namespace mbgl
20 changes: 20 additions & 0 deletions src/mbgl/style/light_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <mbgl/style/light_properties.hpp>
#include <mbgl/style/light_observer.hpp>

namespace mbgl {
namespace style {

class Light::Impl {
public:

LightObserver nullObserver;
LightObserver* observer = &nullObserver;
void setObserver(LightObserver*);

IndexedTuple<LightProperties, LightProperties> properties;
};

} // namespace style
} // namespace mbgl
16 changes: 16 additions & 0 deletions src/mbgl/style/light_observer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <mbgl/style/light.hpp>

namespace mbgl {
namespace style {

class LightObserver {
public:
virtual ~LightObserver() = default;

virtual void onLightChanged(const Light&) {}
};

} // namespace style
} // namespace mbgl
2 changes: 1 addition & 1 deletion src/mbgl/style/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void Parser::parseLight(const JSValue& value) {
return;
}

light = *converted;
light = std::move(*converted);
}

void Parser::parseSources(const JSValue& value) {
Expand Down
Loading

0 comments on commit d70a047

Please sign in to comment.