forked from organicmaps/organicmaps
Added transit scheme callbacks.
This commit is contained in:
parent
7df1cec452
commit
9ef91ae86d
4 changed files with 55 additions and 6 deletions
|
@ -255,6 +255,11 @@ LocalAdsManager & Framework::GetLocalAdsManager()
|
|||
return m_localAdsManager;
|
||||
}
|
||||
|
||||
TransitReadManager & Framework::GetTransitManager()
|
||||
{
|
||||
return m_transitManager;
|
||||
}
|
||||
|
||||
void Framework::OnUserPositionChanged(m2::PointD const & position, bool hasPosition)
|
||||
{
|
||||
GetBookmarkManager().MyPositionMark().SetUserPosition(position, hasPosition);
|
||||
|
@ -1775,6 +1780,9 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
|
|||
|
||||
InvalidateUserMarks();
|
||||
|
||||
bool const transitSchemeEnabled = LoadTransitSchemeEnabled();
|
||||
m_transitManager.EnableTransitSchemeMode(transitSchemeEnabled);
|
||||
|
||||
benchmark::RunGraphicsBenchmark(this);
|
||||
}
|
||||
|
||||
|
@ -2538,15 +2546,13 @@ void Framework::SaveAutoZoom(bool allowAutoZoom)
|
|||
void Framework::EnableTransitScheme(bool enable)
|
||||
{
|
||||
m_transitManager.EnableTransitSchemeMode(enable);
|
||||
if (m_drapeEngine != nullptr)
|
||||
m_drapeEngine->EnableTransitScheme(enable);
|
||||
}
|
||||
|
||||
bool Framework::LoadTransitSchemeEnabled()
|
||||
{
|
||||
bool enabled;
|
||||
if (!settings::Get(kTransitSchemeEnabledKey, enabled))
|
||||
enabled = true;
|
||||
enabled = false;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
|
|
@ -747,13 +747,17 @@ public:
|
|||
|
||||
LocalAdsManager & GetLocalAdsManager();
|
||||
|
||||
TransitReadManager & GetTransitManager();
|
||||
|
||||
bool LoadTrafficEnabled();
|
||||
void SaveTrafficEnabled(bool trafficEnabled);
|
||||
|
||||
bool LoadTrafficSimplifiedColors();
|
||||
void SaveTrafficSimplifiedColors(bool simplified);
|
||||
|
||||
// TODO: Enable transit scheme via transit manager.
|
||||
void EnableTransitScheme(bool enable);
|
||||
|
||||
bool LoadTransitSchemeEnabled();
|
||||
void SaveTransitSchemeEnabled(bool enabled);
|
||||
|
||||
|
|
|
@ -176,6 +176,7 @@ void TransitReadManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
|
|||
|
||||
void TransitReadManager::EnableTransitSchemeMode(bool enable)
|
||||
{
|
||||
ChangeState(enable ? TransitSchemeState::Enabled : TransitSchemeState::Disabled);
|
||||
if (m_isSchemeMode == enable)
|
||||
return;
|
||||
m_isSchemeMode = enable;
|
||||
|
@ -190,6 +191,7 @@ void TransitReadManager::EnableTransitSchemeMode(bool enable)
|
|||
{
|
||||
Invalidate();
|
||||
}
|
||||
m_drapeEngine.SafeCall(&df::DrapeEngine::EnableTransitScheme, enable);
|
||||
}
|
||||
|
||||
void TransitReadManager::UpdateViewport(ScreenBase const & screen)
|
||||
|
@ -242,9 +244,19 @@ void TransitReadManager::UpdateViewport(ScreenBase const & screen)
|
|||
}
|
||||
}
|
||||
ShrinkCacheToAllowableSize();
|
||||
m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme,
|
||||
std::move(displayInfos), mwms);
|
||||
m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTransitScheme, std::move(displayInfos), mwms);
|
||||
}
|
||||
|
||||
bool hasData = false;
|
||||
for (auto const & mwmId : m_lastActiveMwms)
|
||||
{
|
||||
if (m_mwmCache.at(mwmId).m_isLoaded)
|
||||
{
|
||||
hasData = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ChangeState(hasData ? TransitSchemeState::Enabled : TransitSchemeState::NoData);
|
||||
}
|
||||
|
||||
void TransitReadManager::ClearCache(MwmSet::MwmId const & mwmId)
|
||||
|
@ -260,6 +272,7 @@ void TransitReadManager::ClearCache(MwmSet::MwmId const & mwmId)
|
|||
void TransitReadManager::OnMwmDeregistered(MwmSet::MwmId const & mwmId)
|
||||
{
|
||||
ClearCache(mwmId);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void TransitReadManager::Invalidate()
|
||||
|
@ -343,3 +356,17 @@ void TransitReadManager::OnTaskCompleted(threads::IRoutine * task)
|
|||
if (--m_tasksGroups[t->GetId()] == 0)
|
||||
m_event.notify_all();
|
||||
}
|
||||
|
||||
void TransitReadManager::SetStateListener(TransitStateChangedFn const & onStateChangedFn)
|
||||
{
|
||||
m_onStateChangedFn = onStateChangedFn;
|
||||
}
|
||||
|
||||
void TransitReadManager::ChangeState(TransitSchemeState newState)
|
||||
{
|
||||
if (m_state == newState)
|
||||
return;
|
||||
m_state = newState;
|
||||
if (m_onStateChangedFn)
|
||||
m_onStateChangedFn(newState);
|
||||
}
|
||||
|
|
|
@ -80,8 +80,15 @@ private:
|
|||
class TransitReadManager
|
||||
{
|
||||
public:
|
||||
using GetMwmsByRectFn = function<vector<MwmSet::MwmId>(m2::RectD const &)>;
|
||||
enum class TransitSchemeState
|
||||
{
|
||||
Disabled,
|
||||
Enabled,
|
||||
NoData,
|
||||
};
|
||||
|
||||
using GetMwmsByRectFn = function<vector<MwmSet::MwmId>(m2::RectD const &)>;
|
||||
using TransitStateChangedFn = function<void(TransitSchemeState)>;
|
||||
|
||||
TransitReadManager(DataSourceBase & dataSource, TReadFeaturesFn const & readFeaturesFn,
|
||||
GetMwmsByRectFn const & getMwmsByRectFn);
|
||||
|
@ -91,6 +98,7 @@ public:
|
|||
void Stop();
|
||||
|
||||
void SetDrapeEngine(ref_ptr<df::DrapeEngine> engine);
|
||||
void SetStateListener(TransitStateChangedFn const & onStateChangedFn);
|
||||
|
||||
bool GetTransitDisplayInfo(TransitDisplayInfos & transitDisplayInfos);
|
||||
|
||||
|
@ -102,6 +110,7 @@ public:
|
|||
private:
|
||||
void OnTaskCompleted(threads::IRoutine * task);
|
||||
|
||||
void ChangeState(TransitSchemeState newState);
|
||||
void ShrinkCacheToAllowableSize();
|
||||
void ClearCache(MwmSet::MwmId const & mwmId);
|
||||
|
||||
|
@ -118,6 +127,9 @@ private:
|
|||
|
||||
df::DrapeEngineSafePtr m_drapeEngine;
|
||||
|
||||
TransitSchemeState m_state = TransitSchemeState::Disabled;
|
||||
TransitStateChangedFn m_onStateChangedFn;
|
||||
|
||||
struct CacheEntry
|
||||
{
|
||||
CacheEntry(std::chrono::time_point<std::chrono::steady_clock> const & activeTime)
|
||||
|
|
Loading…
Add table
Reference in a new issue