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

Commit

Permalink
[core] generated accessor methods on light
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed May 8, 2017
1 parent 76a2b29 commit 0a0cba8
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 69 deletions.
5 changes: 5 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ set(MBGL_CORE_FILES
src/mbgl/style/layer_impl.hpp
src/mbgl/style/layer_observer.hpp
src/mbgl/style/layout_property.hpp
src/mbgl/style/light.cpp
src/mbgl/style/light_impl.cpp
src/mbgl/style/light_impl.hpp
src/mbgl/style/light_observer.hpp
src/mbgl/style/light_properties.hpp
src/mbgl/style/observer.hpp
src/mbgl/style/paint_property.hpp
src/mbgl/style/parser.cpp
Expand Down
16 changes: 8 additions & 8 deletions include/mbgl/style/conversion/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Converter<Light> {
convert<PropertyValue<LightAnchorType>>(*anchor, error);

if (convertedAnchor) {
light.get<LightAnchor>().value = *convertedAnchor;
light.setAnchor(*convertedAnchor);
} else {
return {};
}
Expand All @@ -39,7 +39,7 @@ struct Converter<Light> {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*anchorTransition, error);
if (transition) {
light.get<LightAnchor>().transition = *transition;
light.setAnchorTransition(*transition);
} else {
return {};
}
Expand All @@ -51,7 +51,7 @@ struct Converter<Light> {
convert<PropertyValue<Color>>(*color, error);

if (convertedColor) {
light.get<LightColor>().value = *convertedColor;
light.setColor(*convertedColor);
} else {
return {};
}
Expand All @@ -62,7 +62,7 @@ struct Converter<Light> {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*colorTransition, error);
if (transition) {
light.get<LightColor>().transition = *transition;
light.setColorTransition(*transition);
} else {
return {};
}
Expand All @@ -74,7 +74,7 @@ struct Converter<Light> {
convert<PropertyValue<Position>>(*position, error);

if (convertedPosition) {
light.get<LightPosition>().value = *convertedPosition;
light.setPosition(*convertedPosition);
} else {
return {};
}
Expand All @@ -85,7 +85,7 @@ struct Converter<Light> {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*positionTransition, error);
if (transition) {
light.get<LightPosition>().transition = *transition;
light.setPositionTransition(*transition);
} else {
return {};
}
Expand All @@ -97,7 +97,7 @@ struct Converter<Light> {
convert<PropertyValue<float>>(*intensity, error);

if (convertedIntensity) {
light.get<LightIntensity>().value = *convertedIntensity;
light.setIntensity(*convertedIntensity);
} else {
return {};
}
Expand All @@ -108,7 +108,7 @@ struct Converter<Light> {
optional<TransitionOptions> transition =
convert<TransitionOptions>(*intensityTransition, error);
if (transition) {
light.get<LightIntensity>().transition = *transition;
light.setIntensityTransition(*transition);
} else {
return {};
}
Expand Down
72 changes: 34 additions & 38 deletions include/mbgl/style/light.hpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
#pragma once
// This file is generated. Do not edit.

#pragma once
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/position.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/indexed_tuple.hpp>

namespace mbgl {
namespace style {

template <class T>
class LightProperty {
public:
using Type = T;
using ValueType = PropertyValue<T>;
class RenderLight;

PropertyValue<T> value;
TransitionOptions transition;
};

struct LightAnchor : LightProperty<LightAnchorType> {
static LightAnchorType defaultValue() {
return LightAnchorType::Viewport;
}
};

struct LightPosition : LightProperty<Position> {
static Position defaultValue() {
std::array<float, 3> default_ = { { 1.15, 210, 30 } };
return Position{ { default_ } };
}
};
namespace style {

struct LightColor : LightProperty<Color> {
static Color defaultValue() {
return Color::white();
}
};
class Light {
public:

struct LightIntensity : LightProperty<float> {
static float defaultValue() {
return 0.5;
}
static LightAnchorType getDefaultAnchor();
PropertyValue<LightAnchorType> getAnchor() const;
void setAnchor(PropertyValue<LightAnchorType>);
void setAnchorTransition(const TransitionOptions&);
TransitionOptions getAnchorTransition() const;

static Position getDefaultPosition();
PropertyValue<Position> getPosition() const;
void setPosition(PropertyValue<Position>);
void setPositionTransition(const TransitionOptions&);
TransitionOptions getPositionTransition() const;

static Color getDefaultColor();
PropertyValue<Color> getColor() const;
void setColor(PropertyValue<Color>);
void setColorTransition(const TransitionOptions&);
TransitionOptions getColorTransition() const;

static float getDefaultIntensity();
PropertyValue<float> getIntensity() const;
void setIntensity(PropertyValue<float>);
void setIntensityTransition(const TransitionOptions&);
TransitionOptions getIntensityTransition() const;

private:
IndexedTuple<LightProperties, LightProperties> properties;

friend class mbgl::RenderLight;
};

using LightProperties = TypeList<LightAnchor, LightPosition, LightColor, LightIntensity>;
class Light : public IndexedTuple<LightProperties, LightProperties> {};

} // namespace style
} // namespace mbgl
35 changes: 35 additions & 0 deletions include/mbgl/style/light.hpp.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%
const properties = locals.properties;
-%>
// This file is generated. Do not edit.

#pragma once
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>

namespace mbgl {

class RenderLight;

namespace style {

class Light {
public:

<% for (const property of properties) { -%>
static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>();
<%- propertyValueType(property) %> get<%- camelize(property.name) %>() const;
void set<%- camelize(property.name) %>(<%- propertyValueType(property) %>);
void set<%- camelize(property.name) %>Transition(const TransitionOptions&);
TransitionOptions get<%- camelize(property.name) %>Transition() const;
<% } -%>
private:
IndexedTuple<LightProperties, LightProperties> properties;
friend class mbgl::RenderLight;
};
} // namespace style
} // namespace mbgl
23 changes: 22 additions & 1 deletion scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ global.isDataDriven = function (property) {
return property['property-function'] === true;
};

global.isLightProperty = function (property) {
return property['light-property'] === true;
};

global.evaluatedType = function (property) {
if (/-translate-anchor$/.test(property.name)) {
return 'TranslateAnchorType';
}
if (/-(rotation|pitch|illumination)-alignment$/.test(property.name)) {
return 'AlignmentType';
}
if (/position/.test(property.name)) {
return 'Position';
}
switch (property.type) {
case 'boolean':
return 'bool';
Expand All @@ -33,7 +40,7 @@ global.evaluatedType = function (property) {
case 'string':
return 'std::string';
case 'enum':
return `${camelize(property.name)}Type`;
return (isLightProperty(property) ? 'Light' : '') + `${camelize(property.name)}Type`;
case 'color':
return `Color`;
case 'array':
Expand Down Expand Up @@ -177,3 +184,17 @@ for (const layer of layers) {

const propertySettersHpp = ejs.compile(fs.readFileSync('include/mbgl/style/conversion/make_property_setters.hpp.ejs', 'utf8'), {strict: true});
writeIfModified('include/mbgl/style/conversion/make_property_setters.hpp', propertySettersHpp({layers: layers}));

// Light
const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => {
var property = spec[`light`][name];
property.name = name;
property['light-property'] = true;
memo.push(property);
return memo;
}, []);

const lightHpp = ejs.compile(fs.readFileSync('include/mbgl/style/light.hpp.ejs', 'utf8'), {strict: true});
const lightCpp = ejs.compile(fs.readFileSync('src/mbgl/style/light.cpp.ejs', 'utf8'), {strict: true});
writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties}));
writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}));
2 changes: 1 addition & 1 deletion src/mbgl/renderer/render_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RenderLight::RenderLight(const style::Light light_)
}

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

void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) {
Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/renderer/render_light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class Evaluated<TypeList<Ps...>> : public IndexedTuple<
using TransitioningLight = Transitioning<style::LightProperties>;
using EvaluatedLight = Evaluated<style::LightProperties>;

class Painter;

class RenderLight {
public:
RenderLight(const style::Light);
Expand Down
115 changes: 115 additions & 0 deletions src/mbgl/style/light.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// This file is generated. Do not edit.

#include <mbgl/style/light.hpp>
#include <mbgl/style/light_impl.hpp>
#include <mbgl/style/light_properties.hpp>

namespace mbgl {
namespace style {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

} // namespace style
} // namespace mbgl
Loading

0 comments on commit 0a0cba8

Please sign in to comment.