From 1952523bd256b29feed68e248f6fb42589bf7784 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Thu, 4 Jul 2019 09:46:06 +0300 Subject: [PATCH] Improved location mode --- drape_frontend/drape_engine.cpp | 38 ++++++---- drape_frontend/drape_engine.hpp | 26 ++++--- drape_frontend/frontend_renderer.cpp | 26 ++++--- drape_frontend/frontend_renderer.hpp | 41 +++++----- drape_frontend/my_position_controller.cpp | 91 ++++++++++++----------- drape_frontend/my_position_controller.hpp | 4 +- map/framework.cpp | 12 +++ map/framework.hpp | 6 +- 8 files changed, 145 insertions(+), 99 deletions(-) diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 858fa809ea..2fde91155d 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -80,6 +80,7 @@ DrapeEngine::DrapeEngine(Params && params) std::bind(&DrapeEngine::ModelViewChanged, this, _1), std::bind(&DrapeEngine::TapEvent, this, _1), std::bind(&DrapeEngine::UserPositionChanged, this, _1, _2), + std::bind(&DrapeEngine::UserPositionPendingTimeout, this), make_ref(m_requestedTiles), std::move(params.m_overlaysShowStatsCallback), params.m_allow3dBuildings, @@ -426,8 +427,8 @@ void DrapeEngine::AddUserEvent(drape_ptr && e) void DrapeEngine::ModelViewChanged(ScreenBase const & screen) { - if (m_modelViewChanged != nullptr) - m_modelViewChanged(screen); + if (m_modelViewChangedHandler != nullptr) + m_modelViewChangedHandler(screen); } void DrapeEngine::MyPositionModeChanged(location::EMyPositionMode mode, bool routingActive) @@ -439,14 +440,20 @@ void DrapeEngine::MyPositionModeChanged(location::EMyPositionMode mode, bool rou void DrapeEngine::TapEvent(TapInfo const & tapInfo) { - if (m_tapListener != nullptr) - m_tapListener(tapInfo); + if (m_tapEventInfoHandler != nullptr) + m_tapEventInfoHandler(tapInfo); } void DrapeEngine::UserPositionChanged(m2::PointD const & position, bool hasPosition) { - if (m_userPositionChanged != nullptr) - m_userPositionChanged(position, hasPosition); + if (m_userPositionChangedHandler != nullptr) + m_userPositionChangedHandler(position, hasPosition); +} + +void DrapeEngine::UserPositionPendingTimeout() +{ + if (m_userPositionPendingTimeoutHandler != nullptr) + m_userPositionPendingTimeoutHandler(); } void DrapeEngine::ResizeImpl(int w, int h) @@ -503,13 +510,13 @@ void DrapeEngine::FollowRoute(int preferredZoomLevel, int preferredZoomLevel3d, MessagePriority::Normal); } -void DrapeEngine::SetModelViewListener(TModelViewListenerFn && fn) +void DrapeEngine::SetModelViewListener(ModelViewChangedHandler && fn) { - m_modelViewChanged = std::move(fn); + m_modelViewChangedHandler = std::move(fn); } #if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) -void DrapeEngine::NotifyGraphicsReady(TGraphicsReadyFn const & fn) +void DrapeEngine::NotifyGraphicsReady(GraphicsReadyHandler const & fn) { m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, make_unique_dp(fn), @@ -517,14 +524,19 @@ void DrapeEngine::NotifyGraphicsReady(TGraphicsReadyFn const & fn) } #endif -void DrapeEngine::SetTapEventInfoListener(TTapEventInfoFn && fn) +void DrapeEngine::SetTapEventInfoListener(TapEventInfoHandler && fn) { - m_tapListener = std::move(fn); + m_tapEventInfoHandler = std::move(fn); } -void DrapeEngine::SetUserPositionListener(TUserPositionChangedFn && fn) +void DrapeEngine::SetUserPositionListener(UserPositionChangedHandler && fn) { - m_userPositionChanged = std::move(fn); + m_userPositionChangedHandler = std::move(fn); +} + +void DrapeEngine::SetUserPositionPendingTimeoutListener(UserPositionPendingTimeoutHandler && fn) +{ + m_userPositionPendingTimeoutHandler = std::move(fn); } void DrapeEngine::SelectObject(SelectionShape::ESelectedObject obj, m2::PointD const & pt, diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index eb51b695ca..82b5ddc605 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -140,12 +140,12 @@ public: bool useVisibleViewport); void SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim, bool useVisibleViewport); - using TModelViewListenerFn = FrontendRenderer::TModelViewChanged; - void SetModelViewListener(TModelViewListenerFn && fn); + using ModelViewChangedHandler = FrontendRenderer::ModelViewChangedHandler; + void SetModelViewListener(ModelViewChangedHandler && fn); #if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) - using TGraphicsReadyFn = FrontendRenderer::TGraphicsReadyFn; - void NotifyGraphicsReady(TGraphicsReadyFn const & fn); + using GraphicsReadyHandler = FrontendRenderer::GraphicsReadyHandler; + void NotifyGraphicsReady(GraphicsReadyHandler const & fn); #endif void ClearUserMarksGroup(kml::MarkGroupId groupId); @@ -165,10 +165,12 @@ public: void LoseLocation(); void StopLocationFollow(); - using TTapEventInfoFn = FrontendRenderer::TTapEventInfoFn; - void SetTapEventInfoListener(TTapEventInfoFn && fn); - using TUserPositionChangedFn = FrontendRenderer::TUserPositionChangedFn; - void SetUserPositionListener(TUserPositionChangedFn && fn); + using TapEventInfoHandler = FrontendRenderer::TapEventInfoHandler; + void SetTapEventInfoListener(TapEventInfoHandler && fn); + using UserPositionChangedHandler = FrontendRenderer::UserPositionChangedHandler; + void SetUserPositionListener(UserPositionChangedHandler && fn); + using UserPositionPendingTimeoutHandler = FrontendRenderer::UserPositionPendingTimeoutHandler; + void SetUserPositionPendingTimeoutListener(UserPositionPendingTimeoutHandler && fn); void SelectObject(SelectionShape::ESelectedObject obj, m2::PointD const & pt, FeatureID const & featureID, bool isAnim); @@ -250,6 +252,7 @@ private: void MyPositionModeChanged(location::EMyPositionMode mode, bool routingActive); void TapEvent(TapInfo const & tapInfo); void UserPositionChanged(m2::PointD const & position, bool hasPosition); + void UserPositionPendingTimeout(); void ResizeImpl(int w, int h); void RecacheGui(bool needResetOldGui); @@ -270,9 +273,10 @@ private: dp::Viewport m_viewport; - TModelViewListenerFn m_modelViewChanged; - TUserPositionChangedFn m_userPositionChanged; - TTapEventInfoFn m_tapListener; + ModelViewChangedHandler m_modelViewChangedHandler; + TapEventInfoHandler m_tapEventInfoHandler; + UserPositionChangedHandler m_userPositionChangedHandler; + UserPositionPendingTimeoutHandler m_userPositionPendingTimeoutHandler; gui::TWidgetsInitInfo m_widgetsInfo; gui::TWidgetsLayoutInfo m_widgetsLayout; diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 9c205e27af..b4307179c4 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -192,9 +192,10 @@ FrontendRenderer::FrontendRenderer(Params && params) , m_choosePositionMode(false) , m_screenshotMode(params.m_myPositionParams.m_hints.m_screenshotMode) , m_viewport(params.m_viewport) - , m_modelViewChangedFn(params.m_modelViewChangedFn) - , m_tapEventInfoFn(params.m_tapEventFn) - , m_userPositionChangedFn(params.m_positionChangedFn) + , m_modelViewChangedHandler(std::move(params.m_modelViewChangedHandler)) + , m_tapEventInfoHandler(std::move(params.m_tapEventHandler)) + , m_userPositionChangedHandler(std::move(params.m_positionChangedHandler)) + , m_userPositionPendingTimeoutHandler(std::move(params.m_userPositionPendingTimeoutHandler)) , m_requestedTiles(params.m_requestedTiles) , m_maxGeneration(0) , m_maxUserMarksGeneration(0) @@ -215,8 +216,10 @@ FrontendRenderer::FrontendRenderer(Params && params) m_isTeardowned = false; #endif - ASSERT(m_tapEventInfoFn, ()); - ASSERT(m_userPositionChangedFn, ()); + ASSERT(m_modelViewChangedHandler, ()); + ASSERT(m_tapEventInfoHandler, ()); + ASSERT(m_userPositionChangedHandler, ()); + ASSERT(m_userPositionPendingTimeoutHandler, ()); m_gpsTrackRenderer = make_unique_dp([this](uint32_t pointsCount) { @@ -1982,8 +1985,8 @@ void FrontendRenderer::OnTap(m2::PointD const & pt, bool isLongTap) mercator = m_myPositionController->Position(); } - ASSERT(m_tapEventInfoFn != nullptr, ()); - m_tapEventInfoFn({mercator, isLongTap, isMyPosition, GetVisiblePOI(selectRect)}); + ASSERT(m_tapEventInfoHandler != nullptr, ()); + m_tapEventInfoHandler({mercator, isLongTap, isMyPosition, GetVisiblePOI(selectRect)}); } void FrontendRenderer::OnForceTap(m2::PointD const & pt) @@ -2457,7 +2460,12 @@ void FrontendRenderer::AddUserEvent(drape_ptr && event) void FrontendRenderer::PositionChanged(m2::PointD const & position, bool hasPosition) { - m_userPositionChangedFn(position, hasPosition); + m_userPositionChangedHandler(position, hasPosition); +} + +void FrontendRenderer::PositionPendingTimeout() +{ + m_userPositionPendingTimeoutHandler(); } void FrontendRenderer::ChangeModelView(m2::PointD const & center, int zoomLevel, @@ -2554,7 +2562,7 @@ void FrontendRenderer::UpdateScene(ScreenBase const & modelView) void FrontendRenderer::EmitModelViewChanged(ScreenBase const & modelView) const { - m_modelViewChangedFn(modelView); + m_modelViewChangedHandler(modelView); } #if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index cb4b21a5e3..ace736ce68 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -75,18 +75,21 @@ class FrontendRenderer : public BaseRenderer, public UserEventStream::Listener { public: - using TModelViewChanged = std::function; - using TGraphicsReadyFn = std::function; - using TTapEventInfoFn = std::function; - using TUserPositionChangedFn = std::function; + using ModelViewChangedHandler = std::function; + using GraphicsReadyHandler = std::function; + using TapEventInfoHandler = std::function; + using UserPositionChangedHandler = std::function; + using UserPositionPendingTimeoutHandler = std::function; struct Params : BaseRenderer::Params { Params(dp::ApiVersion apiVersion, ref_ptr commutator, ref_ptr factory, ref_ptr texMng, MyPositionController::Params && myPositionParams, dp::Viewport viewport, - TModelViewChanged const & modelViewChangedFn, TTapEventInfoFn const & tapEventFn, - TUserPositionChangedFn const & positionChangedFn, ref_ptr requestedTiles, + ModelViewChangedHandler && modelViewChangedHandler, TapEventInfoHandler && tapEventHandler, + UserPositionChangedHandler && positionChangedHandler, + UserPositionPendingTimeoutHandler && userPositionPendingTimeoutHandler, + ref_ptr requestedTiles, OverlaysShowStatsCallback && overlaysShowStatsCallback, bool allow3dBuildings, bool trafficEnabled, bool blockTapEvents, std::vector && enabledEffects, @@ -94,9 +97,10 @@ public: : BaseRenderer::Params(apiVersion, commutator, factory, texMng, onGraphicsContextInitialized) , m_myPositionParams(std::move(myPositionParams)) , m_viewport(viewport) - , m_modelViewChangedFn(modelViewChangedFn) - , m_tapEventFn(tapEventFn) - , m_positionChangedFn(positionChangedFn) + , m_modelViewChangedHandler(std::move(modelViewChangedHandler)) + , m_tapEventHandler(std::move(tapEventHandler)) + , m_positionChangedHandler(std::move(positionChangedHandler)) + , m_userPositionPendingTimeoutHandler(std::move(userPositionPendingTimeoutHandler)) , m_requestedTiles(requestedTiles) , m_overlaysShowStatsCallback(std::move(overlaysShowStatsCallback)) , m_allow3dBuildings(allow3dBuildings) @@ -107,9 +111,10 @@ public: MyPositionController::Params m_myPositionParams; dp::Viewport m_viewport; - TModelViewChanged m_modelViewChangedFn; - TTapEventInfoFn m_tapEventFn; - TUserPositionChangedFn m_positionChangedFn; + ModelViewChangedHandler m_modelViewChangedHandler; + TapEventInfoHandler m_tapEventHandler; + UserPositionChangedHandler m_positionChangedHandler; + UserPositionPendingTimeoutHandler m_userPositionPendingTimeoutHandler; ref_ptr m_requestedTiles; OverlaysShowStatsCallback m_overlaysShowStatsCallback; bool m_allow3dBuildings; @@ -118,7 +123,7 @@ public: std::vector m_enabledEffects; }; - FrontendRenderer(Params && params); + explicit FrontendRenderer(Params && params); ~FrontendRenderer() override; void Teardown(); @@ -127,6 +132,7 @@ public: // MyPositionController::Listener void PositionChanged(m2::PointD const & position, bool hasPosition) override; + void PositionPendingTimeout() override; void ChangeModelView(m2::PointD const & center, int zoomLevel, TAnimationCreator const & parallelAnimCreator) override; void ChangeModelView(double azimuth, TAnimationCreator const & parallelAnimCreator) override; @@ -320,9 +326,10 @@ private: dp::Viewport m_viewport; UserEventStream m_userEventStream; - TModelViewChanged m_modelViewChangedFn; - TTapEventInfoFn m_tapEventInfoFn; - TUserPositionChangedFn m_userPositionChangedFn; + ModelViewChangedHandler m_modelViewChangedHandler; + TapEventInfoHandler m_tapEventInfoHandler; + UserPositionChangedHandler m_userPositionChangedHandler; + UserPositionPendingTimeoutHandler m_userPositionPendingTimeoutHandler; ScreenBase m_lastReadedModelView; TTilesCollection m_notFinishedTiles; @@ -379,7 +386,7 @@ private: bool m_firstLaunchAnimationInterrupted = false; #if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) - TGraphicsReadyFn m_graphicsReadyFn; + GraphicsReadyHandler m_graphicsReadyFn; enum class GraphicsStage { diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 3b328d4c3f..51b0b5660c 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -161,7 +161,6 @@ MyPositionController::MyPositionController(Params && params, ref_ptr= kMaxPendingLocationTimeSec) + if (m_pendingStarted && m_pendingTimer.ElapsedSeconds() >= kMaxPendingLocationTimeSec) + { + m_pendingStarted = false; ChangeMode(location::NotFollowNoPosition); + if (m_listener) + m_listener->PositionPendingTimeout(); + } } } diff --git a/drape_frontend/my_position_controller.hpp b/drape_frontend/my_position_controller.hpp index 95e366f147..9e262eded1 100644 --- a/drape_frontend/my_position_controller.hpp +++ b/drape_frontend/my_position_controller.hpp @@ -32,6 +32,7 @@ public: public: virtual ~Listener() = default; virtual void PositionChanged(m2::PointD const & position, bool hasPosition) = 0; + virtual void PositionPendingTimeout() = 0; // Show map with center in "center" point and current zoom. virtual void ChangeModelView(m2::PointD const & center, int zoomLevel, TAnimationCreator const & parallelAnimCreator) = 0; @@ -188,6 +189,7 @@ private: base::Timer m_lastGPSBearing; base::Timer m_pendingTimer; + bool m_pendingStarted = true; base::Timer m_routingNotFollowTimer; bool m_blockRoutingNotFollowTimer = false; base::Timer m_blockAutoZoomTimer; @@ -212,8 +214,6 @@ private: bool m_allowToFollowAfterObsoletePosition; bool m_needBlockAutoZoom; - bool m_notFollowAfterPending; - uint64_t m_locationWaitingNotifyId; uint64_t m_routingNotFollowNotifyId; uint64_t m_blockAutoZoomNotifyId; diff --git a/map/framework.cpp b/map/framework.cpp index c4b6b54b8a..13d2201e98 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -293,6 +293,11 @@ void Framework::SetMyPositionModeListener(TMyPositionModeChanged && fn) m_myPositionListener = move(fn); } +void Framework::SetMyPositionPendingTimeoutListener(df::DrapeEngine::UserPositionPendingTimeoutHandler && fn) +{ + m_myPositionPendingTimeoutListener = move(fn); +} + TrafficManager & Framework::GetTrafficManager() { return m_trafficManager; @@ -1964,6 +1969,13 @@ void Framework::CreateDrapeEngine(ref_ptr contextFac OnUserPositionChanged(position, hasPosition); }); }); + m_drapeEngine->SetUserPositionPendingTimeoutListener([this]() + { + GetPlatform().RunTask(Platform::Thread::Gui, [this](){ + if (m_myPositionPendingTimeoutListener) + m_myPositionPendingTimeoutListener(); + }); + }); OnSize(params.m_surfaceWidth, params.m_surfaceHeight); diff --git a/map/framework.hpp b/map/framework.hpp index 08988c0aaf..a6cfbee86e 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -210,7 +210,7 @@ protected: ScreenBase m_currentModelView; m2::RectD m_visibleViewport; - using TViewportChangedFn = df::DrapeEngine::TModelViewListenerFn; + using TViewportChangedFn = df::DrapeEngine::ModelViewChangedHandler; TViewportChangedFn m_viewportChangedFn; drape_ptr m_drapeEngine; @@ -223,6 +223,7 @@ protected: bool m_enabledDiffs; location::TMyPositionModeChanged m_myPositionListener; + df::DrapeEngine::UserPositionPendingTimeoutHandler m_myPositionPendingTimeoutListener; unique_ptr m_bmManager; @@ -495,6 +496,7 @@ public: void SwitchMyPositionNextMode(); /// Should be set before Drape initialization. Guarantees that fn is called in main thread context. void SetMyPositionModeListener(location::TMyPositionModeChanged && fn); + void SetMyPositionPendingTimeoutListener(df::DrapeEngine::UserPositionPendingTimeoutHandler && fn); private: void OnUserPositionChanged(m2::PointD const & position, bool hasPosition); @@ -662,7 +664,7 @@ public: void SetViewportListener(TViewportChangedFn const & fn); #if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) - using TGraphicsReadyFn = df::DrapeEngine::TGraphicsReadyFn; + using TGraphicsReadyFn = df::DrapeEngine::GraphicsReadyHandler; void NotifyGraphicsReady(TGraphicsReadyFn const & fn); #endif