From 6dd8a1af0b659411bd644dea76231910867f3bc4 Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 25 Sep 2012 13:57:10 +0300 Subject: [PATCH] removed duplicate anim::Controller instance. --- map/animator.cpp | 7 +++++-- map/compass_arrow.cpp | 22 ++-------------------- map/framework.cpp | 2 ++ map/location_state.cpp | 2 +- map/render_policy.cpp | 7 +++---- map/render_policy.hpp | 9 +++++++-- 6 files changed, 20 insertions(+), 29 deletions(-) diff --git a/map/animator.cpp b/map/animator.cpp index 370f27a2c7..414fdea659 100644 --- a/map/animator.cpp +++ b/map/animator.cpp @@ -16,7 +16,9 @@ void Animator::RotateScreen(double startAngle, double endAngle, double duration) { bool shouldRotate = false; - if (m_rotateScreenTask && m_rotateScreenTask->IsRunning()) + if (m_rotateScreenTask + && !m_rotateScreenTask->IsCancelled() + && !m_rotateScreenTask->IsEnded()) { // if the end angle seriously changed we should re-create rotation task. if (fabs(ang::GetShortestDistance(m_rotateScreenTask->EndAngle(), endAngle)) > m_rotationThreshold) @@ -45,7 +47,8 @@ void Animator::RotateScreen(double startAngle, double endAngle, double duration) void Animator::StopRotation() { if (m_rotateScreenTask - && m_rotateScreenTask->IsRunning()) + && !m_rotateScreenTask->IsEnded() + && !m_rotateScreenTask->IsCancelled()) m_rotateScreenTask->Cancel(); m_rotateScreenTask.reset(); diff --git a/map/compass_arrow.cpp b/map/compass_arrow.cpp index 3463fd15bc..b580fc6fd4 100644 --- a/map/compass_arrow.cpp +++ b/map/compass_arrow.cpp @@ -132,34 +132,16 @@ void CompassArrow::StopAnimation() bool CompassArrow::onTapEnded(m2::PointD const & pt) { - shared_ptr animController = m_framework->GetRenderPolicy()->GetAnimController(); + anim::Controller * animController = m_framework->GetAnimController(); animController->Lock(); /// switching off compass follow mode m_framework->GetInformationDisplay().locationState()->StopCompassFollowing(); - if (m_rotateScreenTask - && !m_rotateScreenTask->IsEnded() - && !m_rotateScreenTask->IsCancelled()) - m_rotateScreenTask->Cancel(); - m_rotateScreenTask.reset(); - double startAngle = m_framework->GetNavigator().Screen().GetAngle(); double endAngle = 0; - double period = 2 * math::pi; - - startAngle -= floor(startAngle / period) * period; - endAngle -= floor(endAngle / period) * period; - - if (fabs(startAngle - endAngle) > math::pi) - startAngle -= 2 * math::pi; - - m_rotateScreenTask.reset(new RotateScreenTask(m_framework, - startAngle, - endAngle, - 2)); - animController->AddTask(m_rotateScreenTask); + m_framework->GetAnimator().RotateScreen(startAngle, endAngle, 2); animController->Unlock(); diff --git a/map/framework.cpp b/map/framework.cpp index 48d8deaccd..e322189d0c 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1135,6 +1135,8 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy) m_renderPolicy->SetRenderFn(DrawModelFn()); + m_renderPolicy->SetAnimController(m_animController.get()); + m_navigator.SetSupportRotation(m_renderPolicy->DoSupportRotation()); if (m_width != 0 && m_height != 0) diff --git a/map/location_state.cpp b/map/location_state.cpp index dcce01ccc2..a9234eaa6a 100644 --- a/map/location_state.cpp +++ b/map/location_state.cpp @@ -387,7 +387,7 @@ namespace location if (!m_framework->GetNavigator().DoSupportRotation()) return; - shared_ptr controller = m_framework->GetRenderPolicy()->GetAnimController(); + anim::Controller * controller = m_framework->GetAnimController(); controller->Lock(); diff --git a/map/render_policy.cpp b/map/render_policy.cpp index b452e428c9..7cc8513412 100644 --- a/map/render_policy.cpp +++ b/map/render_policy.cpp @@ -37,8 +37,7 @@ RenderPolicy::RenderPolicy(Params const & p, m_doSupportRotation(doSupportRotation), m_doForceUpdate(false), m_visualScale(p.m_visualScale), - m_skinName(p.m_skinName), - m_controller(new anim::Controller()) + m_skinName(p.m_skinName) { LOG(LDEBUG, ("each BaseRule will hold up to", idCacheSize, "cached values")); drule::rules().ResizeCaches(idCacheSize); @@ -220,9 +219,9 @@ void RenderPolicy::JoinBenchmarkFence(int fenceID) { } -shared_ptr const & RenderPolicy::GetAnimController() const +void RenderPolicy::SetAnimController(anim::Controller * controller) { - return m_controller; + m_controller = controller; } void RenderPolicy::SetOverlay(shared_ptr const & overlay) diff --git a/map/render_policy.hpp b/map/render_policy.hpp index ded8b91df0..ae35a8f65c 100644 --- a/map/render_policy.hpp +++ b/map/render_policy.hpp @@ -13,6 +13,11 @@ class PaintEvent; class ScreenBase; class VideoTimer; +namespace anim +{ + class Controller; +} + namespace yg { namespace gl @@ -60,7 +65,7 @@ protected: m2::AnyRectD m_invalidRect; double m_visualScale; string m_skinName; - shared_ptr m_controller; + anim::Controller * m_controller; shared_ptr m_overlay; void SetOverlay(shared_ptr const & overlay); @@ -111,6 +116,7 @@ public: /// the start point of rendering in renderpolicy. virtual void SetRenderFn(TRenderFn renderFn); virtual void SetCountryNameFn(TCountryNameFn countryNameFn); + void SetAnimController(anim::Controller * controller); bool DoSupportRotation() const; virtual bool IsTiling() const; @@ -123,7 +129,6 @@ public: bool DoForceUpdate() const; void SetForceUpdate(bool flag); - shared_ptr const & GetAnimController() const; bool IsAnimating() const; void SetInvalidRect(m2::AnyRectD const & glbRect);