diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 2109b75a72..7eda3979f5 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using namespace std::placeholders; diff --git a/drape_frontend/route_builder.cpp b/drape_frontend/route_builder.cpp index a8d8da3c29..cfe67cd3d6 100644 --- a/drape_frontend/route_builder.cpp +++ b/drape_frontend/route_builder.cpp @@ -4,46 +4,26 @@ namespace { -std::vector> SplitSubroute(dp::DrapeID subrouteId, - df::SubrouteConstPtr subroute, - int recacheId) +std::vector> SplitSubroute(df::SubrouteConstPtr subroute) { ASSERT(subroute != nullptr, ()); - std::vector> result; + std::vector> result; if (subroute->m_styleType == df::SubrouteStyleType::Single) { ASSERT(!subroute->m_style.empty(), ()); - auto subrouteData = make_unique_dp(); - subrouteData->m_subrouteId = subrouteId; - subrouteData->m_subroute = subroute; - subrouteData->m_pivot = subrouteData->m_subroute->m_polyline.GetLimitRect().Center(); - subrouteData->m_recacheId = recacheId; - subrouteData->m_styleIndex = 0; - subrouteData->m_startPointIndex = 0; - subrouteData->m_endPointIndex = subrouteData->m_subroute->m_polyline.GetSize() - 1; - result.push_back(std::move(subrouteData)); + result.emplace_back(std::make_pair(0, subroute->m_polyline.GetSize() - 1)); return result; } ASSERT_EQUAL(subroute->m_style.size() + 1, subroute->m_polyline.GetSize(), ()); size_t startIndex = 0; - result.reserve(10); for (size_t i = 1; i <= subroute->m_style.size(); ++i) { if (i == subroute->m_style.size() || subroute->m_style[i] != subroute->m_style[startIndex]) { - auto subrouteData = make_unique_dp(); - subrouteData->m_subrouteId = subrouteId; - subrouteData->m_subroute = subroute; - subrouteData->m_startPointIndex = startIndex; - subrouteData->m_endPointIndex = i; - subrouteData->m_styleIndex = startIndex; - subrouteData->m_pivot = subrouteData->m_subroute->m_polyline.GetLimitRect().Center(); - subrouteData->m_recacheId = recacheId; - result.push_back(std::move(subrouteData)); - + result.emplace_back(std::make_pair(startIndex, i)); startIndex = i; } } @@ -67,9 +47,14 @@ void RouteBuilder::Build(dp::DrapeID subrouteId, SubrouteConstPtr subroute, cacheData.m_baseDepthIndex = subroute->m_baseDepthIndex; m_routeCache[subrouteId] = std::move(cacheData); - auto subrouteData = SplitSubroute(subrouteId, subroute, recacheId); - for (auto & data : subrouteData) - RouteShape::CacheRoute(textures, *data.get()); + auto const & subrouteIndices = SplitSubroute(subroute); + std::vector> subrouteData; + subrouteData.reserve(subrouteIndices.size()); + for (auto const & indices : subrouteIndices) + { + subrouteData.push_back(RouteShape::CacheRoute(subrouteId, subroute, indices.first, + indices.second, recacheId, textures)); + } // Flush route geometry. GLFunctions::glFlush(); diff --git a/drape_frontend/route_builder.hpp b/drape_frontend/route_builder.hpp index e2e2576a30..f22f399928 100644 --- a/drape_frontend/route_builder.hpp +++ b/drape_frontend/route_builder.hpp @@ -19,8 +19,8 @@ namespace df class RouteBuilder { public: - using TFlushRouteFn = function &&)>; - using TFlushRouteArrowsFn = function &&)>; + using TFlushRouteFn = std::function &&)>; + using TFlushRouteArrowsFn = std::function &&)>; RouteBuilder(TFlushRouteFn const & flushRouteFn, TFlushRouteArrowsFn const & flushRouteArrowsFn); diff --git a/drape_frontend/route_renderer.cpp b/drape_frontend/route_renderer.cpp index 8ae2116de7..e97cf9fe1f 100644 --- a/drape_frontend/route_renderer.cpp +++ b/drape_frontend/route_renderer.cpp @@ -403,7 +403,7 @@ void RouteRenderer::RenderSubroute(SubrouteInfo const & subrouteInfo, size_t sub auto const & subrouteData = subrouteInfo.m_subrouteData[subrouteDataIndex]; dp::GLState const & state = subrouteData->m_renderProperty.m_state; - size_t const styleIndex = subrouteData->m_styleIndex; + size_t const styleIndex = subrouteData->m_startPointIndex; ASSERT_LESS(styleIndex, subrouteInfo.m_subroute->m_style.size(), ()); auto const & style = subrouteInfo.m_subroute->m_style[styleIndex]; diff --git a/drape_frontend/route_shape.cpp b/drape_frontend/route_shape.cpp index 4d0c6444e7..bb66493214 100644 --- a/drape_frontend/route_shape.cpp +++ b/drape_frontend/route_shape.cpp @@ -394,22 +394,23 @@ void RouteShape::CacheRouteArrows(ref_ptr mng, m2::PolylineD AV::GetBindingInfo(), routeArrowsData.m_renderProperty); } -void RouteShape::CacheRoute(ref_ptr textures, SubrouteData & subrouteData) +drape_ptr RouteShape::CacheRoute(dp::DrapeID subrouteId, SubrouteConstPtr subroute, + size_t startIndex, size_t endIndex, int recacheId, + ref_ptr textures) { - ASSERT_LESS(subrouteData.m_startPointIndex, subrouteData.m_endPointIndex, ()); + ASSERT_LESS(startIndex, endIndex, ()); - auto const points = subrouteData.m_subroute->m_polyline.ExtractSegment(subrouteData.m_startPointIndex, - subrouteData.m_endPointIndex); + auto const points = subroute->m_polyline.ExtractSegment(startIndex, endIndex); if (points.empty()) - return; + return nullptr; std::vector segmentsColors; - if (!subrouteData.m_subroute->m_traffic.empty()) + if (!subroute->m_traffic.empty()) { - segmentsColors.reserve(subrouteData.m_endPointIndex - subrouteData.m_startPointIndex); - for (size_t i = subrouteData.m_startPointIndex; i < subrouteData.m_endPointIndex; ++i) + segmentsColors.reserve(endIndex - startIndex); + for (size_t i = startIndex; i < endIndex; ++i) { - auto const speedGroup = TrafficGenerator::CheckColorsSimplification(subrouteData.m_subroute->m_traffic[i]); + auto const speedGroup = TrafficGenerator::CheckColorsSimplification(subroute->m_traffic[i]); auto const colorConstant = TrafficGenerator::GetColorBySpeedGroup(speedGroup, true /* route */); dp::Color const color = df::GetColorConstant(colorConstant); float const alpha = (speedGroup == traffic::SpeedGroup::G4 || @@ -419,19 +420,29 @@ void RouteShape::CacheRoute(ref_ptr textures, SubrouteData & } } + auto subrouteData = make_unique_dp(); + subrouteData->m_subrouteId = subrouteId; + subrouteData->m_subroute = subroute; + subrouteData->m_startPointIndex = startIndex; + subrouteData->m_endPointIndex = endIndex; + subrouteData->m_pivot = subroute->m_polyline.GetLimitRect().Center(); + subrouteData->m_recacheId = recacheId; + TGeometryBuffer geometry; TGeometryBuffer joinsGeometry; - PrepareGeometry(points, subrouteData.m_pivot, segmentsColors, - static_cast(subrouteData.m_subroute->m_baseDepthIndex * kDepthPerSubroute), + PrepareGeometry(points, subrouteData->m_pivot, segmentsColors, + static_cast(subroute->m_baseDepthIndex * kDepthPerSubroute), geometry, joinsGeometry); - auto state = CreateGLState(subrouteData.m_subroute->m_style[subrouteData.m_styleIndex].m_pattern.m_isDashed ? + auto state = CreateGLState(subroute->m_style[startIndex].m_pattern.m_isDashed ? gpu::ROUTE_DASH_PROGRAM : gpu::ROUTE_PROGRAM, RenderState::GeometryLayer); state.SetColorTexture(textures->GetSymbolsTexture()); BatchGeometry(state, make_ref(geometry.data()), static_cast(geometry.size()), make_ref(joinsGeometry.data()), static_cast(joinsGeometry.size()), - RV::GetBindingInfo(), subrouteData.m_renderProperty); + RV::GetBindingInfo(), subrouteData->m_renderProperty); + + return subrouteData; } void RouteShape::BatchGeometry(dp::GLState const & state, ref_ptr geometry, uint32_t geomSize, diff --git a/drape_frontend/route_shape.hpp b/drape_frontend/route_shape.hpp index 1a604d4066..9760f786dc 100644 --- a/drape_frontend/route_shape.hpp +++ b/drape_frontend/route_shape.hpp @@ -13,6 +13,7 @@ #include "geometry/polyline2d.hpp" +#include #include #include @@ -61,8 +62,8 @@ struct RoutePattern { double const kEps = 1e-5; return m_isDashed == pattern.m_isDashed && - fabs(m_dashLength - pattern.m_dashLength) < kEps && - fabs(m_gapLength - pattern.m_gapLength) < kEps; + std::fabs(m_dashLength - pattern.m_dashLength) < kEps && + std::fabs(m_gapLength - pattern.m_gapLength) < kEps; } }; @@ -146,7 +147,6 @@ struct BaseSubrouteData struct SubrouteData : public BaseSubrouteData { SubrouteConstPtr m_subroute; - size_t m_styleIndex = 0; size_t m_startPointIndex = 0; size_t m_endPointIndex = 0; }; @@ -168,7 +168,9 @@ public: using AV = gpu::SolidTexturingVertex; using TArrowGeometryBuffer = buffer_vector; - static void CacheRoute(ref_ptr textures, SubrouteData & subrouteData); + static drape_ptr CacheRoute(dp::DrapeID subrouteId, SubrouteConstPtr subroute, + size_t startIndex, size_t endIndex, int recacheId, + ref_ptr textures); static void CacheRouteArrows(ref_ptr mng, m2::PolylineD const & polyline, std::vector const & borders, double baseDepthIndex, diff --git a/geometry/polyline2d.hpp b/geometry/polyline2d.hpp index 11b3442b0b..f214b72e4d 100644 --- a/geometry/polyline2d.hpp +++ b/geometry/polyline2d.hpp @@ -133,17 +133,15 @@ public: vector> ExtractSegment(size_t startPointIndex, size_t endPointIndex) const { - if (startPointIndex > endPointIndex || - startPointIndex + 1 > m_points.size() || - endPointIndex + 1 > m_points.size()) + if (startPointIndex > endPointIndex || startPointIndex >= m_points.size() || + endPointIndex >= m_points.size()) { return vector>(); } - vector> result; - result.reserve(endPointIndex - startPointIndex + 1); + vector> result(endPointIndex - startPointIndex + 1); for (size_t i = startPointIndex; i <= endPointIndex; ++i) - result.push_back(m_points[i]); + result[i] = m_points[i]; return result; }