Fixed calculation of transit scheme state.

This commit is contained in:
Daria Volvenkova 2018-07-03 17:59:07 +03:00 committed by Roman Kuznetsov
parent 4c7e19e2d5
commit 041cd3e8ae
12 changed files with 59 additions and 58 deletions

View file

@ -436,7 +436,6 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::UpdateTransitScheme:
{
ref_ptr<UpdateTransitSchemeMessage> msg = message;
m_transitBuilder->SetVisibleMwms(msg->GetVisibleMwms());
m_transitBuilder->UpdateSchemes(msg->GetTransitDisplayInfos(), m_texMng);
break;
}

View file

@ -749,12 +749,10 @@ void DrapeEngine::ClearTransitSchemeCache(MwmSet::MwmId const & mwmId)
MessagePriority::Normal);
}
void DrapeEngine::UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos,
std::vector<MwmSet::MwmId> const & visibleMwms)
void DrapeEngine::UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos)
{
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<UpdateTransitSchemeMessage>(std::move(transitDisplayInfos),
visibleMwms),
make_unique_dp<UpdateTransitSchemeMessage>(std::move(transitDisplayInfos)),
MessagePriority::Normal);
}

View file

@ -203,8 +203,7 @@ public:
void SetSimplifiedTrafficColors(bool simplified);
void EnableTransitScheme(bool enable);
void UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos,
std::vector<MwmSet::MwmId> const & visibleMwms);
void UpdateTransitScheme(TransitDisplayInfos && transitDisplayInfos);
void ClearTransitSchemeCache(MwmSet::MwmId const & mwmId);
void SetFontScaleFactor(double scaleFactor);

View file

