Improved tiles loading on 17-19 zoom levels

This commit is contained in:
Roman Kuznetsov 2015-12-12 19:04:11 +03:00
parent 33ffa1358b
commit f24cd64d0a
8 changed files with 55 additions and 28 deletions

View file

@ -48,6 +48,7 @@ FrontendRenderer::FrontendRenderer(Params const & params)
, m_userPositionChangedFn(params.m_positionChangedFn)
, m_tileTree(new TileTree())
, m_requestedTiles(params.m_requestedTiles)
, m_maxGeneration(0)
{
#ifdef DRAW_INFO
m_tpf = 0.0;
@ -120,8 +121,8 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
bucket->GetBuffer()->Build(program);
if (!IsUserMarkLayer(key))
{
CheckTileGenerations(key);
m_tileTree->ProcessTile(key, GetCurrentZoomLevel(), state, move(bucket));
if (CheckTileGenerations(key))
m_tileTree->ProcessTile(key, GetCurrentZoomLevelForData(), state, move(bucket));
}
else
{
@ -134,7 +135,9 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::FinishReading:
{
ref_ptr<FinishReadingMessage> msg = message;
m_tileTree->FinishTiles(msg->GetTiles(), GetCurrentZoomLevel());
for (auto const & tileKey : msg->GetTiles())
CheckTileGenerations(tileKey);
m_tileTree->FinishTiles(msg->GetTiles(), GetCurrentZoomLevelForData());
break;
}
@ -537,13 +540,20 @@ void FrontendRenderer::RemoveRenderGroups(TRenderGroupRemovePredicate const & pr
m_deferredRenderGroups.end());
}
void FrontendRenderer::CheckTileGenerations(TileKey const & tileKey)
bool FrontendRenderer::CheckTileGenerations(TileKey const & tileKey)
{
bool const result = (tileKey.m_generation >= m_maxGeneration);
if (tileKey.m_generation > m_maxGeneration)
m_maxGeneration = tileKey.m_generation;
auto removePredicate = [&tileKey](drape_ptr<RenderGroup> const & group)
{
return group->GetTileKey() == tileKey && group->GetTileKey().m_generation < tileKey.m_generation;
};
RemoveRenderGroups(removePredicate);
return result;
}
void FrontendRenderer::OnCompassTapped()
@ -756,6 +766,12 @@ int FrontendRenderer::GetCurrentZoomLevel() const
return m_currentZoomLevel;
}
int FrontendRenderer::GetCurrentZoomLevelForData() const
{
int const upperScale = scales::GetUpperScale();
return (m_currentZoomLevel <= upperScale ? m_currentZoomLevel : upperScale);
}
void FrontendRenderer::ResolveZoomLevel(ScreenBase const & screen)
{
m_currentZoomLevel = GetDrawTileScale(screen);
@ -864,9 +880,10 @@ void FrontendRenderer::ResolveTileKeys(ScreenBase const & screen, TTilesCollecti
void FrontendRenderer::ResolveTileKeys(m2::RectD const & rect, TTilesCollection & tiles)
{
// equal for x and y
int const tileScale = GetCurrentZoomLevel();
int const zoomLevel = GetCurrentZoomLevelForData();
double const range = MercatorBounds::maxX - MercatorBounds::minX;
double const rectSize = range / (1 << tileScale);
double const rectSize = range / (1 << zoomLevel);
int const minTileX = static_cast<int>(floor(rect.minX() / rectSize));
int const maxTileX = static_cast<int>(ceil(rect.maxX() / rectSize));
@ -874,14 +891,15 @@ void FrontendRenderer::ResolveTileKeys(m2::RectD const & rect, TTilesCollection
int const maxTileY = static_cast<int>(ceil(rect.maxY() / rectSize));
// request new tiles
m_tileTree->BeginRequesting(tileScale, rect);
m_tileTree->BeginRequesting(zoomLevel, rect);
for (int tileY = minTileY; tileY < maxTileY; ++tileY)
{
for (int tileX = minTileX; tileX < maxTileX; ++tileX)
{
TileKey key(tileX, tileY, tileScale);
TileKey key(tileX, tileY, zoomLevel);
if (rect.IsIntersect(key.GetGlobalRect()))
{
key.m_styleZoomLevel = GetCurrentZoomLevel();
tiles.insert(key);
m_tileTree->RequestTile(key);
}
@ -1072,7 +1090,7 @@ void FrontendRenderer::UpdateScene(ScreenBase const & modelView)
auto removePredicate = [this](drape_ptr<RenderGroup> const & group)
{
return group->IsOverlay() && group->GetTileKey().m_zoomLevel > GetCurrentZoomLevel();
return group->IsOverlay() && group->GetTileKey().m_styleZoomLevel > GetCurrentZoomLevel();
};
RemoveRenderGroups(removePredicate);

View file

@ -147,6 +147,7 @@ private:
void ResolveTileKeys(ScreenBase const & screen, TTilesCollection & tiles);
void ResolveTileKeys(m2::RectD const & rect, TTilesCollection & tiles);
int GetCurrentZoomLevel() const;
int GetCurrentZoomLevelForData() const;
void ResolveZoomLevel(ScreenBase const & screen);
void OnTap(m2::PointD const & pt, bool isLong) override;
@ -197,7 +198,7 @@ private:
using TRenderGroupRemovePredicate = function<bool(drape_ptr<RenderGroup> const &)>;
void RemoveRenderGroups(TRenderGroupRemovePredicate const & predicate);
void CheckTileGenerations(TileKey const & tileKey);
bool CheckTileGenerations(TileKey const & tileKey);
void OnCompassTapped();
@ -230,6 +231,7 @@ private:
unique_ptr<TileTree> m_tileTree;
int m_currentZoomLevel = -1;
ref_ptr<RequestedTiles> m_requestedTiles;
uint64_t m_maxGeneration;
};
} // namespace df

View file

@ -171,8 +171,8 @@ size_t ReadManager::ReadCount()
bool ReadManager::MustDropAllTiles(ScreenBase const & screen) const
{
int const oldScale = df::GetTileScaleBase(m_currentViewport);
int const newScale = df::GetTileScaleBase(screen);
int const oldScale = df::GetDrawTileScale(m_currentViewport);
int const newScale = df::GetDrawTileScale(screen);
return (oldScale != newScale) || !m_currentViewport.GlobalRect().IsIntersect(screen.GlobalRect());
}

View file

@ -50,9 +50,11 @@ RuleDrawer::RuleDrawer(TDrawerCallback const & fn,
m_globalRect = m_context->GetTileKey().GetGlobalRect();
int32_t tileSize = df::VisualParams::Instance().GetTileSize();
m_geometryConvertor.OnSize(0, 0, tileSize, tileSize);
m_geometryConvertor.SetFromRect(m2::AnyRectD(m_globalRect));
m_currentScaleGtoP = 1.0f / m_geometryConvertor.GetScale();
m2::RectD const r = m_context->GetTileKey().GetGlobalRect(true /* considerStyleZoom */);
ScreenBase geometryConvertor;
geometryConvertor.OnSize(0, 0, tileSize, tileSize);
geometryConvertor.SetFromRect(m2::AnyRectD(r));
m_currentScaleGtoP = 1.0f / geometryConvertor.GetScale();
for (size_t i = 0; i < m_mapShapes.size(); i++)
m_mapShapes[i].reserve(kMinFlushSizes[i] + 1);

View file

@ -43,7 +43,6 @@ private:
ref_ptr<EngineContext> m_context;
m2::RectD m_globalRect;
ScreenBase m_geometryConvertor;
double m_currentScaleGtoP;
array<TMapShapes, df::PrioritiesCount> m_mapShapes;

View file

@ -99,11 +99,9 @@ void TileInfo::ProcessID(FeatureID const & id)
void TileInfo::InitStylist(FeatureType const & f, Stylist & s)
{
CheckCanceled();
df::InitStylist(f, m_context->GetTileKey().m_zoomLevel, s);
df::InitStylist(f, m_context->GetTileKey().m_styleZoomLevel, s);
}
//====================================================//
bool TileInfo::DoNeedReadIndex() const
{
return m_featureInfo.empty();
@ -117,9 +115,8 @@ void TileInfo::CheckCanceled() const
int TileInfo::GetZoomLevel() const
{
int const upperScale = scales::GetUpperScale();
int const zoomLevel = m_context->GetTileKey().m_zoomLevel;
return (zoomLevel <= upperScale ? zoomLevel : upperScale);
ASSERT_LESS_OR_EQUAL(m_context->GetTileKey().m_zoomLevel, scales::GetUpperScale(), ());
return m_context->GetTileKey().m_zoomLevel;
}
} // namespace df

View file

@ -6,16 +6,23 @@ namespace df
{
TileKey::TileKey()
: m_x(-1), m_y(-1), m_zoomLevel(-1), m_generation(0)
: m_x(-1), m_y(-1),
m_zoomLevel(-1),
m_styleZoomLevel(-1),
m_generation(0)
{}
TileKey::TileKey(int x, int y, int zoomLevel)
: m_x(x), m_y(y), m_zoomLevel(zoomLevel), m_generation(0)
: m_x(x), m_y(y),
m_zoomLevel(zoomLevel),
m_styleZoomLevel(zoomLevel),
m_generation(0)
{}
TileKey::TileKey(TileKey const & key, uint64_t generation)
: m_x(key.m_x), m_y(key.m_y),
m_zoomLevel(key.m_zoomLevel),
m_styleZoomLevel(key.m_styleZoomLevel),
m_generation(generation)
{}
@ -37,9 +44,9 @@ bool TileKey::operator ==(TileKey const & other) const
m_zoomLevel == other.m_zoomLevel;
}
m2::RectD TileKey::GetGlobalRect() const
m2::RectD TileKey::GetGlobalRect(bool considerStyleZoom) const
{
double const worldSizeDevisor = 1 << m_zoomLevel;
double const worldSizeDevisor = 1 << (considerStyleZoom ? m_styleZoomLevel : m_zoomLevel);
// Mercator SizeX and SizeY is equal
double const rectSize = (MercatorBounds::maxX - MercatorBounds::minX) / worldSizeDevisor;
@ -53,7 +60,8 @@ string DebugPrint(TileKey const & key)
{
ostringstream out;
out << "[x = " << key.m_x << ", y = " << key.m_y << ", zoomLevel = "
<< key.m_zoomLevel << ", gen = " << key.m_generation << "]";
<< key.m_zoomLevel << ", styleZoomLevel = " << key.m_styleZoomLevel
<< ", gen = " << key.m_generation << "]";
return out.str();
}

View file

@ -26,11 +26,12 @@ struct TileKey
bool operator < (TileKey const & other) const;
bool operator == (TileKey const & other) const;
m2::RectD GetGlobalRect() const;
m2::RectD GetGlobalRect(bool considerStyleZoom = false) const;
int m_x;
int m_y;
int m_zoomLevel;
int m_styleZoomLevel;
uint64_t m_generation;
};