diff --git a/drape_frontend/route_shape.cpp b/drape_frontend/route_shape.cpp index 602e30d884..9c78fba1eb 100644 --- a/drape_frontend/route_shape.cpp +++ b/drape_frontend/route_shape.cpp @@ -11,16 +11,12 @@ #include "drape/glsl_types.hpp" #include "drape/texture_manager.hpp" -#include "indexer/map_style_reader.hpp" - #include "base/logging.hpp" namespace df { - namespace { - float const kLeftSide = 1.0f; float const kCenter = 0.0f; float const kRightSide = -1.0f; @@ -33,9 +29,9 @@ void GetArrowTextureRegion(ref_ptr textures, dp::TextureMana textures->GetSymbolRegion("route-arrow", region); } -vector CalculatePoints(m2::PolylineD const & polyline, double start, double end) +std::vector CalculatePoints(m2::PolylineD const & polyline, double start, double end) { - vector result; + std::vector result; result.reserve(polyline.GetSize() / 4); auto addIfNotExist = [&result](m2::PointD const & pnt) @@ -44,7 +40,7 @@ vector CalculatePoints(m2::PolylineD const & polyline, double start, result.push_back(pnt); }; - vector const & path = polyline.GetPoints(); + std::vector const & path = polyline.GetPoints(); double len = 0; bool started = false; for (size_t i = 0; i + 1 < path.size(); i++) @@ -81,8 +77,9 @@ vector CalculatePoints(m2::PolylineD const & polyline, double start, return result; } -void GenerateJoinsTriangles(glsl::vec3 const & pivot, vector const & normals, glsl::vec4 const & color, - glsl::vec2 const & length, bool isLeft, RouteShape::TGeometryBuffer & joinsGeometry) +void GenerateJoinsTriangles(glsl::vec3 const & pivot, std::vector const & normals, + glsl::vec4 const & color, glsl::vec2 const & length, bool isLeft, + RouteShape::TGeometryBuffer & joinsGeometry) { float const kEps = 1e-5; size_t const trianglesCount = normals.size() / 3; @@ -110,8 +107,8 @@ glsl::vec2 GetUV(m2::RectF const & texRect, glsl::vec2 const & uv) return GetUV(texRect, uv.x, uv.y); } -void GenerateArrowsTriangles(glsl::vec4 const & pivot, vector const & normals, - m2::RectF const & texRect, vector const & uv, +void GenerateArrowsTriangles(glsl::vec4 const & pivot, std::vector const & normals, + m2::RectF const & texRect, std::vector const & uv, bool normalizedUV, RouteShape::TArrowGeometryBuffer & joinsGeometry) { size_t const trianglesCount = normals.size() / 3; @@ -128,15 +125,15 @@ void GenerateArrowsTriangles(glsl::vec4 const & pivot, vector const } // namespace -void RouteShape::PrepareGeometry(vector const & path, m2::PointD const & pivot, - vector const & segmentsColors, +void RouteShape::PrepareGeometry(std::vector const & path, m2::PointD const & pivot, + std::vector const & segmentsColors, TGeometryBuffer & geometry, TGeometryBuffer & joinsGeometry, double & outputLength) { ASSERT(path.size() > 1, ()); // Construct segments. - vector segments; + std::vector segments; segments.reserve(path.size() - 1); ConstructLineSegments(path, segmentsColors, segments); @@ -199,7 +196,7 @@ void RouteShape::PrepareGeometry(vector const & path, m2::PointD con float widthScalar = segments[i].m_hasLeftJoin[EndPoint] ? segments[i].m_rightWidthScalar[EndPoint].x : segments[i].m_leftWidthScalar[EndPoint].x; - vector normals; + std::vector normals; normals.reserve(24); GenerateJoinNormals(dp::RoundJoin, n1, n2, 1.0f, segments[i].m_hasLeftJoin[EndPoint], widthScalar, normals); @@ -211,7 +208,7 @@ void RouteShape::PrepareGeometry(vector const & path, m2::PointD con // Generate caps. if (i == 0) { - vector normals; + std::vector normals; normals.reserve(24); GenerateCapNormals(dp::RoundCap, segments[i].m_leftNormals[StartPoint], segments[i].m_rightNormals[StartPoint], -segments[i].m_tangent, @@ -223,7 +220,7 @@ void RouteShape::PrepareGeometry(vector const & path, m2::PointD con if (i == static_cast(segments.size()) - 1) { - vector normals; + std::vector normals; normals.reserve(24); GenerateCapNormals(dp::RoundCap, segments[i].m_leftNormals[EndPoint], segments[i].m_rightNormals[EndPoint], segments[i].m_tangent, @@ -237,20 +234,20 @@ void RouteShape::PrepareGeometry(vector const & path, m2::PointD con } } -void RouteShape::PrepareArrowGeometry(vector const & path, m2::PointD const & pivot, +void RouteShape::PrepareArrowGeometry(std::vector const & path, m2::PointD const & pivot, m2::RectF const & texRect, float depthStep, float depth, TArrowGeometryBuffer & geometry, TArrowGeometryBuffer & joinsGeometry) { ASSERT(path.size() > 1, ()); // Construct segments. - vector segments; + std::vector segments; segments.reserve(path.size() - 1); - ConstructLineSegments(path, vector(), segments); + ConstructLineSegments(path, std::vector(), segments); m2::RectF tr = texRect; - tr.setMinX(texRect.minX() * (1.0 - kArrowTailSize) + texRect.maxX() * kArrowTailSize); - tr.setMaxX(texRect.minX() * kArrowHeadSize + texRect.maxX() * (1.0 - kArrowHeadSize)); + tr.setMinX(static_cast(texRect.minX() * (1.0 - kArrowTailSize) + texRect.maxX() * kArrowTailSize)); + tr.setMaxX(static_cast(texRect.minX() * kArrowHeadSize + texRect.maxX() * (1.0 - kArrowHeadSize))); // Build geometry. float const depthInc = depthStep / (segments.size() + 1); @@ -300,9 +297,9 @@ void RouteShape::PrepareArrowGeometry(vector const & path, m2::Point segments[i].m_leftWidthScalar[EndPoint].x; int const kAverageSize = 24; - vector normals; + std::vector normals; normals.reserve(kAverageSize); - vector uv; + std::vector uv; uv.reserve(kAverageSize); GenerateJoinNormals(dp::RoundJoin, n1, n2, 1.0f, segments[i].m_hasLeftJoin[EndPoint], @@ -316,14 +313,14 @@ void RouteShape::PrepareArrowGeometry(vector const & path, m2::Point // Generate arrow head. if (i == segments.size() - 1) { - vector normals = + std::vector normals = { segments[i].m_rightNormals[EndPoint], segments[i].m_leftNormals[EndPoint], kArrowHeadFactor * segments[i].m_tangent }; - float const u = 1.0f - kArrowHeadSize; - vector uv = { glsl::vec2(u, 1.0f), glsl::vec2(u, 0.0f), glsl::vec2(1.0f, 0.5f) }; + float const u = 1.0f - static_cast(kArrowHeadSize); + std::vector uv = { glsl::vec2(u, 1.0f), glsl::vec2(u, 0.0f), glsl::vec2(1.0f, 0.5f) }; glsl::vec4 const headPivot = glsl::vec4(glsl::ToVec2(endPt), depth, 1.0); depth += depthInc; GenerateArrowsTriangles(headPivot, normals, texRect, uv, true /* normalizedUV */, joinsGeometry); @@ -336,11 +333,11 @@ void RouteShape::PrepareArrowGeometry(vector const & path, m2::Point glsl::vec2 const n2 = segments[i].m_rightNormals[StartPoint]; glsl::vec2 const n3 = (n1 - kArrowTailFactor * segments[i].m_tangent); glsl::vec2 const n4 = (n2 - kArrowTailFactor * segments[i].m_tangent); - vector normals = { n2, n4, n1, n1, n4, n3 }; + std::vector normals = { n2, n4, n1, n1, n4, n3 }; m2::RectF t = texRect; t.setMaxX(tr.minX()); - vector uv = + std::vector uv = { glsl::ToVec2(t.RightBottom()), glsl::ToVec2(t.LeftBottom()), @@ -395,7 +392,8 @@ void RouteShape::CacheRouteSign(ref_ptr mng, RouteSignData & } void RouteShape::CacheRouteArrows(ref_ptr mng, m2::PolylineD const & polyline, - vector const & borders, RouteArrowsData & routeArrowsData) + std::vector const & borders, + RouteArrowsData & routeArrowsData) { TArrowGeometryBuffer geometry; TArrowGeometryBuffer joinsGeometry; @@ -410,7 +408,7 @@ void RouteShape::CacheRouteArrows(ref_ptr mng, m2::PolylineD for (ArrowBorders const & b : borders) { depth -= depthStep; - vector points = CalculatePoints(polyline, b.m_startDistance, b.m_endDistance); + std::vector points = CalculatePoints(polyline, b.m_startDistance, b.m_endDistance); ASSERT_LESS_OR_EQUAL(points.size(), polyline.GetSize(), ()); PrepareArrowGeometry(points, routeArrowsData.m_pivot, region.GetTexRect(), depthStep, depth, geometry, joinsGeometry); @@ -423,12 +421,13 @@ void RouteShape::CacheRouteArrows(ref_ptr mng, m2::PolylineD void RouteShape::CacheRoute(ref_ptr textures, RouteData & routeData) { - vector segmentsColors; + std::vector segmentsColors; segmentsColors.reserve(routeData.m_traffic.size()); - for (auto const & speedGroup : routeData.m_traffic) + for (auto speedGroup : routeData.m_traffic) { - dp::Color const color = df::GetColorConstant(TrafficGenerator::GetColorBySpeedGroup(speedGroup, - true /* route */)); + speedGroup = TrafficGenerator::CheckColorsSimplification(speedGroup); + auto const colorConstant = TrafficGenerator::GetColorBySpeedGroup(speedGroup, true /* route */); + dp::Color const color = df::GetColorConstant(colorConstant); float const alpha = (speedGroup == traffic::SpeedGroup::G4 || speedGroup == traffic::SpeedGroup::G5 || speedGroup == traffic::SpeedGroup::Unknown) ? 0.0f : 1.0f; @@ -479,5 +478,4 @@ void RouteShape::BatchGeometry(dp::GLState const & state, ref_ptr geometry } } } - -} // namespace df +} // namespace df diff --git a/drape_frontend/route_shape.hpp b/drape_frontend/route_shape.hpp index 039332246a..bab193800d 100644 --- a/drape_frontend/route_shape.hpp +++ b/drape_frontend/route_shape.hpp @@ -13,11 +13,10 @@ #include "geometry/polyline2d.hpp" -#include "std/vector.hpp" +#include namespace df { - double const kArrowSize = 0.0008; // Constants below depend on arrow texture. @@ -28,9 +27,9 @@ double const kArrowHeadTextureWidth = 32.0; double const kArrowTailTextureWidth = 4.0; double const kArrowHeadSize = kArrowHeadTextureWidth / kArrowTextureWidth; -float const kArrowHeadFactor = 2.0 * kArrowHeadTextureWidth / kArrowTextureHeight; +float const kArrowHeadFactor = static_cast(2.0 * kArrowHeadTextureWidth / kArrowTextureHeight); double const kArrowTailSize = kArrowTailTextureWidth / kArrowTextureWidth; -float const kArrowTailFactor = 2.0 * kArrowTailTextureWidth / kArrowTextureHeight; +float const kArrowTailFactor = static_cast(2.0 * kArrowTailTextureWidth / kArrowTextureHeight); double const kArrowHeightFactor = kArrowTextureHeight / kArrowBodyHeight; double const kArrowAspect = kArrowTextureWidth / kArrowTextureHeight; @@ -52,7 +51,7 @@ struct RoutePattern struct RouteRenderProperty { dp::GLState m_state; - vector> m_buckets; + std::vector> m_buckets; RouteRenderProperty() : m_state(0, dp::GLState::GeometryLayer) {} }; @@ -67,10 +66,10 @@ struct RouteData { int m_routeIndex; m2::PolylineD m_sourcePolyline; - vector m_sourceTurns; + std::vector m_sourceTurns; m2::PointD m_pivot; df::ColorConstant m_color; - vector m_traffic; + std::vector m_traffic; double m_length; RouteRenderProperty m_route; RoutePattern m_pattern; @@ -104,19 +103,20 @@ public: static void CacheRoute(ref_ptr textures, RouteData & routeData); static void CacheRouteSign(ref_ptr mng, RouteSignData & routeSignData); static void CacheRouteArrows(ref_ptr mng, m2::PolylineD const & polyline, - vector const & borders, RouteArrowsData & routeArrowsData); + std::vector const & borders, + RouteArrowsData & routeArrowsData); private: - static void PrepareGeometry(vector const & path, m2::PointD const & pivot, - vector const & segmentsColors, + static void PrepareGeometry(std::vector const & path, m2::PointD const & pivot, + std::vector const & segmentsColors, TGeometryBuffer & geometry, TGeometryBuffer & joinsGeometry, double & outputLength); - static void PrepareArrowGeometry(vector const & path, m2::PointD const & pivot, + static void PrepareArrowGeometry(std::vector const & path, m2::PointD const & pivot, m2::RectF const & texRect, float depthStep, float depth, - TArrowGeometryBuffer & geometry, TArrowGeometryBuffer & joinsGeometry); + TArrowGeometryBuffer & geometry, + TArrowGeometryBuffer & joinsGeometry); static void BatchGeometry(dp::GLState const & state, ref_ptr geometry, uint32_t geomSize, ref_ptr joinsGeometry, uint32_t joinsGeomSize, dp::BindingInfo const & bindingInfo, RouteRenderProperty & property); }; - -} // namespace df +} // namespace df diff --git a/drape_frontend/traffic_generator.cpp b/drape_frontend/traffic_generator.cpp index 5a1178c60e..581bc70be5 100644 --- a/drape_frontend/traffic_generator.cpp +++ b/drape_frontend/traffic_generator.cpp @@ -345,7 +345,17 @@ void TrafficGenerator::SetSimplifiedColorSchemeEnabled(bool enabled) } // static -df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup const & speedGroup, bool route) +traffic::SpeedGroup TrafficGenerator::CheckColorsSimplification(traffic::SpeedGroup speedGroup) +{ + traffic::SpeedGroup group = speedGroup; + // In simplified color scheme we reduce amount of speed groups visually. + if (m_simplifiedColorScheme && speedGroup == traffic::SpeedGroup::G4) + group = traffic::SpeedGroup::G3; + return group; +} + +// static +df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup speedGroup, bool route) { size_t constexpr kSpeedGroupsCount = static_cast(traffic::SpeedGroup::Count); static array const kColorMap @@ -372,12 +382,7 @@ df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup con "TrafficUnknown", }}; - traffic::SpeedGroup group = speedGroup; - // In simplified color scheme we reduce amount of speed groups visually. - if (m_simplifiedColorScheme && speedGroup == traffic::SpeedGroup::G4) - group = traffic::SpeedGroup::G3; - - size_t const index = static_cast(group); + size_t const index = static_cast(CheckColorsSimplification(speedGroup)); ASSERT_LESS(index, kSpeedGroupsCount, ()); return route ? kColorMapRoute[index] : kColorMap[index]; } diff --git a/drape_frontend/traffic_generator.hpp b/drape_frontend/traffic_generator.hpp index 3bc9d4608a..1b42fd01f0 100644 --- a/drape_frontend/traffic_generator.hpp +++ b/drape_frontend/traffic_generator.hpp @@ -148,7 +148,8 @@ public: void InvalidateTexturesCache(); static void SetSimplifiedColorSchemeEnabled(bool enabled); - static df::ColorConstant GetColorBySpeedGroup(traffic::SpeedGroup const & speedGroup, bool route); + static traffic::SpeedGroup CheckColorsSimplification(traffic::SpeedGroup speedGroup); + static df::ColorConstant GetColorBySpeedGroup(traffic::SpeedGroup speedGroup, bool route); private: struct TrafficBatcherKey