Merge pull request #537 from rokuz/p2p-rendering

Added showing of start and finish points in p2p mode
This commit is contained in:
Vlad Mihaylenko 2015-11-16 12:59:56 +03:00
commit ea9b3a5551
7 changed files with 153 additions and 46 deletions

View file

@ -263,6 +263,9 @@ extern NSString * const kAlohalyticsTapEventKey;
MapsAppDelegate.theApp.routingPlaneMode = MWMRoutingPlaneModePlacePage;
[self setupBestRouter];
[self buildRoute];
GetFramework().SetRouteStartPoint(from.Point());
GetFramework().SetRouteFinishPoint(to.Point());
}
- (void)buildRouteFrom:(MWMRoutePoint const &)from
@ -274,6 +277,8 @@ extern NSString * const kAlohalyticsTapEventKey;
if (IPAD)
self.searchManager.state = MWMSearchManagerStateHidden;
[self buildRoute];
GetFramework().SetRouteStartPoint(from.Point());
}
- (void)buildRouteTo:(MWMRoutePoint const &)to
@ -285,6 +290,8 @@ extern NSString * const kAlohalyticsTapEventKey;
if (IPAD)
self.searchManager.state = MWMSearchManagerStateHidden;
[self buildRoute];
GetFramework().SetRouteFinishPoint(to.Point());
}
#pragma mark - MWMNavigationDashboardManager
@ -447,6 +454,9 @@ extern NSString * const kAlohalyticsTapEventKey;
withParameters:@{kStatAction : kStatSwapRoutingPoints}];
swap(_routeSource, _routeDestination);
[self buildRoute];
GetFramework().SetRouteStartPoint(self.routeSource.Point());
GetFramework().SetRouteFinishPoint(self.routeDestination.Point());
}
- (void)didStartEditingRoutePoint:(BOOL)isSource

View file

@ -486,6 +486,16 @@ void BookmarkManager::UpdateRouteDistanceFromBegin(double distance)
m_routeRenderer->UpdateDistanceFromBegin(distance);
}
void BookmarkManager::SetRouteStartPoint(m2::PointD const & pt)
{
m_routeRenderer->SetRoutePoint(pt, true /* start */);
}
void BookmarkManager::SetRouteFinishPoint(m2::PointD const & pt)
{
m_routeRenderer->SetRoutePoint(pt, false /* start */);
}
UserMarkContainer const * BookmarkManager::FindUserMarksContainer(UserMarkContainer::Type type) const
{
ASSERT(type >= 0 && type < m_userMarkLayers.size(), ());

View file

@ -92,6 +92,8 @@ public:
graphics::Color const & color);
void ResetRouteTrack();
void UpdateRouteDistanceFromBegin(double distance);
void SetRouteStartPoint(m2::PointD const & pt);
void SetRouteFinishPoint(m2::PointD const & pt);
private:
UserMarkContainer const * FindUserMarksContainer(UserMarkContainer::Type type) const;

View file

@ -2409,3 +2409,13 @@ void Framework::SetLastUsedRouter(RouterType type)
{
Settings::Set(kRouterTypeKey, routing::ToString(type));
}
void Framework::SetRouteStartPoint(m2::PointD const & pt)
{
m_bmManager.SetRouteStartPoint(pt);
}
void Framework::SetRouteFinishPoint(m2::PointD const & pt)
{
m_bmManager.SetRouteFinishPoint(pt);
}

View file

@ -630,6 +630,9 @@ public:
return m_routingSession.GenerateTurnNotifications(turnNotifications);
}
void SetRouteStartPoint(m2::PointD const & pt);
void SetRouteFinishPoint(m2::PointD const & pt);
private:
void SetRouterImpl(routing::RouterType type);
void RemoveRoute();

View file