@ -753,6 +753,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::EnableTransitScheme:
{
ref_ptr<EnableTransitSchemeMessage > msg = message;
m_transitSchemeEnabled = msg->IsEnabled();
if (!msg->IsEnabled())
m_transitSchemeRenderer->ClearGLDependentResources(make_ref(m_overlayTree));
break;
@ -1360,11 +1361,10 @@ void FrontendRenderer::RenderTransitSchemeLayer(ScreenBase const & modelView)
{
GLFunctions::glClear(gl_const::GLDepthBit);
GLFunctions::glEnable(gl_const::GLDepthTest);
if (m_transitSchemeRenderer->HasRenderData(m_currentZoomLevel))
if (m_transitSchemeEnabled && m_transitSchemeRenderer->IsSchemeVisible(m_currentZoomLevel))
{
RenderTransitBackground();
GLFunctions::glEnable(gl_const::GLDepthTest);
m_transitSchemeRenderer->RenderTransit(modelView, m_currentZoomLevel, make_ref(m_gpuProgramManager),
m_transitSchemeRenderer->RenderTransit(modelView, make_ref(m_gpuProgramManager),
make_ref(m_postprocessRenderer), m_generalUniforms);
}
GLFunctions::glDisable(gl_const::GLDepthTest);
@ -1463,7 +1463,7 @@ void FrontendRenderer::BuildOverlayTree(ScreenBase const & modelView)
for (drape_ptr<RenderGroup> & group : overlay.m_renderGroups)
UpdateOverlayTree(modelView, group);
}
if (m_transitSchemeRenderer->HasRenderData(m_currentZoomLevel) && !HasTransitRouteData())
if (m_transitSchemeRenderer->IsSchemeVisible(m_currentZoomLevel) && !HasTransitRouteData())
m_transitSchemeRenderer->CollectOverlays(make_ref(m_overlayTree), modelView);
EndUpdateOverlayTree();
}

View file

@ -318,6 +318,7 @@ private:
bool m_needRestoreSize;
bool m_trafficEnabled;
bool m_transitSchemeEnabled = false;
drape_ptr<OverlaysTracker> m_overlaysTracker;
OverlaysShowStatsCallback m_overlaysShowStatsCallback;

View file

@ -1053,19 +1053,16 @@ private:
class UpdateTransitSchemeMessage : public Message
{
public:
UpdateTransitSchemeMessage(TransitDisplayInfos && transitInfos,
std::vector<MwmSet::MwmId> const & visibleMwms)
: m_transitInfos(move(transitInfos)), m_visibleMwms(visibleMwms)
UpdateTransitSchemeMessage(TransitDisplayInfos && transitInfos)
: m_transitInfos(move(transitInfos))
{}
Type GetType() const override { return Message::UpdateTransitScheme; }
TransitDisplayInfos const & GetTransitDisplayInfos() { return m_transitInfos; }
std::vector<MwmSet::MwmId> const & GetVisibleMwms() const { return m_visibleMwms; }
private:
TransitDisplayInfos m_transitInfos;
std::vector<MwmSet::MwmId> m_visibleMwms;
};
class RegenerateTransitMessage : public Message

View file

@ -274,11 +274,6 @@ bool FindLongerPath(routing::transit::StopId stop1Id, routing::transit::StopId s
}
} // namespace
void TransitSchemeBuilder::SetVisibleMwms(std::vector<MwmSet::MwmId> const & visibleMwms)
{
m_visibleMwms = visibleMwms;
}
void TransitSchemeBuilder::UpdateSchemes(TransitDisplayInfos const & transitDisplayInfos,
ref_ptr<dp::TextureManager> textures)
{

View file

@ -111,8 +111,6 @@ public:
: m_flushRenderDataFn(flushFn)
{}
void SetVisibleMwms(std::vector<MwmSet::MwmId> const & visibleMwms);
void UpdateSchemes(TransitDisplayInfos const & transitDisplayInfos, ref_ptr<dp::TextureManager> textures);
void RebuildSchemes(ref_ptr<dp::TextureManager> textures);
@ -167,7 +165,6 @@ private:
using TransitSchemes = std::map<MwmSet::MwmId, MwmSchemeData>;
TransitSchemes m_schemes;
std::vector<MwmSet::MwmId> m_visibleMwms;
TFlushRenderDataFn m_flushRenderDataFn;

View file

@ -27,9 +27,15 @@ float CalculateHalfWidth(ScreenBase const & screen)
}
} // namespace
bool TransitSchemeRenderer::HasRenderData(int zoomLevel) const
bool TransitSchemeRenderer::IsSchemeVisible(int zoomLevel) const
{
return !m_linesRenderData.empty() && zoomLevel >= kTransitSchemeMinZoomLevel;
return zoomLevel >= kTransitSchemeMinZoomLevel;
}
bool TransitSchemeRenderer::HasRenderData() const
{
return !m_linesRenderData.empty() || !m_linesCapsRenderData.empty() || !m_markersRenderData.empty() ||
!m_textRenderData.empty() || !m_colorSymbolRenderData.empty();
}
void TransitSchemeRenderer::ClearGLDependentResources(ref_ptr<dp::OverlayTree> tree)
@ -123,12 +129,12 @@ void TransitSchemeRenderer::PrepareRenderData(ref_ptr<gpu::ProgramManager> mng,
currentRenderData.emplace_back(std::move(newRenderData));
}
void TransitSchemeRenderer::RenderTransit(ScreenBase const & screen, int zoomLevel,
ref_ptr<gpu::ProgramManager> mng,
void TransitSchemeRenderer::RenderTransit(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
ref_ptr<PostprocessRenderer> postprocessRenderer,
dp::UniformValuesStorage const & commonUniforms)
{
if (!HasRenderData(zoomLevel))
auto const zoomLevel = GetDrawTileScale(screen);
if (!IsSchemeVisible(zoomLevel) || !HasRenderData())
return;
float const pixelHalfWidth = CalculateHalfWidth(screen);

View file

@ -21,10 +21,9 @@ class TransitSchemeRenderer
public:
void AddRenderData(ref_ptr<gpu::ProgramManager> mng, ref_ptr<dp::OverlayTree> tree, TransitRenderData && renderData);
bool HasRenderData(int zoomLevel) const;
bool IsSchemeVisible(int zoomLevel) const;
void RenderTransit(ScreenBase const & screen, int zoomLevel,
ref_ptr<gpu::ProgramManager> mng,
void RenderTransit(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
ref_ptr<PostprocessRenderer> postprocessRenderer,
dp::UniformValuesStorage const & commonUniforms);
@ -61,6 +60,8 @@ private:
void RenderStubs(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms);
bool HasRenderData() const;
uint32_t m_lastRecacheId = 0;
std::vector<TransitRenderData> m_linesRenderData;
std::vector<TransitRenderData> m_linesCapsRenderData;

View file

@ -181,7 +181,6 @@ void TransitReadManager::EnableTransitSchemeMode(bool enable)
m_isSchemeMode = enable;
if (!m_isSchemeMode)
{
m_lastVisibleMwms.clear();
m_lastActiveMwms.clear();
m_mwmCache.clear();
m_cacheSize = 0;
@ -200,18 +199,18 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen)
if (!m_isSchemeMode)
return;
if (df::GetZoomLevel(screen.GetScale()) < kMinSchemeZoomLevel)
if (df::GetDrawTileScale(screen) < kMinSchemeZoomLevel)
{
ChangeState(TransitSchemeState::Enabled);
return;
}
auto mwms = m_getMwmsByRectFn(screen.ClipRect());
if (m_lastVisibleMwms == mwms)
return;
m_lastVisibleMwms = mwms;
m_lastActiveMwms.clear();
auto const currentTime = steady_clock::now();
TransitDisplayInfos displayInfos;
TransitDisplayInfos newTransitData;
for (auto const & mwmId : mwms)
{
if (!mwmId.IsAlive())
@ -220,7 +219,7 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen)
auto it = m_mwmCache.find(mwmId);
if (it == m_mwmCache.end())
{
displayInfos[mwmId] = {};
newTransitData[mwmId] = {};
m_mwmCache.insert(make_pair(mwmId, CacheEntry(currentTime)));
}
else
@ -228,25 +227,37 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen)
it->second.m_lastActiveTime = currentTime;
}
}
GetTransitDisplayInfo(displayInfos);
if (!displayInfos.empty())
{
for (auto const & transitInfo : displayInfos)
{
if (transitInfo.second != nullptr)
{
auto it = m_mwmCache.find(transitInfo.first);
it->second.m_isLoaded = true;
it->second.m_dataSize = CalculateCacheSize(*transitInfo.second);
m_cacheSize += it->second.m_dataSize;
}
if (!newTransitData.empty())
{
GetTransitDisplayInfo(newTransitData);
TransitDisplayInfos validTransitData;
for (auto & transitDataItem : newTransitData)
{
auto & transitInfo = transitDataItem.second;
if (!transitInfo || transitInfo->m_lines.empty())
continue;
auto it = m_mwmCache.find(transitDataItem.first);
it->second.m_isLoaded = true;
auto const dataSize = CalculateCacheSize(*transitInfo);
it->second.m_dataSize = dataSize;
m_cacheSize += dataSize;
validTransitData[transitDataItem.first] = std::move(transitInfo);
}
if (!validTransitData.empty())
{
ShrinkCacheToAllowableSize();
m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, std::move(validTransitData));
}
ShrinkCacheToAllowableSize();
m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, std::move(displayInfos), mwms);
}
bool hasData = false;
bool hasData = m_lastActiveMwms.empty();
for (auto const & mwmId : m_lastActiveMwms)
{
if (m_mwmCache.at(mwmId).m_isLoaded)
@ -279,8 +290,6 @@ void TransitReadManager::Invalidate()
if (!m_isSchemeMode)
return;
m_lastVisibleMwms.clear();
if (m_currentModelView.second)
UpdateViewport(m_currentModelView.first);
}

View file

@ -141,7 +141,6 @@ private:
};
GetMwmsByRectFn m_getMwmsByRectFn;
std::vector<MwmSet::MwmId> m_lastVisibleMwms;
std::set<MwmSet::MwmId> m_lastActiveMwms;
std::map<MwmSet::MwmId, CacheEntry> m_mwmCache;
size_t m_cacheSize = 0;