Rework easing transition code

This brings the easing transition code a bit closer to how easings work
in gl-js. Instead of having an array of individual transitions for scale,
rotate, and pan, there is a single transition function that does all the
required calculations. This permits us to:

* Eliminate the "timeout" transition. (Fixes #126)
* Replace start/stopPanning() et al with setGestureInProgress(). Apps or
  SDKs are expected to make paired calls to setGestureInProgress(). This
  state will be ORed with the active easing state to determine when to
  use texture interpolation. (Fixes #79)
* Run style recalculations only when an ease transition that affects the
  zoom is in progress. (Fixes #1155)
This commit is contained in:
John Firebaugh
2015-04-01 13:49:35 -07:00
parent 9e38d7cc2b
commit 12c07b916b
11 changed files with 154 additions and 287 deletions

View File

@@ -7,7 +7,6 @@
#include <mbgl/renderer/painter.hpp>
#include <mbgl/map/annotation.hpp>
#include <mbgl/map/sprite.hpp>
#include <mbgl/util/transition.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/clip_ids.hpp>
#include <mbgl/util/string.hpp>
@@ -72,7 +71,8 @@ Map::Map(View& view_, FileSource& fileSource_)
texturePool(std::make_shared<TexturePool>()),
painter(util::make_unique<Painter>(*spriteAtlas, *glyphAtlas, *lineAtlas)),
annotationManager(util::make_unique<AnnotationManager>()),
data(util::make_unique<MapData>())
data(util::make_unique<MapData>()),
updated(static_cast<UpdateType>(Update::Nothing))
{
view.initialize(this);
}
@@ -449,10 +449,13 @@ void Map::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth,
void Map::cancelTransitions() {
transform.cancelTransitions();
triggerUpdate();
}
void Map::setGestureInProgress(bool inProgress) {
transform.setGestureInProgress(inProgress);
triggerUpdate();
}
#pragma mark - Position
@@ -470,21 +473,11 @@ LatLng Map::getLatLng() const {
return state.getLatLng();
}
void Map::startPanning() {
transform.startPanning();
triggerUpdate();
}
void Map::stopPanning() {
transform.stopPanning();
triggerUpdate();
}
void Map::resetPosition() {
transform.setAngle(0);
transform.setLatLng(LatLng(0, 0));
transform.setZoom(0);
triggerUpdate();
triggerUpdate(Update::Zoom);
}
@@ -492,12 +485,12 @@ void Map::resetPosition() {
void Map::scaleBy(double ds, double cx, double cy, Duration duration) {
transform.scaleBy(ds, cx, cy, duration);
triggerUpdate();
triggerUpdate(Update::Zoom);
}
void Map::setScale(double scale, double cx, double cy, Duration duration) {
transform.setScale(scale, cx, cy, duration);
triggerUpdate();
triggerUpdate(Update::Zoom);
}
double Map::getScale() const {
@@ -506,7 +499,7 @@ double Map::getScale() const {
void Map::setZoom(double zoom, Duration duration) {
transform.setZoom(zoom, duration);
triggerUpdate();
triggerUpdate(Update::Zoom);
}
double Map::getZoom() const {
@@ -515,23 +508,13 @@ double Map::getZoom() const {
void Map::setLatLngZoom(LatLng latLng, double zoom, Duration duration) {
transform.setLatLngZoom(latLng, zoom, duration);
triggerUpdate();
triggerUpdate(Update::Zoom);
}
void Map::resetZoom() {
setZoom(0);
}
void Map::startScaling() {
transform.startScaling();
triggerUpdate();
}
void Map::stopScaling() {
transform.stopScaling();
triggerUpdate();
}
double Map::getMinZoom() const {
return transform.getMinZoom();
}
@@ -567,16 +550,6 @@ void Map::resetNorth() {
triggerUpdate();
}
void Map::startRotating() {
transform.startRotating();
triggerUpdate();
}
void Map::stopRotating() {
transform.stopRotating();
triggerUpdate();
}
#pragma mark - Access Token
void Map::setAccessToken(const std::string &token) {
@@ -802,44 +775,49 @@ void Map::loadStyleJSON(const std::string& json, const std::string& base) {
const std::string glyphURL = util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken());
glyphStore->setURL(glyphURL);
triggerUpdate();
triggerUpdate(Update::Zoom);
}
void Map::prepare() {
assert(Environment::currentlyOn(ThreadType::Map));
const auto u = updated.exchange(static_cast<UpdateType>(Update::Nothing));
if ((u & static_cast<UpdateType>(Update::StyleInfo)) || !style) {
reloadStyle();
}
if (u & static_cast<UpdateType>(Update::Debug)) {
assert(painter);
painter->setDebug(data->getDebug());
}
if (u & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
if (style) {
style->setDefaultTransitionDuration(data->getDefaultTransitionDuration());
}
}
if (u & static_cast<UpdateType>(Update::Classes)) {
if (style) {
style->cascade(data->getClasses());
}
}
const auto now = Clock::now();
data->setAnimationTime(now);
// Update transform transitions.
auto u = updated.exchange(static_cast<UpdateType>(Update::Nothing)) |
transform.updateTransitions(now);
const auto animationTime = Clock::now();
data->setAnimationTime(animationTime);
if (transform.needsTransition()) {
transform.updateTransitions(animationTime);
if (!style) {
u |= static_cast<UpdateType>(Update::StyleInfo);
}
state = transform.currentState();
if (u & static_cast<UpdateType>(Update::StyleInfo)) {
reloadStyle();
}
if (u & static_cast<UpdateType>(Update::Debug)) {
assert(painter);
painter->setDebug(data->getDebug());
}
if (style) {
if (u & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
style->setDefaultTransitionDuration(data->getDefaultTransitionDuration());
}
if (u & static_cast<UpdateType>(Update::Classes)) {
style->cascade(data->getClasses());
}
if (u & static_cast<UpdateType>(Update::StyleInfo) ||
u & static_cast<UpdateType>(Update::Classes) ||
u & static_cast<UpdateType>(Update::Zoom)) {
style->recalculate(state.getNormalizedZoom(), now);
}
updateSources();
style->recalculate(state.getNormalizedZoom(), animationTime);
// Allow the sprite atlas to potentially pull new sprite images if needed.
spriteAtlas->resize(state.getPixelRatio());
@@ -863,6 +841,7 @@ void Map::render() {
assert(painter);
painter->render(*style, activeSources,
state, data->getAnimationTime());
// Schedule another rerender when we definitely need a next frame.
if (transform.needsTransition() || style->hasTransitions()) {
triggerUpdate();