From fb3404937c4c8bc0a13ce2f1c5949fab8a69cf10 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Thu, 10 Aug 2017 19:35:05 +0300 Subject: [PATCH] Fixed route disappearing on map style switch (#6846) Fixed route disappearing on map style switch --- drape_frontend/drape_engine.cpp | 4 +-- drape_frontend/drape_engine.hpp | 2 +- drape_frontend/frontend_renderer.cpp | 14 ++++++----- drape_frontend/message_subclasses.hpp | 16 +++++------- drape_frontend/route_builder.cpp | 4 +-- drape_frontend/route_builder.hpp | 2 +- drape_frontend/route_renderer.cpp | 35 ++++++++++++++++++++++----- drape_frontend/route_renderer.hpp | 1 + drape_frontend/route_shape.hpp | 5 +++- map/routing_manager.cpp | 2 +- 10 files changed, 55 insertions(+), 30 deletions(-) diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 7a9aea58db..86d55c13cd 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -469,11 +469,11 @@ void DrapeEngine::DeselectObject() MessagePriority::Normal); } -dp::DrapeID DrapeEngine::AddSubroute(drape_ptr && subroute) +dp::DrapeID DrapeEngine::AddSubroute(SubrouteConstPtr subroute) { dp::DrapeID const id = GenerateDrapeID(); m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, - make_unique_dp(id, std::move(subroute)), + make_unique_dp(id, subroute), MessagePriority::Normal); return id; } diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 3aff8328c8..d7eef6d035 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -156,7 +156,7 @@ public: FeatureID const & featureID, bool isAnim); void DeselectObject(); - dp::DrapeID AddSubroute(drape_ptr &&segment); + dp::DrapeID AddSubroute(SubrouteConstPtr subroute); void RemoveSubroute(dp::DrapeID subrouteId, bool deactivateFollowing); void FollowRoute(int preferredZoomLevel, int preferredZoomLevel3d, bool enableAutoZoom); void DeactivateRouteFollowing(); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index a7046391d4..af2494c1da 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -432,9 +432,15 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) { ref_ptr msg = message; drape_ptr routeData = msg->AcceptRouteData(); + + if (routeData->m_recacheId < 0) + routeData->m_recacheId = m_lastRecacheRouteId; + if (!CheckRouteRecaching(make_ref(routeData))) break; + m_routeRenderer->ClearObsoleteRouteData(m_lastRecacheRouteId); + m_routeRenderer->AddRouteData(std::move(routeData), make_ref(m_gpuProgramManager)); // Here we have to recache route arrows. @@ -821,12 +827,11 @@ void FrontendRenderer::UpdateGLResources() for (auto const & routeData : m_routeRenderer->GetRouteData()) { auto msg = make_unique_dp(routeData->m_subrouteId, - std::move(routeData->m_subroute), + routeData->m_subroute, m_lastRecacheRouteId); m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, std::move(msg), MessagePriority::Normal); } - m_routeRenderer->ClearRouteData(); m_trafficRenderer->ClearGLDependentResources(); @@ -858,9 +863,6 @@ void FrontendRenderer::FollowRoute(int preferredZoomLevel, int preferredZoomLeve bool FrontendRenderer::CheckRouteRecaching(ref_ptr routeData) { - if (routeData->m_recacheId < 0) - return true; - return routeData->m_recacheId >= m_lastRecacheRouteId; } @@ -2017,7 +2019,7 @@ void FrontendRenderer::EmitModelViewChanged(ScreenBase const & modelView) const void FrontendRenderer::OnCacheRouteArrows(int routeIndex, std::vector const & borders) { m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread, - make_unique_dp(routeIndex, borders), + make_unique_dp(routeIndex, borders, m_lastRecacheRouteId), MessagePriority::Normal); } diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index ecf80042b7..ede68d3860 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -547,35 +547,31 @@ private: class AddSubrouteMessage : public Message { public: - AddSubrouteMessage(dp::DrapeID subrouteId, drape_ptr && subroute) - : AddSubrouteMessage(subrouteId, std::move(subroute), -1 /* invalid recache id */) + AddSubrouteMessage(dp::DrapeID subrouteId, SubrouteConstPtr subroute) + : AddSubrouteMessage(subrouteId, subroute, -1 /* invalid recache id */) {} - AddSubrouteMessage(dp::DrapeID subrouteId, drape_ptr && subroute, int recacheId) + AddSubrouteMessage(dp::DrapeID subrouteId, SubrouteConstPtr subroute, int recacheId) : m_subrouteId(subrouteId) - , m_subroute(std::move(subroute)) + , m_subroute(subroute) , m_recacheId(recacheId) {} Type GetType() const override { return Message::AddSubroute; } dp::DrapeID GetSubrouteId() const { return m_subrouteId; }; - drape_ptr && GetSubroute() { return std::move(m_subroute); } + SubrouteConstPtr GetSubroute() const { return m_subroute; } int GetRecacheId() const { return m_recacheId; } private: dp::DrapeID m_subrouteId; - drape_ptr m_subroute; + SubrouteConstPtr m_subroute; int const m_recacheId; }; class CacheRouteArrowsMessage : public Message { public: - CacheRouteArrowsMessage(dp::DrapeID subrouteId, std::vector const & borders) - : CacheRouteArrowsMessage(subrouteId, borders, -1 /* invalid recache id */) - {} - CacheRouteArrowsMessage(dp::DrapeID subrouteId, std::vector const & borders, int recacheId) : m_subrouteId(subrouteId) diff --git a/drape_frontend/route_builder.cpp b/drape_frontend/route_builder.cpp index be450ec959..8af31c2b50 100644 --- a/drape_frontend/route_builder.cpp +++ b/drape_frontend/route_builder.cpp @@ -10,12 +10,12 @@ RouteBuilder::RouteBuilder(TFlushRouteFn const & flushRouteFn, , m_flushRouteArrowsFn(flushRouteArrowsFn) {} -void RouteBuilder::Build(dp::DrapeID subrouteId, drape_ptr && subroute, +void RouteBuilder::Build(dp::DrapeID subrouteId, SubrouteConstPtr subroute, ref_ptr textures, int recacheId) { drape_ptr routeData = make_unique_dp(); routeData->m_subrouteId = subrouteId; - routeData->m_subroute = std::move(subroute); + routeData->m_subroute = subroute; routeData->m_pivot = routeData->m_subroute->m_polyline.GetLimitRect().Center(); routeData->m_recacheId = recacheId; RouteShape::CacheRoute(textures, *routeData.get()); diff --git a/drape_frontend/route_builder.hpp b/drape_frontend/route_builder.hpp index f027aa5650..8e483e3973 100644 --- a/drape_frontend/route_builder.hpp +++ b/drape_frontend/route_builder.hpp @@ -25,7 +25,7 @@ public: RouteBuilder(TFlushRouteFn const & flushRouteFn, TFlushRouteArrowsFn const & flushRouteArrowsFn); - void Build(dp::DrapeID subrouteId, drape_ptr && subroute, + void Build(dp::DrapeID subrouteId, SubrouteConstPtr subroute, ref_ptr textures, int recacheId); void BuildArrows(dp::DrapeID subrouteId, std::vector const & borders, diff --git a/drape_frontend/route_renderer.cpp b/drape_frontend/route_renderer.cpp index 0738706a18..f8592eb9b3 100644 --- a/drape_frontend/route_renderer.cpp +++ b/drape_frontend/route_renderer.cpp @@ -61,7 +61,7 @@ uint32_t const kPreviewPointsCount = 512; double const kInvalidDistance = -1.0; -void InterpolateByZoom(drape_ptr const & subroute, ScreenBase const & screen, +void InterpolateByZoom(SubrouteConstPtr const & subroute, ScreenBase const & screen, float & halfWidth, double & zoom) { int index = 0; @@ -88,9 +88,9 @@ float CalculateRadius(ScreenBase const & screen) void ClipBorders(std::vector & borders) { - auto invalidBorders = [](ArrowBorders const & borders) + auto invalidBorders = [](ArrowBorders const & arrowBorders) { - return borders.m_groupIndex == kInvalidGroup; + return arrowBorders.m_groupIndex == kInvalidGroup; }; borders.erase(std::remove_if(borders.begin(), borders.end(), invalidBorders), borders.end()); } @@ -231,7 +231,7 @@ void BuildBuckets(RouteRenderProperty const & renderProperty, ref_ptrGetBuffer()->Build(mng->GetProgram(renderProperty.m_state.GetProgramIndex())); } -dp::Color GetOutlineColor(drape_ptr const & subroute) +dp::Color GetOutlineColor(SubrouteConstPtr const & subroute) { if (subroute->m_routeType == RouteType::Car || subroute->m_routeType == RouteType::Taxi) return df::GetColorConstant(kRouteOutlineColor); @@ -377,9 +377,9 @@ dp::Color RouteRenderer::GetMaskColor(RouteType routeType, double baseDistance, { if (routeType == RouteType::Car) return GetColorConstant(arrows ? kRouteArrowsMaskCar : kRouteMaskCar); - else if (routeType == RouteType::Bicycle) + if (routeType == RouteType::Bicycle) return GetColorConstant(arrows ? kRouteArrowsMaskBicycle : kRouteMaskBicycle); - else if (routeType == RouteType::Pedestrian) + if (routeType == RouteType::Pedestrian) return GetColorConstant(kRouteMaskPedestrian); } return {0, 0, 0, 0}; @@ -591,6 +591,29 @@ void RouteRenderer::ClearRouteData() m_hiddenSubroutes.clear(); } +void RouteRenderer::ClearObsoleteRouteData(int currentRecacheId) +{ + std::vector deletedSubroutes; + deletedSubroutes.reserve(m_routeData.size()); + auto const functor = [&deletedSubroutes, ¤tRecacheId](drape_ptr const & data) + { + if (data->m_recacheId < currentRecacheId) + { + deletedSubroutes.push_back(data->m_subrouteId); + return true; + } + return false; + }; + m_routeData.erase(std::remove_if(m_routeData.begin(), m_routeData.end(), functor), + m_routeData.end()); + + for (auto const & subrouteId : deletedSubroutes) + { + m_routeAdditional[subrouteId].m_arrowsData.reset(); + m_routeAdditional[subrouteId].m_arrowBorders.clear(); + } +} + void RouteRenderer::Clear() { ClearRouteData(); diff --git a/drape_frontend/route_renderer.hpp b/drape_frontend/route_renderer.hpp index 13a0460685..6ad568faba 100644 --- a/drape_frontend/route_renderer.hpp +++ b/drape_frontend/route_renderer.hpp @@ -57,6 +57,7 @@ public: void Clear(); void ClearRouteData(); + void ClearObsoleteRouteData(int currentRecacheId); void ClearGLDependentResources(); void UpdateDistanceFromBegin(double distanceFromBegin); diff --git a/drape_frontend/route_shape.hpp b/drape_frontend/route_shape.hpp index 1e52002664..ff3e539f1b 100644 --- a/drape_frontend/route_shape.hpp +++ b/drape_frontend/route_shape.hpp @@ -13,6 +13,7 @@ #include "geometry/polyline2d.hpp" +#include #include namespace df @@ -68,6 +69,8 @@ struct Subroute df::RoutePattern m_pattern; }; +using SubrouteConstPtr = std::shared_ptr; + struct RouteRenderProperty { dp::GLState m_state; @@ -87,7 +90,7 @@ struct BaseRouteData struct RouteData : public BaseRouteData { - drape_ptr m_subroute; + SubrouteConstPtr m_subroute; double m_length = 0.0; }; diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index b8c5e8b5e5..40ee30b7a1 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -485,7 +485,7 @@ void RoutingManager::InsertRoute(Route const & route) default: ASSERT(false, ("Unknown router type")); } - auto const subrouteId = m_drapeEngine->AddSubroute(std::move(subroute)); + auto const subrouteId = m_drapeEngine->AddSubroute(df::SubrouteConstPtr(subroute.release())); m_drapeSubroutes.push_back(subrouteId); // TODO: we will send subrouteId to routing subsystem when we can partly update route.