From 29a96cdd6f614018025c957bd5f313ba8caa7607 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Tue, 15 Dec 2015 19:38:59 +0300 Subject: [PATCH] Switching between 2d, 3d and 3d-buildings modes. --- android/jni/com/mapswithme/maps/Framework.cpp | 11 ++++---- android/jni/com/mapswithme/maps/Framework.hpp | 2 +- .../src/com/mapswithme/maps/Framework.java | 2 +- .../maps/search/SearchFragment.java | 5 ++-- drape_frontend/backend_renderer.cpp | 6 +++++ drape_frontend/drape_engine.cpp | 8 ++++-- drape_frontend/drape_engine.hpp | 2 +- drape_frontend/frontend_renderer.cpp | 7 ++++-- drape_frontend/message.hpp | 1 + drape_frontend/message_subclasses.hpp | 22 +++++++++++++--- drape_frontend/read_manager.cpp | 23 ++++++++++++++--- drape_frontend/read_manager.hpp | 3 +++ drape_frontend/rule_drawer.cpp | 6 ++--- drape_frontend/rule_drawer.hpp | 4 +-- drape_frontend/tile_info.cpp | 4 +-- drape_frontend/tile_info.hpp | 6 ++--- .../Search/Console/MWMConsole.mm | 5 ++-- map/framework.cpp | 25 +++++++++++-------- map/framework.hpp | 6 ++--- qt/search_panel.cpp | 5 ++-- 20 files changed, 103 insertions(+), 50 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index e59bfaa7bc..80ff9ea6ca 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -188,9 +188,9 @@ MapStyle Framework::GetMapStyle() const return m_work.GetMapStyle(); } -void Framework::Allow3dMode(bool allow) +void Framework::Allow3dMode(bool allow3d, bool allow3dBuildings) { - m_work.Allow3dMode(allow); + m_work.Allow3dMode(allow3d, allow3dBuildings); } Storage & Framework::Storage() @@ -1319,13 +1319,14 @@ extern "C" } JNIEXPORT void JNICALL - Java_com_mapswithme_maps_Framework_nativeAllow3dMode(JNIEnv * env, jclass thiz, jboolean allow) + Java_com_mapswithme_maps_Framework_nativeAllow3dMode(JNIEnv * env, jclass thiz, jboolean allow, jboolean allowBuildings) { bool const allow3d = static_cast(allow); + bool const allow3dBuildings = static_cast(allowBuildings); - g_framework->PostDrapeTask([allow3d]() + g_framework->PostDrapeTask([allow3d, allow3dBuildings]() { - g_framework->Allow3dMode(allow3d); + g_framework->Allow3dMode(allow3d, allow3dBuildings); }); } } // extern "C" diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 19fb1ac0ab..f067224b04 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -156,7 +156,7 @@ namespace android location::EMyPositionMode GetMyPositionMode() const; void SetMyPositionMode(location::EMyPositionMode mode); - void Allow3dMode(bool allow); + void Allow3dMode(bool allow3d, bool allow3dBuildings); void SetupWidget(gui::EWidget widget, float x, float y, dp::Anchor anchor); void ApplyWidgets(); diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index e967974a72..9269a4e25c 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -178,5 +178,5 @@ public class Framework public native static void nativeDeregisterMaps(); - public native static void nativeAllow3dMode(boolean enable); + public native static void nativeAllow3dMode(boolean allow3d, boolean allow3dBuildings); } diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 37817015fb..69610a759d 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -339,13 +339,14 @@ public class SearchFragment extends BaseMwmFragment private boolean try3dMode(String str) { final boolean is3d = str.equals("?3d"); + final boolean is3dBuildings = str.equals("?b3d"); final boolean is2d = str.equals("?2d"); - if (!is3d && !is2d) + if (!is3d && !is3dBuildings && !is2d) return false; hideSearch(); - Framework.nativeAllow3dMode(is3d); + Framework.nativeAllow3dMode(is3d || is3dBuildings, is3dBuildings); return true; } diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index e3656bd416..82865e6532 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -237,6 +237,12 @@ void BackendRenderer::AcceptMessage(ref_ptr message) ProcessStopRenderingMessage(); break; } + case Message::Allow3dBuildings: + { + ref_ptr msg = message; + m_readManager->Allow3dBuildings(msg->Allow3dBuildings()); + break; + } default: ASSERT(false, ()); break; diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index b32fdace68..f8e693b4f7 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -429,10 +429,14 @@ gui::TWidgetsSizeInfo const & DrapeEngine::GetWidgetSizes() return m_widgetSizes; } -void DrapeEngine::Allow3dMode(bool enable) +void DrapeEngine::Allow3dMode(bool allow3d, bool allow3dBuildings) { + m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, + make_unique_dp(allow3dBuildings), + MessagePriority::Normal); + m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, - make_unique_dp(enable), + make_unique_dp(allow3d), MessagePriority::Normal); } diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 2e636425c4..a1dfa983ad 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -114,7 +114,7 @@ public: void SetWidgetLayout(gui::TWidgetsLayoutInfo && info); gui::TWidgetsSizeInfo const & GetWidgetSizes(); - void Allow3dMode(bool enable); + void Allow3dMode(bool allow3d, bool allow3dBuildings); void EnablePerspective(double rotationAngle, double angleFOV); private: diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 7965f1c71e..8d4f2a1b37 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -514,8 +514,11 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) { ref_ptr const msg = message; #ifdef OMIM_OS_DESKTOP - if (m_enable3dInNavigation == msg->Enable()) + bool const isPerspective = m_userEventStream.GetCurrentScreen().isPerspective(); + if (m_enable3dInNavigation == msg->Allow() && + m_enable3dInNavigation != isPerspective) { + if (m_enable3dInNavigation) AddUserEvent(EnablePerspectiveEvent(M_PI / 4.0, M_PI / 3.0, false /* animated */, true /* immediately start */)); @@ -523,7 +526,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) AddUserEvent(DisablePerspectiveEvent()); } #endif - m_enable3dInNavigation = msg->Enable(); + m_enable3dInNavigation = msg->Allow(); break; } diff --git a/drape_frontend/message.hpp b/drape_frontend/message.hpp index 078b9ae86b..0c5fafe824 100644 --- a/drape_frontend/message.hpp +++ b/drape_frontend/message.hpp @@ -45,6 +45,7 @@ public: InvalidateTextures, Invalidate, Allow3dMode, + Allow3dBuildings, EnablePerspective }; diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index d02d850408..02fb3a396e 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -656,15 +656,29 @@ public: class Allow3dModeMessage : public Message { public: - Allow3dModeMessage(bool enable) - : m_enable(enable) + Allow3dModeMessage(bool allow) + : m_allow(allow) {} Type GetType() const override { return Message::Allow3dMode; } - bool Enable() const { return m_enable; } + bool Allow() const { return m_allow; } private: - bool const m_enable; + bool const m_allow; +}; + +class Allow3dBuildingsMessage : public Message +{ +public: + Allow3dBuildingsMessage(bool allow3dBuildings) + : m_allow3dBuildings(allow3dBuildings) + {} + + Type GetType() const override { return Message::Allow3dBuildings; } + bool Allow3dBuildings() const { return m_allow3dBuildings; } + +private: + bool const m_allow3dBuildings; }; class EnablePerspectiveMessage : public Message diff --git a/drape_frontend/read_manager.cpp b/drape_frontend/read_manager.cpp index 91d038b2cf..e1a76f3cfe 100755 --- a/drape_frontend/read_manager.cpp +++ b/drape_frontend/read_manager.cpp @@ -37,6 +37,8 @@ ReadManager::ReadManager(ref_ptr commutator, MapDataProvider , m_pool(make_unique_dp(ReadCount(), bind(&ReadManager::OnTaskFinished, this, _1))) , m_forceUpdate(true) , m_is3d(false) + , m_is3dBuildings(false) + , m_modeChanged(false) , myPool(64, ReadMWMTaskFactory(m_memIndex, m_model)) , m_counter(0) , m_generationCounter(0) @@ -78,9 +80,12 @@ void ReadManager::UpdateCoverage(ScreenBase const & screen, TTilesCollection con m_forceUpdate = false; m_is3d = screen.isPerspective(); - bool const changeMode = (m_is3d != m_currentViewport.isPerspective()); - if (changeMode || MustDropAllTiles(screen)) + m_modeChanged |= m_is3dBuildings && (m_is3d != m_currentViewport.isPerspective()); + + if (m_modeChanged || MustDropAllTiles(screen)) { + m_modeChanged = false; + IncreaseCounter(static_cast(tiles.size())); m_generationCounter++; @@ -183,7 +188,7 @@ void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey, ref_ptr tileInfo(new TileInfo(make_unique_dp(TileKey(tileKey, m_generationCounter), m_commutator, texMng))); - tileInfo->Set3dMode(m_is3d); + tileInfo->Set3dBuildings(m_is3d && m_is3dBuildings); m_tileInfos.insert(tileInfo); ReadMWMTask * task = myPool.Get(); task->Init(tileInfo); @@ -192,7 +197,7 @@ void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey, ref_ptr const & tileToReread) { - tileToReread->Set3dMode(m_is3d); + tileToReread->Set3dBuildings(m_is3d && m_is3dBuildings); ReadMWMTask * task = myPool.Get(); task->Init(tileToReread); m_pool->PushFront(task); @@ -215,4 +220,14 @@ void ReadManager::IncreaseCounter(int value) m_counter += value; } +void ReadManager::Allow3dBuildings(bool allow3dBuildings) +{ + if (m_is3dBuildings != allow3dBuildings) + { + m_modeChanged = true; + m_forceUpdate = true; + m_is3dBuildings = allow3dBuildings; + } +} + } // namespace df diff --git a/drape_frontend/read_manager.hpp b/drape_frontend/read_manager.hpp index baa7465719..cd6778b0fe 100755 --- a/drape_frontend/read_manager.hpp +++ b/drape_frontend/read_manager.hpp @@ -36,6 +36,7 @@ public: void Stop(); bool CheckTileKey(TileKey const & tileKey) const; + void Allow3dBuildings(bool allow3dBuildings); static size_t ReadCount(); @@ -57,6 +58,8 @@ private: ScreenBase m_currentViewport; bool m_forceUpdate; bool m_is3d; + bool m_is3dBuildings; + bool m_modeChanged; struct LessByTileInfo { diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 1b319d52b2..21ca696732 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -38,12 +38,12 @@ size_t kMinFlushSizes[df::PrioritiesCount] = RuleDrawer::RuleDrawer(TDrawerCallback const & fn, TCheckCancelledCallback const & checkCancelled, TIsCountryLoadedByNameFn const & isLoadedFn, - ref_ptr context, bool is3d) + ref_ptr context, bool is3dBuildings) : m_callback(fn) , m_checkCancelled(checkCancelled) , m_isLoadedFn(isLoadedFn) , m_context(context) - , m_is3d(is3d) + , m_is3dBuidings(is3dBuildings) , m_wasCancelled(false) { ASSERT(m_callback != nullptr, ()); @@ -134,7 +134,7 @@ void RuleDrawer::operator()(FeatureType const & f) if (s.AreaStyleExists()) { - bool const is3dBuilding = m_is3d ? (ftypes::IsBuildingChecker::Instance()(f) && f.GetLayer() >= 0) : false; + bool const is3dBuilding = m_is3dBuidings ? (ftypes::IsBuildingChecker::Instance()(f) && f.GetLayer() >= 0) : false; float areaHeight = 0.0f; if (is3dBuilding) diff --git a/drape_frontend/rule_drawer.hpp b/drape_frontend/rule_drawer.hpp index 01e088d43d..41e35dd0c0 100644 --- a/drape_frontend/rule_drawer.hpp +++ b/drape_frontend/rule_drawer.hpp @@ -29,7 +29,7 @@ public: using TIsCountryLoadedByNameFn = function; RuleDrawer(TDrawerCallback const & drawerFn, TCheckCancelledCallback const & checkCancelled, - TIsCountryLoadedByNameFn const & isLoadedFn, ref_ptr context, bool is3d); + TIsCountryLoadedByNameFn const & isLoadedFn, ref_ptr context, bool is3dBuildings); ~RuleDrawer(); void operator() (FeatureType const & f); @@ -45,7 +45,7 @@ private: m2::RectD m_globalRect; double m_currentScaleGtoP; - bool const m_is3d; + bool const m_is3dBuidings; array m_mapShapes; bool m_wasCancelled; diff --git a/drape_frontend/tile_info.cpp b/drape_frontend/tile_info.cpp index d3854c17b5..46d30f7f23 100644 --- a/drape_frontend/tile_info.cpp +++ b/drape_frontend/tile_info.cpp @@ -16,7 +16,7 @@ namespace df TileInfo::TileInfo(drape_ptr && context) : m_context(move(context)) - , m_is3d(false) + , m_is3dBuidings(false) , m_isCanceled(false) { } @@ -74,7 +74,7 @@ void TileInfo::ReadFeatures(MapDataProvider const & model, MemoryFeatureIndex & RuleDrawer drawer(bind(&TileInfo::InitStylist, this, _1 ,_2), bind(&TileInfo::IsCancelled, this), model.m_isCountryLoadedByNameFn, - make_ref(m_context), m_is3d); + make_ref(m_context), m_is3dBuidings); model.ReadFeatures(bind(ref(drawer), _1), featuresToRead); } } diff --git a/drape_frontend/tile_info.hpp b/drape_frontend/tile_info.hpp index 89334d634b..a0c01cac66 100644 --- a/drape_frontend/tile_info.hpp +++ b/drape_frontend/tile_info.hpp @@ -31,8 +31,8 @@ public: void Cancel(MemoryFeatureIndex & memIndex); bool IsCancelled() const; - void Set3dMode(bool mode) { m_is3d = mode; } - bool Get3dMode() const { return m_is3d; } + void Set3dBuildings(bool buildings3d) { m_is3dBuidings = buildings3d; } + bool Get3dBuildings() const { return m_is3dBuidings; } m2::RectD GetGlobalRect() const; TileKey const & GetTileKey() const { return m_context->GetTileKey(); } @@ -50,7 +50,7 @@ private: private: drape_ptr m_context; TFeaturesInfo m_featureInfo; - bool m_is3d; + bool m_is3dBuidings; atomic m_isCanceled; }; diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/Console/MWMConsole.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/Console/MWMConsole.mm index e84b5acb2a..8d9d335581 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/Console/MWMConsole.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/Console/MWMConsole.mm @@ -36,13 +36,14 @@ { // Hook for shell command on change 3d mode BOOL const is3d = [cmd isEqualToString:@"?3d"]; + BOOL const is3dBuildings = [cmd isEqualToString:@"?b3d"]; BOOL const is2d = [cmd isEqualToString:@"?2d"]; - if (!is3d && !is2d) + if (!is3d && !is3dBuildings && !is2d) return NO; Framework & frm = GetFramework(); - frm.Allow3dMode(is3d); + frm.Allow3dMode(is3d || is3dBuildings, is3dBuildings); return YES; } diff --git a/map/framework.cpp b/map/framework.cpp index 839abaf914..f3f732badb 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -94,6 +94,7 @@ namespace char const kRouterTypeKey[] = "router"; char const kMapStyleKey[] = "MapStyleKeyV1"; char const kAllow3dKey[] = "Allow3d"; + char const kAllow3dBuildingsKey[] = "Buildings3d"; double const kRotationAngle = math::pi4; double const kAngleFOV = math::pi / 3.0; @@ -1282,8 +1283,10 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, ActivateUserMark(mark, true); } - bool const allow3d = Load3dMode(); - Allow3dMode(allow3d); + bool allow3d = true; + bool allow3dBuildings = true; + Load3dMode(allow3d, allow3dBuildings); + Allow3dMode(allow3d, allow3dBuildings); // In case of the engine reinitialization recover route. if (m_routingSession.IsActive()) @@ -2073,20 +2076,20 @@ void Framework::SetRouteFinishPoint(m2::PointD const & pt, bool isValid) m_drapeEngine->SetRoutePoint(pt, false /* isStart */, isValid); } -void Framework::Allow3dMode(bool allow) +void Framework::Allow3dMode(bool allow3d, bool allow3dBuildings) { - Save3dMode(allow); - CallDrapeFunction(bind(&df::DrapeEngine::Allow3dMode, _1, allow)); + Save3dMode(allow3d, allow3dBuildings); + CallDrapeFunction(bind(&df::DrapeEngine::Allow3dMode, _1, allow3d, allow3dBuildings)); } -void Framework::Save3dMode(bool allow) +void Framework::Save3dMode(bool allow3d, bool allow3dBuildings) { - Settings::Set(kAllow3dKey, allow); + Settings::Set(kAllow3dKey, allow3d); + Settings::Set(kAllow3dBuildingsKey, allow3dBuildings); } -bool Framework::Load3dMode() +void Framework::Load3dMode(bool &allow3d, bool &allow3dBuildings) { - bool allow = true; - Settings::Get(kAllow3dKey, allow); - return allow; + Settings::Get(kAllow3dKey, allow3d); + Settings::Get(kAllow3dBuildingsKey, allow3dBuildings); } diff --git a/map/framework.hpp b/map/framework.hpp index 0dc435ff01..63cdb18328 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -544,9 +544,9 @@ public: void SetRouteStartPoint(m2::PointD const & pt, bool isValid); void SetRouteFinishPoint(m2::PointD const & pt, bool isValid); - void Allow3dMode(bool allow); - void Save3dMode(bool allow); - bool Load3dMode(); + void Allow3dMode(bool allow3d, bool allow3dBuildings); + void Save3dMode(bool allow3d, bool allow3dBuildings); + void Load3dMode(bool & allow3d, bool & allow3dBuildings); private: void SetRouterImpl(routing::RouterType type); diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index c7ce808fda..9851e54496 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -195,12 +195,13 @@ bool SearchPanel::TryChangeRouterCmd(QString const & str) bool SearchPanel::Try3dModeCmd(QString const & str) { bool const is3dModeOn = (str == "?3d"); + bool const is3dBuildingsOn = (str == "?b3d"); bool const is3dModeOff = (str == "?2d"); - if (!is3dModeOn && !is3dModeOff) + if (!is3dModeOn && !is3dBuildingsOn && !is3dModeOff) return false; - m_pDrawWidget->GetFramework().Allow3dMode(is3dModeOn); + m_pDrawWidget->GetFramework().Allow3dMode(is3dModeOn || is3dBuildingsOn, is3dBuildingsOn); return true; }