@ -227,21 +227,29 @@ float NormColor(uint8_t value)
}
RouteRenderer::RouteRenderer()
: m_endOfRouteDisplayList(nullptr)
, m_arrowDisplayList(nullptr)
: m_arrowDisplayList(nullptr)
, m_distanceFromBegin(0.0)
, m_needClearGraphics(false)
, m_needClearData(false)
, m_waitForConstruction(false)
{}
{
}
RouteRenderer::~RouteRenderer()
{
ASSERT(m_routeGraphics.empty(), ());
ASSERT(m_endOfRouteDisplayList == nullptr, ());
ASSERT(m_startRoutePoint.m_displayList == nullptr, ());
ASSERT(m_finishRoutePoint.m_displayList == nullptr, ());
ASSERT(m_arrowDisplayList == nullptr, ());
}
void RouteRenderer::SetRoutePoint(m2::PointD const & pt, bool start)
{
RoutePoint & pnt = start ? m_startRoutePoint : m_finishRoutePoint;
pnt.m_point = pt;
pnt.m_needUpdate = true;
}
void RouteRenderer::Setup(m2::PolylineD const & routePolyline, vector<double> const & turns, graphics::Color const & color)
{
if (!m_routeData.m_geometry.empty())
@ -251,10 +259,15 @@ void RouteRenderer::Setup(m2::PolylineD const & routePolyline, vector<double> co
m_turns = turns;
m_color = color;
m_endOfRoutePoint = routePolyline.Back();
m_distanceFromBegin = 0.0;
m_polyline = routePolyline;
if (!m_startRoutePoint.IsVisible())
SetRoutePoint(m_polyline.Front(), true /* start */);
if (!m_finishRoutePoint.IsVisible())
SetRoutePoint(m_polyline.Back(), false /* start */);
m_waitForConstruction = true;
}
@ -309,10 +322,6 @@ void RouteRenderer::ConstructRoute(graphics::Screen * dlScreen)
dlScreen->setDisplayList(m_arrowDisplayList);
dlScreen->drawRouteGeometry(texture, m_arrowsStorage);
m_endOfRouteDisplayList = dlScreen->createDisplayList();
dlScreen->setDisplayList(m_endOfRouteDisplayList);
dlScreen->drawSymbol(m_endOfRoutePoint, "route_to", graphics::EPosCenter, 0);
dlScreen->setDisplayList(nullptr);
m_waitForConstruction = false;
@ -361,19 +370,40 @@ void RouteRenderer::DestroyDisplayLists()
{
m_routeGraphics.clear();
DestroyRoutePointGraphics(true /* start */);
DestroyRoutePointGraphics(false /* start */);
if (m_arrowDisplayList != nullptr)
{
delete m_arrowDisplayList;
m_arrowDisplayList = nullptr;
}
}
if (m_endOfRouteDisplayList != nullptr)
void RouteRenderer::CreateRoutePointGraphics(graphics::Screen * dlScreen, bool start)
{
RoutePoint & pnt = start ? m_startRoutePoint : m_finishRoutePoint;
if (pnt.m_needUpdate)
{
delete m_endOfRouteDisplayList;
m_endOfRouteDisplayList = nullptr;
DestroyRoutePointGraphics(start);
pnt.m_displayList = dlScreen->createDisplayList();
dlScreen->setDisplayList(pnt.m_displayList);
dlScreen->drawSymbol(pnt.m_point, start ? "route_from" : "route_to", graphics::EPosCenter, 0);
dlScreen->setDisplayList(nullptr);
pnt.m_needUpdate = false;
}
}
void RouteRenderer::DestroyRoutePointGraphics(bool start)
{
if (start)
m_startRoutePoint.Reset();
else
m_finishRoutePoint.Reset();
}
void RouteRenderer::InterpolateByZoom(ScreenBase const & screen, float & halfWidth, float & alpha, double & zoom) const
{
double const zoomLevel = my::clamp(fabs(log(screen.GetScale()) / log(2.0)), 1.0, scales::UPPER_STYLE_SCALE + 1.0);
@ -409,44 +439,57 @@ void RouteRenderer::Render(graphics::Screen * dlScreen, ScreenBase const & scree
if (m_waitForConstruction)
ConstructRoute(dlScreen);
if (m_routeGraphics.empty())
return;
// route points
CreateRoutePointGraphics(dlScreen, true /* start */);
CreateRoutePointGraphics(dlScreen, false /* start */);
ASSERT_EQUAL(m_routeGraphics.size(), m_routeData.m_geometry.size(), ());
// rendering
dlScreen->clear(graphics::Color(), false, 1.0f, true);
// interpolate values by zoom level
double zoom = 0.0;
float halfWidth = 0.0;
float alpha = 0.0;
InterpolateByZoom(screen, halfWidth, alpha, zoom);
// set up uniforms
graphics::UniformsHolder uniforms;
uniforms.insertValue(graphics::ERouteColor, NormColor(m_color.r), NormColor(m_color.g), NormColor(m_color.b), alpha);
uniforms.insertValue(graphics::ERouteHalfWidth, halfWidth, halfWidth * screen.GetScale());
uniforms.insertValue(graphics::ERouteClipLength, m_distanceFromBegin);
// render routes
dlScreen->applyRouteStates();
for (size_t i = 0; i < m_routeGraphics.size(); ++i)
if (!m_routeGraphics.empty())
{
RouteGraphics & graphics = m_routeGraphics[i];
if (!screen.ClipRect().IsIntersect(m_routeData.m_boundingBoxes[i]))
continue;
ASSERT_EQUAL(m_routeGraphics.size(), m_routeData.m_geometry.size(), ());
size_t const indicesCount = graphics.m_storage.m_indices->size() / sizeof(unsigned short);
dlScreen->drawDisplayList(graphics.m_displayList, screen.GtoPMatrix(), &uniforms, indicesCount);
// rendering
dlScreen->clear(graphics::Color(), false, 1.0f, true);
// interpolate values by zoom level
double zoom = 0.0;
float halfWidth = 0.0;
float alpha = 0.0;
InterpolateByZoom(screen, halfWidth, alpha, zoom);
// set up uniforms
graphics::UniformsHolder uniforms;
uniforms.insertValue(graphics::ERouteColor, NormColor(m_color.r), NormColor(m_color.g), NormColor(m_color.b), alpha);
uniforms.insertValue(graphics::ERouteHalfWidth, halfWidth, halfWidth * screen.GetScale());
uniforms.insertValue(graphics::ERouteClipLength, m_distanceFromBegin);
// render routes
dlScreen->applyRouteStates();
for (size_t i = 0; i < m_routeGraphics.size(); ++i)
{
RouteGraphics & graphics = m_routeGraphics[i];
if (!screen.ClipRect().IsIntersect(m_routeData.m_boundingBoxes[i]))
continue;
size_t const indicesCount = graphics.m_storage.m_indices->size() / sizeof(unsigned short);
dlScreen->drawDisplayList(graphics.m_displayList, screen.GtoPMatrix(), &uniforms, indicesCount);
}
// render arrows
if (zoom >= kArrowAppearingZoomLevel)
RenderArrow(dlScreen, halfWidth, screen);
}
// render arrows
if (zoom >= kArrowAppearingZoomLevel)
RenderArrow(dlScreen, halfWidth, screen);
if (m_startRoutePoint.IsVisible())
{
dlScreen->applyStates();
dlScreen->drawDisplayList(m_startRoutePoint.m_displayList, screen.GtoPMatrix());
}
dlScreen->applyStates();
dlScreen->drawDisplayList(m_endOfRouteDisplayList, screen.GtoPMatrix());
if (m_finishRoutePoint.IsVisible())
{
dlScreen->applyStates();
dlScreen->drawDisplayList(m_finishRoutePoint.m_displayList, screen.GtoPMatrix());
}
}
void RouteRenderer::RenderArrow(graphics::Screen * dlScreen, float halfWidth, ScreenBase const & screen)

View file

@ -69,6 +69,8 @@ public:
void Clear();
void Render(graphics::Screen * dlScreen, ScreenBase const & screen);
void SetRoutePoint(m2::PointD const & pt, bool start);
void UpdateDistanceFromBegin(double distanceFromBegin);
private:
@ -85,6 +87,9 @@ private:
bool RecacheArrows();
void DestroyDisplayLists();
void CreateRoutePointGraphics(graphics::Screen * dlScreen, bool start);
void DestroyRoutePointGraphics(bool start);
struct RouteGraphics
{
graphics::DisplayList * m_displayList;
@ -101,8 +106,33 @@ private:
}
};
struct RoutePoint
{
graphics::DisplayList * m_displayList;
m2::PointD m_point;
bool m_needUpdate;
bool IsVisible() const { return m_displayList != nullptr; }
void Reset()
{
if (m_displayList != nullptr)
{
delete m_displayList;
m_displayList = nullptr;
}
}
RoutePoint() : m_displayList(nullptr), m_needUpdate(false) {}
~RoutePoint()
{
Reset();
}
};
vector<RouteGraphics> m_routeGraphics;
graphics::DisplayList * m_endOfRouteDisplayList;
RoutePoint m_startRoutePoint;
RoutePoint m_finishRoutePoint;
graphics::DisplayList * m_arrowDisplayList;
graphics::gl::Storage m_arrowsStorage;
@ -111,7 +141,6 @@ private:
m2::RectF m_arrowTextureRect;
graphics::Color m_color;
vector<double> m_turns;
m2::PointD m_endOfRoutePoint;
m2::PolylineD m_polyline;
ArrowsBuffer m_arrowBuffer;