mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 13:00:05 +00:00 
			
		
		
		
	Update placefile polygon data outside of render loop
This commit is contained in:
		
							parent
							
								
									a4027ba120
								
							
						
					
					
						commit
						8f2b87790a
					
				
					 3 changed files with 76 additions and 74 deletions
				
			
		|  | @ -91,9 +91,6 @@ public: | ||||||
|    bool dirty_ {false}; |    bool dirty_ {false}; | ||||||
|    bool thresholded_ {false}; |    bool thresholded_ {false}; | ||||||
| 
 | 
 | ||||||
|    std::vector<std::shared_ptr<const gr::Placefile::PolygonDrawItem>> |  | ||||||
|       polygonList_ {}; |  | ||||||
| 
 |  | ||||||
|    boost::container::stable_vector<TessVertexArray> tessCombineBuffer_ {}; |    boost::container::stable_vector<TessVertexArray> tessCombineBuffer_ {}; | ||||||
| 
 | 
 | ||||||
|    std::mutex           bufferMutex_ {}; |    std::mutex           bufferMutex_ {}; | ||||||
|  | @ -243,9 +240,6 @@ void PlacefilePolygons::StartPolygons() | ||||||
|    // Clear the new buffer
 |    // Clear the new buffer
 | ||||||
|    p->newBuffer_.clear(); |    p->newBuffer_.clear(); | ||||||
|    p->newThresholdBuffer_.clear(); |    p->newThresholdBuffer_.clear(); | ||||||
| 
 |  | ||||||
|    // Clear the polygon list
 |  | ||||||
