From eed7a850c5a984239fd3ae11e65531edf8247cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 19 Jan 2016 17:16:51 -0800 Subject: [PATCH 1/3] [core] Non-animated transforms during transform animation Allow non-animated changes to occur during a transform animation without canceling that animation. --- include/mbgl/map/camera.hpp | 14 +++++++++----- src/mbgl/map/transform.cpp | 34 ++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index a1b9bfe691a..e6300efd695 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -58,13 +58,17 @@ struct AnimationOptions { /** The easing timing curve of the transition. */ optional easing; - /** A function that is called on each frame of the transition, just before a - screen update, except on the last frame. The first parameter indicates - the elapsed time as a percentage of the duration. */ + /** A function that is called from the Map thread on each frame of the + transition, just before a screen update, except on the last frame. The + first parameter indicates the elapsed time as a percentage of the + duration. */ std::function transitionFrameFn; - /** A function that is called once on the last frame of the transition, just - before the corresponding screen update. */ + /** A function that is called once from the Map thread on the last frame of + the transition, just before the corresponding screen update. The first + parameter indicates how much of the transition was completed, as a + percentage of the duration. In the event that the transition is + canceled, this parameter will have a value less than 1.0. */ std::function transitionFinishFn; /** Creates an animation with no options specified. */ diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 6ec387ac23a..67d248ca38d 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -553,11 +553,11 @@ void Transform::startTransition(const CameraOptions& camera, const AnimationOptions& animation, std::function frame, const Duration& duration) { - if (transitionFinishFn) { + bool isAnimated = duration != Duration::zero(); + if (isAnimated && transitionFinishFn) { transitionFinishFn(); } - bool isAnimated = duration != Duration::zero(); view.notifyMapChange(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange); // Associate the anchor, if given, with a coordinate. @@ -567,12 +567,8 @@ void Transform::startTransition(const CameraOptions& camera, anchor.y = state.getHeight() - anchor.y; anchorLatLng = state.pointToLatLng(anchor); } - - transitionStart = Clock::now(); - transitionDuration = duration; - - transitionFrameFn = [isAnimated, animation, frame, anchor, anchorLatLng, this](const TimePoint now) { - float t = isAnimated ? (std::chrono::duration(now - transitionStart) / transitionDuration) : 1.0; + + auto frameFn = [animation, frame, anchor, anchorLatLng, this](double t) { Update result; if (t >= 1.0) { result = frame(1.0); @@ -584,6 +580,24 @@ void Transform::startTransition(const CameraOptions& camera, if (_validPoint(anchor)) { state.moveLatLng(anchorLatLng, anchor); } + return result; + }; + + if (!isAnimated) { + view.notifyMapChange(MapChangeRegionWillChange); + frameFn(1.0); + view.notifyMapChange(MapChangeRegionDidChange); + return; + } + + view.notifyMapChange(MapChangeRegionWillChangeAnimated); + + transitionStart = Clock::now(); + transitionDuration = duration; + + transitionFrameFn = [isAnimated, animation, frame, anchor, anchorLatLng, frameFn, this](const TimePoint now) { + float t = isAnimated ? (std::chrono::duration(now - transitionStart) / transitionDuration) : 1.0; + Update result = frameFn(t); // At t = 1.0, a DidChangeAnimated notification should be sent from finish(). if (t < 1.0) { @@ -611,10 +625,6 @@ void Transform::startTransition(const CameraOptions& camera, } view.notifyMapChange(isAnimated ? MapChangeRegionDidChangeAnimated : MapChangeRegionDidChange); }; - - if (!isAnimated) { - transitionFrameFn(Clock::now()); - } } bool Transform::inTransition() const { From f6d8822dc0866b9e78879bbf656b0572f566da9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 19 Jan 2016 17:36:22 -0800 Subject: [PATCH 2/3] [core] Removed redundant notification --- src/mbgl/map/transform.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 67d248ca38d..e4c8deac349 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -558,8 +558,6 @@ void Transform::startTransition(const CameraOptions& camera, transitionFinishFn(); } - view.notifyMapChange(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange); - // Associate the anchor, if given, with a coordinate. PrecisionPoint anchor = camera.anchor ? *camera.anchor : PrecisionPoint(NAN, NAN); LatLng anchorLatLng; From b454d036ddef2955e31a18d0c7f834315400276c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 19 Jan 2016 22:26:09 -0800 Subject: [PATCH 3/3] [core] Reverted change to doc comment --- include/mbgl/map/camera.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index e6300efd695..cb2c7bdbf11 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -65,10 +65,7 @@ struct AnimationOptions { std::function transitionFrameFn; /** A function that is called once from the Map thread on the last frame of - the transition, just before the corresponding screen update. The first - parameter indicates how much of the transition was completed, as a - percentage of the duration. In the event that the transition is - canceled, this parameter will have a value less than 1.0. */ + the transition, just before the corresponding screen update. */ std::function transitionFinishFn; /** Creates an animation with no options specified. */