Pass {Duration,TimePoint} by const ref if possible

This commit is contained in:
Bruno de Oliveira Abinader
2015-07-13 15:15:50 +03:00
parent 7d8b4dc6c0
commit 2aad2f4e14
19 changed files with 107 additions and 106 deletions

View File

@@ -79,8 +79,8 @@ public:
void setClasses(const std::vector<std::string>&);
std::vector<std::string> getClasses() const;
void setDefaultTransitionDuration(Duration = Duration::zero());
Duration getDefaultTransitionDuration();
void setDefaultTransitionDuration(const Duration& = Duration::zero());
Duration getDefaultTransitionDuration() const;
void setStyleURL(const std::string& url);
void setStyleJSON(const std::string& json, const std::string& base = "");
std::string getStyleURL() const;
@@ -91,27 +91,27 @@ public:
void setGestureInProgress(bool);
// Position
void moveBy(double dx, double dy, Duration = Duration::zero());
void setLatLng(LatLng latLng, Duration = Duration::zero());
void moveBy(double dx, double dy, const Duration& = Duration::zero());
void setLatLng(LatLng latLng, const Duration& = Duration::zero());
LatLng getLatLng() const;
void resetPosition();
// Scale
void scaleBy(double ds, double cx = -1, double cy = -1, Duration = Duration::zero());
void setScale(double scale, double cx = -1, double cy = -1, Duration = Duration::zero());
void scaleBy(double ds, double cx = -1, double cy = -1, const Duration& = Duration::zero());
void setScale(double scale, double cx = -1, double cy = -1, const Duration& = Duration::zero());
double getScale() const;
void setZoom(double zoom, Duration = Duration::zero());
void setZoom(double zoom, const Duration& = Duration::zero());
double getZoom() const;
void setLatLngZoom(LatLng latLng, double zoom, Duration = Duration::zero());
void fitBounds(LatLngBounds bounds, EdgeInsets padding, Duration duration = Duration::zero());
void fitBounds(AnnotationSegment segment, EdgeInsets padding, Duration duration = Duration::zero());
void setLatLngZoom(LatLng latLng, double zoom, const Duration& = Duration::zero());
void fitBounds(LatLngBounds bounds, EdgeInsets padding, const Duration& duration = Duration::zero());
void fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duration& duration = Duration::zero());
void resetZoom();
double getMinZoom() const;
double getMaxZoom() const;
// Rotation
void rotateBy(double sx, double sy, double ex, double ey, Duration = Duration::zero());
void setBearing(double degrees, Duration = Duration::zero());
void rotateBy(double sx, double sy, double ex, double ey, const Duration& = Duration::zero());
void setBearing(double degrees, const Duration& = Duration::zero());
void setBearing(double degrees, double cx, double cy);
double getBearing() const;
void resetNorth();

View File

@@ -116,12 +116,12 @@ void Map::setGestureInProgress(bool inProgress) {
#pragma mark - Position
void Map::moveBy(double dx, double dy, Duration duration) {
void Map::moveBy(double dx, double dy, const Duration& duration) {
transform->moveBy(dx, dy, duration);
update();
}
void Map::setLatLng(LatLng latLng, Duration duration) {
void Map::setLatLng(LatLng latLng, const Duration& duration) {
transform->setLatLng(latLng, duration);
update();
}
@@ -140,12 +140,12 @@ void Map::resetPosition() {
#pragma mark - Scale
void Map::scaleBy(double ds, double cx, double cy, Duration duration) {
void Map::scaleBy(double ds, double cx, double cy, const Duration& duration) {
transform->scaleBy(ds, cx, cy, duration);
update(Update::Zoom);
}
void Map::setScale(double scale, double cx, double cy, Duration duration) {
void Map::setScale(double scale, double cx, double cy, const Duration& duration) {
transform->setScale(scale, cx, cy, duration);
update(Update::Zoom);
}
@@ -154,7 +154,7 @@ double Map::getScale() const {
return transform->getScale();
}
void Map::setZoom(double zoom, Duration duration) {
void Map::setZoom(double zoom, const Duration& duration) {
transform->setZoom(zoom, duration);
update(Update::Zoom);
}
@@ -163,12 +163,12 @@ double Map::getZoom() const {
return transform->getZoom();
}
void Map::setLatLngZoom(LatLng latLng, double zoom, Duration duration) {
void Map::setLatLngZoom(LatLng latLng, double zoom, const Duration& duration) {
transform->setLatLngZoom(latLng, zoom, duration);
update(Update::Zoom);
}
void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, Duration duration) {
void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, const Duration& duration) {
AnnotationSegment segment = {
{bounds.ne.latitude, bounds.sw.longitude},
bounds.sw,
@@ -178,7 +178,7 @@ void Map::fitBounds(LatLngBounds bounds, EdgeInsets padding, Duration duration)
fitBounds(segment, padding, duration);
}
void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, Duration duration) {
void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duration& duration) {
if (segment.empty()) {
return;
}
@@ -243,12 +243,12 @@ uint16_t Map::getHeight() const {
#pragma mark - Rotation
void Map::rotateBy(double sx, double sy, double ex, double ey, Duration duration) {
void Map::rotateBy(double sx, double sy, double ex, double ey, const Duration& duration) {
transform->rotateBy(sx, sy, ex, ey, duration);
update();
}
void Map::setBearing(double degrees, Duration duration) {
void Map::setBearing(double degrees, const Duration& duration) {
transform->setAngle(-degrees * M_PI / 180, duration);
update();
}
@@ -416,12 +416,12 @@ std::vector<std::string> Map::getClasses() const {
return data->getClasses();
}
void Map::setDefaultTransitionDuration(Duration duration) {
void Map::setDefaultTransitionDuration(const Duration& duration) {
data->setDefaultTransitionDuration(duration);
update(Update::DefaultTransitionDuration);
}
Duration Map::getDefaultTransitionDuration() {
Duration Map::getDefaultTransitionDuration() const {
return data->getDefaultTransitionDuration();
}

View File

@@ -254,7 +254,7 @@ void MapContext::update() {
return;
}
TimePoint now = Clock::now();
const TimePoint now = Clock::now();
data.setAnimationTime(now);

View File

@@ -69,14 +69,15 @@ public:
// has a bug that doesn't allow TimePoints to be atomic.
return TimePoint(animationTime);
}
inline void setAnimationTime(TimePoint timePoint) {
inline void setAnimationTime(const TimePoint& timePoint) {
animationTime = timePoint.time_since_epoch();
};
inline Duration getDefaultTransitionDuration() const {
return defaultTransitionDuration;
}
inline void setDefaultTransitionDuration(Duration duration) {
inline void setDefaultTransitionDuration(const Duration& duration) {
defaultTransitionDuration = duration;
}

View File

@@ -53,7 +53,7 @@ bool Transform::resize(const std::array<uint16_t, 2> size) {
#pragma mark - Position
void Transform::moveBy(const double dx, const double dy, const Duration duration) {
void Transform::moveBy(const double dx, const double dy, const Duration& duration) {
if (std::isnan(dx) || std::isnan(dy)) {
return;
}
@@ -61,7 +61,7 @@ void Transform::moveBy(const double dx, const double dy, const Duration duration
_moveBy(dx, dy, duration);
}
void Transform::_moveBy(const double dx, const double dy, const Duration duration) {
void Transform::_moveBy(const double dx, const double dy, const Duration& duration) {
double x = state.x + std::cos(state.angle) * dx + std::sin( state.angle) * dy;
double y = state.y + std::cos(state.angle) * dy + std::sin(-state.angle) * dx;
@@ -95,7 +95,7 @@ void Transform::_moveBy(const double dx, const double dy, const Duration duratio
}
}
void Transform::setLatLng(const LatLng latLng, const Duration duration) {
void Transform::setLatLng(const LatLng latLng, const Duration& duration) {
if (std::isnan(latLng.latitude) || std::isnan(latLng.longitude)) {
return;
}
@@ -109,7 +109,7 @@ void Transform::setLatLng(const LatLng latLng, const Duration duration) {
_setScaleXY(state.scale, xn, yn, duration);
}
void Transform::setLatLngZoom(const LatLng latLng, const double zoom, const Duration duration) {
void Transform::setLatLngZoom(const LatLng latLng, const double zoom, const Duration& duration) {
if (std::isnan(latLng.latitude) || std::isnan(latLng.longitude) || std::isnan(zoom)) {
return;
}
@@ -132,7 +132,7 @@ void Transform::setLatLngZoom(const LatLng latLng, const double zoom, const Dura
#pragma mark - Zoom
void Transform::scaleBy(const double ds, const double cx, const double cy, const Duration duration) {
void Transform::scaleBy(const double ds, const double cx, const double cy, const Duration& duration) {
if (std::isnan(ds) || std::isnan(cx) || std::isnan(cy)) {
return;
}
@@ -149,7 +149,7 @@ void Transform::scaleBy(const double ds, const double cx, const double cy, const
}
void Transform::setScale(const double scale, const double cx, const double cy,
const Duration duration) {
const Duration& duration) {
if (std::isnan(scale) || std::isnan(cx) || std::isnan(cy)) {
return;
}
@@ -157,7 +157,7 @@ void Transform::setScale(const double scale, const double cx, const double cy,
_setScale(scale, cx, cy, duration);
}
void Transform::setZoom(const double zoom, const Duration duration) {
void Transform::setZoom(const double zoom, const Duration& duration) {
if (std::isnan(zoom)) {
return;
}
@@ -173,7 +173,7 @@ double Transform::getScale() const {
return state.scale;
}
void Transform::_setScale(double new_scale, double cx, double cy, const Duration duration) {
void Transform::_setScale(double new_scale, double cx, double cy, const Duration& duration) {
// Ensure that we don't zoom in further than the maximum allowed.
if (new_scale < state.min_scale) {
new_scale = state.min_scale;
@@ -205,7 +205,7 @@ void Transform::_setScale(double new_scale, double cx, double cy, const Duration
}
void Transform::_setScaleXY(const double new_scale, const double xn, const double yn,
const Duration duration) {
const Duration& duration) {
double scale = new_scale;
double x = xn;
double y = yn;
@@ -254,7 +254,7 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
#pragma mark - Angle
void Transform::rotateBy(const double start_x, const double start_y, const double end_x,
const double end_y, const Duration duration) {
const double end_y, const Duration& duration) {
if (std::isnan(start_x) || std::isnan(start_y) || std::isnan(end_x) || std::isnan(end_y)) {
return;
}
@@ -286,7 +286,7 @@ void Transform::rotateBy(const double start_x, const double start_y, const doubl
_setAngle(ang, duration);
}
void Transform::setAngle(const double new_angle, const Duration duration) {
void Transform::setAngle(const double new_angle, const Duration& duration) {
if (std::isnan(new_angle)) {
return;
}
@@ -314,7 +314,7 @@ void Transform::setAngle(const double new_angle, const double cx, const double c
}
}
void Transform::_setAngle(double new_angle, const Duration duration) {
void Transform::_setAngle(double new_angle, const Duration& duration) {
double angle = _normalizeAngle(new_angle, state.angle);
state.angle = _normalizeAngle(state.angle, angle);
@@ -352,7 +352,7 @@ double Transform::getAngle() const {
void Transform::startTransition(std::function<Update(double)> frame,
std::function<void()> finish,
Duration duration) {
const Duration& duration) {
if (transitionFinishFn) {
transitionFinishFn();
}
@@ -360,7 +360,7 @@ void Transform::startTransition(std::function<Update(double)> frame,
transitionStart = Clock::now();
transitionDuration = duration;
transitionFrameFn = [frame, this](TimePoint now) {
transitionFrameFn = [frame, this](const TimePoint now) {
float t = std::chrono::duration<float>(now - transitionStart) / transitionDuration;
if (t >= 1.0) {
Update result = frame(1.0);
@@ -381,7 +381,7 @@ bool Transform::needsTransition() const {
return !!transitionFrameFn;
}
UpdateType Transform::updateTransitions(const TimePoint now) {
UpdateType Transform::updateTransitions(const TimePoint& now) {
return static_cast<UpdateType>(transitionFrameFn ? transitionFrameFn(now) : Update::Nothing);
}

View File

@@ -23,27 +23,27 @@ public:
bool resize(std::array<uint16_t, 2> size);
// Position
void moveBy(double dx, double dy, Duration = Duration::zero());
void setLatLng(LatLng latLng, Duration = Duration::zero());
void setLatLngZoom(LatLng latLng, double zoom, Duration = Duration::zero());
void moveBy(double dx, double dy, const Duration& = Duration::zero());
void setLatLng(LatLng latLng, const Duration& = Duration::zero());
void setLatLngZoom(LatLng latLng, double zoom, const Duration& = Duration::zero());
inline const LatLng getLatLng() const { return state.getLatLng(); }
// Zoom
void scaleBy(double ds, double cx = -1, double cy = -1, Duration = Duration::zero());
void setScale(double scale, double cx = -1, double cy = -1, Duration = Duration::zero());
void setZoom(double zoom, Duration = Duration::zero());
void scaleBy(double ds, double cx = -1, double cy = -1, const Duration& = Duration::zero());
void setScale(double scale, double cx = -1, double cy = -1, const Duration& = Duration::zero());
void setZoom(double zoom, const Duration& = Duration::zero());
double getZoom() const;
double getScale() const;
// Angle
void rotateBy(double sx, double sy, double ex, double ey, Duration = Duration::zero());
void setAngle(double angle, Duration = Duration::zero());
void rotateBy(double sx, double sy, double ex, double ey, const Duration& = Duration::zero());
void setAngle(double angle, const Duration& = Duration::zero());
void setAngle(double angle, double cx, double cy);
double getAngle() const;
// Transitions
bool needsTransition() const;
UpdateType updateTransitions(TimePoint now);
UpdateType updateTransitions(const TimePoint& now);
void cancelTransitions();
// Gesture
@@ -53,10 +53,10 @@ public:
const TransformState getState() const { return state; }
private:
void _moveBy(double dx, double dy, Duration = Duration::zero());
void _setScale(double scale, double cx, double cy, Duration = Duration::zero());
void _setScaleXY(double new_scale, double xn, double yn, Duration = Duration::zero());
void _setAngle(double angle, Duration = Duration::zero());
void _moveBy(double dx, double dy, const Duration& = Duration::zero());
void _setScale(double scale, double cx, double cy, const Duration& = Duration::zero());
void _setScaleXY(double new_scale, double xn, double yn, const Duration& = Duration::zero());
void _setAngle(double angle, const Duration& = Duration::zero());
View &view;
@@ -64,11 +64,11 @@ private:
void startTransition(std::function<Update(double)> frame,
std::function<void()> finish,
Duration);
const Duration& duration);
TimePoint transitionStart;
Duration transitionDuration;
std::function<Update(TimePoint)> transitionFrameFn;
std::function<Update(const TimePoint)> transitionFrameFn;
std::function<void()> transitionFinishFn;
};

View File

@@ -3,7 +3,7 @@
using namespace mbgl;
// Record frame history that will be used to calculate fading params
void FrameHistory::record(TimePoint now, float zoom) {
void FrameHistory::record(const TimePoint& now, float zoom) {
// first frame ever
if (!history.size()) {
history.emplace_back(FrameSnapshot{TimePoint::min(), zoom});
@@ -15,7 +15,7 @@ void FrameHistory::record(TimePoint now, float zoom) {
}
}
bool FrameHistory::needsAnimation(const Duration duration) const {
bool FrameHistory::needsAnimation(const Duration& duration) const {
if (!history.size()) {
return false;
}
@@ -47,7 +47,7 @@ bool FrameHistory::needsAnimation(const Duration duration) const {
return false;
}
FadeProperties FrameHistory::getFadeProperties(Duration duration) {
FadeProperties FrameHistory::getFadeProperties(const Duration& duration) {
const TimePoint currentTime = Clock::now();
// Remove frames until only one is outside the duration, or until there are only three

View File

@@ -11,8 +11,8 @@
namespace mbgl {
struct FrameSnapshot {
explicit inline FrameSnapshot(TimePoint now_, float z_) : now(now_), z(z_) {}
TimePoint now;
explicit inline FrameSnapshot(const TimePoint& now_, float z_) : now(now_), z(z_) {}
const TimePoint now;
float z;
};
@@ -26,10 +26,10 @@ struct FadeProperties {
class FrameHistory {
public:
// Record frame history that will be used to calculate fading params
void record(TimePoint now, float zoom);
void record(const TimePoint& now, float zoom);
bool needsAnimation(Duration) const;
FadeProperties getFadeProperties(Duration);
bool needsAnimation(const Duration& duration) const;
FadeProperties getFadeProperties(const Duration& duration);
public:
std::deque<FrameSnapshot> history;

View File

@@ -165,7 +165,7 @@ void Painter::prepareTile(const Tile& tile) {
config.stencilFunc = { GL_EQUAL, ref, mask };
}
void Painter::render(const Style& style, TransformState state_, const FrameData& frame_, TimePoint time) {
void Painter::render(const Style& style, TransformState state_, const FrameData& frame_, const TimePoint& time) {
state = state_;
frame = frame_;

View File

@@ -96,7 +96,7 @@ public:
void render(const Style& style,
TransformState state,
const FrameData& frame,
TimePoint time);
const TimePoint& time);
// Renders debug information for a tile.
void renderTileDebug(const Tile& tile);

View File

@@ -2,7 +2,7 @@
namespace mbgl {
AppliedClassProperty::AppliedClassProperty(ClassID class_id, TimePoint begin_, TimePoint end_, const PropertyValue &value_)
AppliedClassProperty::AppliedClassProperty(ClassID class_id, const TimePoint& begin_, const TimePoint& end_, const PropertyValue &value_)
: name(class_id),
begin(begin_),
end(end_),
@@ -13,7 +13,7 @@ ClassID AppliedClassProperties::mostRecent() const {
return propertyValues.empty() ? ClassID::Fallback : propertyValues.back().name;
}
void AppliedClassProperties::add(ClassID class_id, TimePoint begin, TimePoint end, const PropertyValue &value) {
void AppliedClassProperties::add(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value) {
propertyValues.emplace_back(class_id, begin, end, value);
}
@@ -23,7 +23,7 @@ bool AppliedClassProperties::hasTransitions() const {
// Erase all items in the property list that are before a completed transition.
// Then, if the only remaining property is a Fallback value, remove it too.
void AppliedClassProperties::cleanup(TimePoint now) {
void AppliedClassProperties::cleanup(const TimePoint& now) {
// Iterate backwards, but without using the rbegin/rend interface since we need forward
// iterators to use .erase().
for (auto it = propertyValues.end(), begin = propertyValues.begin(); it != begin;) {

View File

@@ -11,7 +11,7 @@ namespace mbgl {
class AppliedClassProperty {
public:
AppliedClassProperty(ClassID class_id, TimePoint begin, TimePoint end, const PropertyValue &value);
AppliedClassProperty(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value);
public:
const ClassID name;
@@ -28,8 +28,8 @@ public:
public:
// Returns the ID of the most recent
ClassID mostRecent() const;
void add(ClassID class_id, TimePoint begin, TimePoint end, const PropertyValue &value);
void cleanup(TimePoint now);
void add(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value);
void cleanup(const TimePoint& now);
bool hasTransitions() const;
bool empty() const;
};

View File

@@ -86,13 +86,13 @@ void Style::update(const TransformState& transform,
}
}
void Style::cascade(const std::vector<std::string>& classes, TimePoint now) {
void Style::cascade(const std::vector<std::string>& classes, const TimePoint& now) {
for (const auto& layer : layers) {
layer->setClasses(classes, now, defaultTransition);
}
}
void Style::recalculate(float z, TimePoint now) {
void Style::recalculate(float z, const TimePoint& now) {
uv::writelock lock(mtx);
for (const auto& source : sources) {

View File

@@ -54,8 +54,8 @@ public:
// a tile is ready so observers can render the tile.
void update(const TransformState&, TexturePool&);
void cascade(const std::vector<std::string>&, TimePoint now);
void recalculate(float z, TimePoint now);
void cascade(const std::vector<std::string>&, const TimePoint& now);
void recalculate(float z, const TimePoint& now);
void setDefaultTransitionDuration(Duration);
bool hasTransitions() const;

View File

@@ -28,7 +28,7 @@ bool StyleLayer::isVisible() const {
}
}
void StyleLayer::setClasses(const std::vector<std::string> &class_names, const TimePoint now,
void StyleLayer::setClasses(const std::vector<std::string> &class_names, const TimePoint& now,
const PropertyTransition &defaultTransition) {
// Stores all keys that we have already added transitions for.
std::set<PropertyKey> already_applied;
@@ -69,7 +69,7 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const T
// Helper function for applying all properties of a a single class that haven't been applied yet.
void StyleLayer::applyClassProperties(const ClassID class_id,
std::set<PropertyKey> &already_applied, TimePoint now,
std::set<PropertyKey> &already_applied, const TimePoint& now,
const PropertyTransition &defaultTransition) {
auto style_it = styles.find(class_id);
if (style_it == styles.end()) {
@@ -134,7 +134,7 @@ private:
};
template <typename T>
void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
auto it = appliedStyle.find(key);
if (it != appliedStyle.end()) {
AppliedClassProperties &applied = it->second;
@@ -152,7 +152,7 @@ void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, c
}
template <typename T>
void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
auto it = appliedStyle.find(key);
if (it != appliedStyle.end()) {
AppliedClassProperties &applied = it->second;
@@ -174,7 +174,7 @@ void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, cons
}
template <>
void StyleLayer::applyStyleProperties<FillProperties>(const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyStyleProperties<FillProperties>(const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
properties.set<FillProperties>();
FillProperties &fill = properties.get<FillProperties>();
applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, now, zoomHistory);
@@ -187,7 +187,7 @@ void StyleLayer::applyStyleProperties<FillProperties>(const float z, const TimeP
}
template <>
void StyleLayer::applyStyleProperties<LineProperties>(const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyStyleProperties<LineProperties>(const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
properties.set<LineProperties>();
LineProperties &line = properties.get<LineProperties>();
applyTransitionedStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now, zoomHistory);
@@ -201,11 +201,11 @@ void StyleLayer::applyStyleProperties<LineProperties>(const float z, const TimeP
applyStyleProperty(PropertyKey::LineImage, line.image, z, now, zoomHistory);
// for scaling dasharrays
applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), TimePoint::max(), zoomHistory);
applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), now, zoomHistory);
}
template <>
void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
properties.set<SymbolProperties>();
SymbolProperties &symbol = properties.get<SymbolProperties>();
applyTransitionedStyleProperty(PropertyKey::IconOpacity, symbol.icon.opacity, z, now, zoomHistory);
@@ -228,7 +228,7 @@ void StyleLayer::applyStyleProperties<SymbolProperties>(const float z, const Tim
}
template <>
void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
properties.set<RasterProperties>();
RasterProperties &raster = properties.get<RasterProperties>();
applyTransitionedStyleProperty(PropertyKey::RasterOpacity, raster.opacity, z, now, zoomHistory);
@@ -241,7 +241,7 @@ void StyleLayer::applyStyleProperties<RasterProperties>(const float z, const Tim
}
template <>
void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const TimePoint now, const ZoomHistory &zoomHistory) {
void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const TimePoint& now, const ZoomHistory &zoomHistory) {
properties.set<BackgroundProperties>();
BackgroundProperties &background = properties.get<BackgroundProperties>();
applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now, zoomHistory);
@@ -249,7 +249,7 @@ void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const
applyStyleProperty(PropertyKey::BackgroundImage, background.image, z, now, zoomHistory);
}
void StyleLayer::updateProperties(float z, const TimePoint now, ZoomHistory &zoomHistory) {
void StyleLayer::updateProperties(float z, const TimePoint& now, ZoomHistory &zoomHistory) {
cleanupAppliedStyleProperties(now);
switch (type) {
@@ -271,7 +271,7 @@ bool StyleLayer::hasTransitions() const {
return false;
}
void StyleLayer::cleanupAppliedStyleProperties(TimePoint now) {
void StyleLayer::cleanupAppliedStyleProperties(const TimePoint& now) {
for (auto it = appliedStyle.begin(); it != appliedStyle.end();) {
AppliedClassProperties& appliedPropertyValues = it->second;
appliedPropertyValues.cleanup(now);

View File

@@ -40,10 +40,10 @@ public:
// Updates the StyleProperties information in this layer by evaluating all
// pending transitions and applied classes in order.
void updateProperties(float z, TimePoint now, ZoomHistory &zoomHistory);
void updateProperties(float z, const TimePoint& now, ZoomHistory &zoomHistory);
// Sets the list of classes and creates transitions to the currently applied values.
void setClasses(const std::vector<std::string> &class_names, TimePoint now,
void setClasses(const std::vector<std::string> &class_names, const TimePoint& now,
const PropertyTransition &defaultTransition);
bool hasTransitions() const;
@@ -51,16 +51,16 @@ public:
private:
// Applies all properties from a class, if they haven't been applied already.
void applyClassProperties(ClassID class_id, std::set<PropertyKey> &already_applied,
TimePoint now, const PropertyTransition &defaultTransition);
const TimePoint& now, const PropertyTransition &defaultTransition);
// Sets the properties of this object by evaluating all pending transitions and
// aplied classes in order.
template <typename T> void applyStyleProperties(float z, TimePoint now, const ZoomHistory &zoomHistory);
template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, TimePoint now, const ZoomHistory &zoomHistory);
template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, TimePoint now, const ZoomHistory &zoomHistory);
template <typename T> void applyStyleProperties(float z, const TimePoint& now, const ZoomHistory &zoomHistory);
template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, const TimePoint& now, const ZoomHistory &zoomHistory);
template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, const TimePoint& now, const ZoomHistory &zoomHistory);
// Removes all expired style transitions.
void cleanupAppliedStyleProperties(TimePoint now);
void cleanupAppliedStyleProperties(const TimePoint& now);
public:
// The name of this layer.

View File

@@ -13,12 +13,12 @@ struct ZoomHistory {
TimePoint lastIntegerZoomTime;
bool first = true;
void update(float z, TimePoint now) {
void update(float z, const TimePoint& now) {
if (first) {
first = false;
lastIntegerZoom = std::floor(z);
lastIntegerZoomTime = TimePoint(Duration(0));
lastIntegerZoomTime = TimePoint(Duration::zero());
lastZoom = z;
}

View File

@@ -10,7 +10,7 @@ UnitBezier ease(0, 0, 0.25, 1);
transition::~transition() {}
template <typename T>
transition::state ease_transition<T>::update(TimePoint now) const {
transition::state ease_transition<T>::update(const TimePoint& now) const {
float t = progress(now);
if (t >= 1) {
value = to;

View File

@@ -14,18 +14,18 @@ public:
complete
};
inline transition(TimePoint start_, Duration duration_)
inline transition(const TimePoint& start_, const Duration& duration_)
: start(start_),
duration(duration_) {}
inline float progress(TimePoint now) const {
inline float progress(const TimePoint& now) const {
if (duration == Duration::zero()) return 1;
if (start > now) return 0;
return std::chrono::duration<float>(now - start) / duration;
}
virtual state update(TimePoint now) const = 0;
virtual state update(const TimePoint& now) const = 0;
virtual ~transition();
protected:
@@ -36,13 +36,13 @@ protected:
template <typename T>
class ease_transition : public transition {
public:
ease_transition(T from_, T to_, T& value_, TimePoint start_, Duration duration_)
ease_transition(T from_, T to_, T& value_, const TimePoint& start_, const Duration& duration_)
: transition(start_, duration_),
from(from_),
to(to_),
value(value_) {}
state update(TimePoint now) const;
state update(const TimePoint& now) const;
private:
const T from, to;
@@ -53,12 +53,12 @@ private:
template <typename T>
class timeout : public transition {
public:
timeout(T final_value_, T& value_, TimePoint start_, Duration duration_)
timeout(T final_value_, T& value_, const TimePoint& start_, const Duration& duration_)
: transition(start_, duration_),
final_value(final_value_),
value(value_) {}
state update(TimePoint now) const {
state update(const TimePoint& now) const {
if (progress(now) >= 1) {
value = final_value;
return complete;