|    p->polygonList_.clear(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PlacefilePolygons::AddPolygon( | void PlacefilePolygons::AddPolygon( | ||||||
|  | @ -253,7 +247,6 @@ void PlacefilePolygons::AddPolygon( | ||||||
| { | { | ||||||
|    if (di != nullptr) |    if (di != nullptr) | ||||||
|    { |    { | ||||||
|       p->polygonList_.emplace_back(di); |  | ||||||
|       p->Tessellate(di); |       p->Tessellate(di); | ||||||
|    } |    } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,6 +5,8 @@ | ||||||
| #include <scwx/qt/manager/placefile_manager.hpp> | #include <scwx/qt/manager/placefile_manager.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/asio/post.hpp> | ||||||
|  | #include <boost/asio/thread_pool.hpp> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -36,14 +38,12 @@ public: | ||||||
| 
 | 
 | ||||||
|    void ConnectSignals(); |    void ConnectSignals(); | ||||||
| 
 | 
 | ||||||
|    void AddIcon(const std::shared_ptr<gr::Placefile::IconDrawItem>& di); |    boost::asio::thread_pool threadPool_ {1}; | ||||||
|    void AddPolygon(const std::shared_ptr<gr::Placefile::PolygonDrawItem>& di); |  | ||||||
|    void AddText(const std::shared_ptr<gr::Placefile::TextDrawItem>& di); |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
|    PlacefileLayer* self_; |    PlacefileLayer* self_; | ||||||
| 
 | 
 | ||||||
|    std::string placefileName_; |    std::string placefileName_; | ||||||
|  |    std::mutex  dataMutex_ {}; | ||||||
|    bool        dirty_ {true}; |    bool        dirty_ {true}; | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<gl::draw::PlacefileIcons>    placefileIcons_; |    std::shared_ptr<gl::draw::PlacefileIcons>    placefileIcons_; | ||||||
|  | @ -74,7 +74,7 @@ void PlacefileLayer::Impl::ConnectSignals() | ||||||
|                     { |                     { | ||||||
|                        if (name == placefileName_) |                        if (name == placefileName_) | ||||||
|                        { |                        { | ||||||
|                           dirty_ = true; |                           self_->ReloadData(); | ||||||
|                        } |                        } | ||||||
|                     }); |                     }); | ||||||
| } | } | ||||||
|  | @ -99,39 +99,6 @@ void PlacefileLayer::Initialize() | ||||||
|    DrawLayer::Initialize(); |    DrawLayer::Initialize(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PlacefileLayer::Impl::AddIcon( |  | ||||||
|    const std::shared_ptr<gr::Placefile::IconDrawItem>& di) |  | ||||||
| { |  | ||||||
|    if (!dirty_) |  | ||||||
|    { |  | ||||||
|       return; |  | ||||||
|    } |  | ||||||
| 
 |  | ||||||
|    placefileIcons_->AddIcon(di); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void PlacefileLayer::Impl::AddPolygon( |  | ||||||
|    const std::shared_ptr<gr::Placefile::PolygonDrawItem>& di) |  | ||||||
| { |  | ||||||
|    if (!dirty_) |  | ||||||
|    { |  | ||||||
|       return; |  | ||||||
|    }; |  | ||||||
| 
 |  | ||||||
|    placefilePolygons_->AddPolygon(di); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void PlacefileLayer::Impl::AddText( |  | ||||||
|    const std::shared_ptr<gr::Placefile::TextDrawItem>& di) |  | ||||||
| { |  | ||||||
|    if (!dirty_) |  | ||||||
|    { |  | ||||||
|       return; |  | ||||||
|    }; |  | ||||||
| 
 |  | ||||||
|    placefileText_->AddText(di); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void PlacefileLayer::Render( | void PlacefileLayer::Render( | ||||||
|    const QMapLibreGL::CustomLayerRenderParameters& params) |    const QMapLibreGL::CustomLayerRenderParameters& params) | ||||||
| { | { | ||||||
|  | @ -161,30 +128,22 @@ void PlacefileLayer::Render( | ||||||
|          p->placefileIcons_->SetIconFiles(placefile->icon_files(), |          p->placefileIcons_->SetIconFiles(placefile->icon_files(), | ||||||
|                                           placefile->name()); |                                           placefile->name()); | ||||||
| 
 | 
 | ||||||
|          // Reset Placefile Polygons
 |  | ||||||
|          p->placefilePolygons_->StartPolygons(); |  | ||||||
| 
 |  | ||||||
|          // Reset Placefile Text
 |          // Reset Placefile Text
 | ||||||
|          p->placefileText_->Reset(); |          p->placefileText_->Reset(); | ||||||
|       } |  | ||||||
| 
 | 
 | ||||||
|          for (auto& drawItem : placefile->GetDrawItems()) |          for (auto& drawItem : placefile->GetDrawItems()) | ||||||
|          { |          { | ||||||
|             switch (drawItem->itemType_) |             switch (drawItem->itemType_) | ||||||
|             { |             { | ||||||
|             case gr::Placefile::ItemType::Text: |             case gr::Placefile::ItemType::Text: | ||||||
|             p->AddText( |                p->placefileText_->AddText( | ||||||
|                std::static_pointer_cast<gr::Placefile::TextDrawItem>(drawItem)); |                   std::static_pointer_cast<gr::Placefile::TextDrawItem>( | ||||||
|  |                      drawItem)); | ||||||
|                break; |                break; | ||||||
| 
 | 
 | ||||||
|             case gr::Placefile::ItemType::Icon: |             case gr::Placefile::ItemType::Icon: | ||||||
|             p->AddIcon( |                p->placefileIcons_->AddIcon( | ||||||
|                std::static_pointer_cast<gr::Placefile::IconDrawItem>(drawItem)); |                   std::static_pointer_cast<gr::Placefile::IconDrawItem>( | ||||||
|             break; |  | ||||||
| 
 |  | ||||||
|          case gr::Placefile::ItemType::Polygon: |  | ||||||
|             p->AddPolygon( |  | ||||||
|                std::static_pointer_cast<gr::Placefile::PolygonDrawItem>( |  | ||||||
|                      drawItem)); |                      drawItem)); | ||||||
|                break; |                break; | ||||||
| 
 | 
 | ||||||
|  | @ -192,11 +151,6 @@ void PlacefileLayer::Render( | ||||||
|                break; |                break; | ||||||
|             } |             } | ||||||
|          } |          } | ||||||
| 
 |  | ||||||
|       if (p->dirty_) |  | ||||||
|       { |  | ||||||
|          // Finish Placefile Polygons
 |  | ||||||
|          p->placefilePolygons_->FinishPolygons(); |  | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  | @ -212,6 +166,59 @@ void PlacefileLayer::Deinitialize() | ||||||
|    DrawLayer::Deinitialize(); |    DrawLayer::Deinitialize(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void PlacefileLayer::ReloadData() | ||||||
|  | { | ||||||
|  |    // TODO: No longer needed after moving Icon and Text Render items here
 | ||||||
|  |    p->dirty_ = true; | ||||||
|  | 
 | ||||||
|  |    boost::asio::post( | ||||||
|  |       p->threadPool_, | ||||||
|  |       [this]() | ||||||
|  |       { | ||||||
|  |          logger_->debug("ReloadData: {}", p->placefileName_); | ||||||
|  | 
 | ||||||
|  |          std::unique_lock lock {p->dataMutex_}; | ||||||
|  | 
 | ||||||
|  |          std::shared_ptr<manager::PlacefileManager> placefileManager = | ||||||
|  |             manager::PlacefileManager::Instance(); | ||||||
|  | 
 | ||||||
|  |          auto placefile = placefileManager->placefile(p->placefileName_); | ||||||
|  |          if (placefile == nullptr) | ||||||
|  |          { | ||||||
|  |             return; | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          // Reset Placefile Polygons
 | ||||||
|  |          p->placefilePolygons_->StartPolygons(); | ||||||
|  | 
 | ||||||
|  |          for (auto& drawItem : placefile->GetDrawItems()) | ||||||
|  |          { | ||||||
|  |             switch (drawItem->itemType_) | ||||||
|  |             { | ||||||
|  |             case gr::Placefile::ItemType::Text: | ||||||
|  |                // TODO
 | ||||||
|  |                break; | ||||||
|  | 
 | ||||||
|  |             case gr::Placefile::ItemType::Icon: | ||||||
|  |                // TODO
 | ||||||
|  |                break; | ||||||
|  | 
 | ||||||
|  |             case gr::Placefile::ItemType::Polygon: | ||||||
|  |                p->placefilePolygons_->AddPolygon( | ||||||
|  |                   std::static_pointer_cast<gr::Placefile::PolygonDrawItem>( | ||||||
|  |                      drawItem)); | ||||||
|  |                break; | ||||||
|  | 
 | ||||||
|  |             default: | ||||||
|  |                break; | ||||||
|  |             } | ||||||
|  |          } | ||||||
|  | 
 | ||||||
|  |          // Finish Placefile Polygons
 | ||||||
|  |          p->placefilePolygons_->FinishPolygons(); | ||||||
|  |       }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace map
 | } // namespace map
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -26,6 +26,8 @@ public: | ||||||
|    void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final; |    void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final; | ||||||
|    void Deinitialize() override final; |    void Deinitialize() override final; | ||||||
| 
 | 
 | ||||||
|  |    void ReloadData(); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::unique_ptr<Impl> p; |    std::unique_ptr<Impl> p; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat