diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-01-27 14:28:09 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:10:41 +0300 |
commit | 45705dea1fd95a3bdfa3ceaf643208b20bf51941 (patch) | |
tree | c6dc2a0bebc2b3ac312b7498842219287af68995 /drape_frontend/read_manager.cpp | |
parent | e0bff294004d45ac14ccf2e6686b2834d94554d8 (diff) |
[drape] rebase fixes
Diffstat (limited to 'drape_frontend/read_manager.cpp')
-rw-r--r-- | drape_frontend/read_manager.cpp | 234 |
1 files changed, 117 insertions, 117 deletions
diff --git a/drape_frontend/read_manager.cpp b/drape_frontend/read_manager.cpp index 5eb84d879b..b6820cb348 100644 --- a/drape_frontend/read_manager.cpp +++ b/drape_frontend/read_manager.cpp @@ -12,165 +12,165 @@ namespace df { -namespace -{ -struct LessCoverageCell -{ - bool operator()(shared_ptr<TileInfo> const & l, TileKey const & r) const + namespace { - return l->GetTileKey() < r; + struct LessCoverageCell + { + bool operator()(shared_ptr<TileInfo> const & l, TileKey const & r) const + { + return l->GetTileKey() < r; + } + + bool operator()(TileKey const & l, shared_ptr<TileInfo> const & r) const + { + return l < r->GetTileKey(); + } + }; + + TileKey TileInfoPtrToTileKey(shared_ptr<TileInfo> const & p) + { + return p->GetTileKey(); + } } - bool operator()(TileKey const & l, shared_ptr<TileInfo> const & r) const + ReadManager::ReadManager(double visualScale, int w, int h, + EngineContext & context, + model::FeaturesFetcher & model) + : m_context(context) + , m_model(model) { - return l < r->GetTileKey(); + m_scalesProcessor.SetParams(visualScale, ScalesProcessor::CalculateTileSize(w, h)); + m_pool.Reset(new threads::ThreadPool(ReadCount(), bind(&ReadManager::OnTaskFinished, this, _1))); } -}; - -TileKey TileInfoPtrToTileKey(shared_ptr<TileInfo> const & p) -{ - return p->GetTileKey(); -} -} - -ReadManager::ReadManager(double visualScale, int w, int h, - EngineContext & context, - model::FeaturesFetcher & model) - : m_context(context) - , m_model(model) -{ - m_scalesProcessor.SetParams(visualScale, ScalesProcessor::CalculateTileSize(w, h)); - m_pool.Reset(new threads::ThreadPool(ReadCount(), bind(&ReadManager::OnTaskFinished, this, _1))); -} -void ReadManager::OnTaskFinished(threads::IRoutine * task) -{ - delete task; -} + void ReadManager::OnTaskFinished(threads::IRoutine * task) + { + delete task; + } -void ReadManager::UpdateCoverage(const ScreenBase & screen, CoverageUpdateDescriptor & updateDescr) -{ - if (screen == m_currentViewport) - return; + void ReadManager::UpdateCoverage(const ScreenBase & screen, CoverageUpdateDescriptor & updateDescr) + { + if (screen == m_currentViewport) + return; - set<TileKey> tiles; - GetTileKeys(tiles, screen); + set<TileKey> tiles; + GetTileKeys(tiles, screen); - if (MustDropAllTiles(screen)) - { + if (MustDropAllTiles(screen)) + { for_each(m_tileInfos.begin(), m_tileInfos.end(), bind(&ReadManager::CancelTileInfo, this, _1)); - m_tileInfos.clear(); + m_tileInfos.clear(); - for_each(tiles.begin(), tiles.end(), bind(&ReadManager::PushTaskBackForTileKey, this, _1)); + for_each(tiles.begin(), tiles.end(), bind(&ReadManager::PushTaskBackForTileKey, this, _1)); - updateDescr.DoDropAll(); - } - else - { - // Find rects that go out from viewport - buffer_vector<tileinfo_ptr, 8> outdatedTiles; - set_difference(m_tileInfos.begin(), m_tileInfos.end(), - tiles.begin(), tiles.end(), - back_inserter(outdatedTiles), LessCoverageCell()); + updateDescr.DoDropAll(); + } + else + { + // Find rects that go out from viewport + buffer_vector<tileinfo_ptr, 8> outdatedTiles; + set_difference(m_tileInfos.begin(), m_tileInfos.end(), + tiles.begin(), tiles.end(), + back_inserter(outdatedTiles), LessCoverageCell()); - // Find rects that go in into viewport - buffer_vector<TileKey, 8> inputRects; - set_difference(tiles.begin(), tiles.end(), - m_tileInfos.begin(), m_tileInfos.end(), - back_inserter(inputRects), LessCoverageCell()); + // Find rects that go in into viewport + buffer_vector<TileKey, 8> inputRects; + set_difference(tiles.begin(), tiles.end(), + m_tileInfos.begin(), m_tileInfos.end(), + back_inserter(inputRects), LessCoverageCell()); - for_each(outdatedTiles.begin(), outdatedTiles.end(), bind(&ReadManager::ClearTileInfo, this, _1)); + for_each(outdatedTiles.begin(), outdatedTiles.end(), bind(&ReadManager::ClearTileInfo, this, _1)); - buffer_vector<TileKey, 16> outdatedTileKeys; - transform(outdatedTiles.begin(), outdatedTiles.end(), - back_inserter(outdatedTileKeys), &TileInfoPtrToTileKey); + buffer_vector<TileKey, 16> outdatedTileKeys; + transform(outdatedTiles.begin(), outdatedTiles.end(), + back_inserter(outdatedTileKeys), &TileInfoPtrToTileKey); - updateDescr.DropTiles(outdatedTileKeys.data(), outdatedTileKeys.size()); + updateDescr.DropTiles(outdatedTileKeys.data(), outdatedTileKeys.size()); - for_each(m_tileInfos.begin(), m_tileInfos.end(), bind(&ReadManager::PushTaskFront, this, _1)); - for_each(inputRects.begin(), inputRects.end(), bind(&ReadManager::PushTaskBackForTileKey, this, _1)); + for_each(m_tileInfos.begin(), m_tileInfos.end(), bind(&ReadManager::PushTaskFront, this, _1)); + for_each(inputRects.begin(), inputRects.end(), bind(&ReadManager::PushTaskBackForTileKey, this, _1)); + } + m_currentViewport = screen; } - m_currentViewport = screen; -} -void ReadManager::Resize(const m2::RectI & rect) -{ - m_currentViewport.OnSize(rect); -} + void ReadManager::Resize(const m2::RectI & rect) + { + m_currentViewport.OnSize(rect); + } -void ReadManager::Stop() -{ + void ReadManager::Stop() + { for_each(m_tileInfos.begin(), m_tileInfos.end(), bind(&ReadManager::CancelTileInfo, this, _1)); - m_tileInfos.clear(); + m_tileInfos.clear(); - m_pool->Stop(); - m_pool.Destroy(); -} + m_pool->Stop(); + m_pool.Destroy(); + } -size_t ReadManager::ReadCount() -{ - return max(GetPlatform().CpuCores() - 2, 1); -} + size_t ReadManager::ReadCount() + { + return max(GetPlatform().CpuCores() - 2, 1); + } -void ReadManager::GetTileKeys(set<TileKey> & out, ScreenBase const & screen) const -{ - out.clear(); + void ReadManager::GetTileKeys(set<TileKey> & out, ScreenBase const & screen) const + { + out.clear(); - int const tileScale = m_scalesProcessor.GetTileScaleBase(screen); - // equal for x and y - double const range = MercatorBounds::maxX - MercatorBounds::minX; - double const rectSize = range / (1 << tileScale); + int const tileScale = m_scalesProcessor.GetTileScaleBase(screen); + // equal for x and y + double const range = MercatorBounds::maxX - MercatorBounds::minX; + double const rectSize = range / (1 << tileScale); - m2::AnyRectD const & globalRect = screen.GlobalRect(); - m2::RectD const & clipRect = globalRect.GetGlobalRect(); + m2::AnyRectD const & globalRect = screen.GlobalRect(); + m2::RectD const & clipRect = globalRect.GetGlobalRect(); - int const minTileX = static_cast<int>(floor(clipRect.minX() / rectSize)); - int const maxTileX = static_cast<int>(ceil(clipRect.maxX() / rectSize)); - int const minTileY = static_cast<int>(floor(clipRect.minY() / rectSize)); - int const maxTileY = static_cast<int>(ceil(clipRect.maxY() / rectSize)); + int const minTileX = static_cast<int>(floor(clipRect.minX() / rectSize)); + int const maxTileX = static_cast<int>(ceil(clipRect.maxX() / rectSize)); + int const minTileY = static_cast<int>(floor(clipRect.minY() / rectSize)); + int const maxTileY = static_cast<int>(ceil(clipRect.maxY() / rectSize)); - for (int tileY = minTileY; tileY < maxTileY; ++tileY) - for (int tileX = minTileX; tileX < maxTileX; ++tileX) - { - double const left = tileX * rectSize; - double const top = tileY * rectSize; + for (int tileY = minTileY; tileY < maxTileY; ++tileY) + for (int tileX = minTileX; tileX < maxTileX; ++tileX) + { + double const left = tileX * rectSize; + double const top = tileY * rectSize; - m2::RectD currentTileRect(left, top, - left + rectSize, top + rectSize); + m2::RectD currentTileRect(left, top, + left + rectSize, top + rectSize); - if (globalRect.IsIntersect(m2::AnyRectD(currentTileRect))) - out.insert(TileKey(tileX, tileY, tileScale)); - } -} + if (globalRect.IsIntersect(m2::AnyRectD(currentTileRect))) + out.insert(TileKey(tileX, tileY, tileScale)); + } + } -bool ReadManager::MustDropAllTiles(ScreenBase const & screen) const -{ - const int oldScale = m_scalesProcessor.GetTileScaleBase(m_currentViewport); - const int newScale = m_scalesProcessor.GetTileScaleBase(screen); - return (oldScale != newScale) || !m_currentViewport.GlobalRect().IsIntersect(screen.GlobalRect()); -} + bool ReadManager::MustDropAllTiles(ScreenBase const & screen) const + { + const int oldScale = m_scalesProcessor.GetTileScaleBase(m_currentViewport); + const int newScale = m_scalesProcessor.GetTileScaleBase(screen); + return (oldScale != newScale) || !m_currentViewport.GlobalRect().IsIntersect(screen.GlobalRect()); + } -void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey) -{ + void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey) + { tileinfo_ptr tileInfo(new TileInfo(tileKey)); - m_tileInfos.insert(tileInfo); - m_pool->PushBack(new ReadMWMTask(tileInfo, m_memIndex, m_model, m_context)); -} + m_tileInfos.insert(tileInfo); + m_pool->PushBack(new ReadMWMTask(tileInfo, m_memIndex, m_model, m_context)); + } void ReadManager::PushTaskFront(tileinfo_ptr const & tileToReread) -{ - m_pool->PushFront(new ReadMWMTask(tileToReread, m_memIndex, m_model, m_context)); -} + { + m_pool->PushFront(new ReadMWMTask(tileToReread, m_memIndex, m_model, m_context)); + } void ReadManager::CancelTileInfo(tileinfo_ptr tileToCancel) -{ + { tileToCancel->Cancel(m_memIndex); } void ReadManager::ClearTileInfo(tileinfo_ptr & tileToClear) { CancelTileInfo(tileToClear); - m_tileInfos.erase(tileToClear); -} + m_tileInfos.erase(tileToClear); + } } |