mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:30:05 +00:00 
			
		
		
		
	Update placefile text data outside of render loop, polygon cleanup
This commit is contained in:
		
							parent
							
								
									8f2b87790a
								
							
						
					
					
						commit
						b159540215
					
				
					 6 changed files with 60 additions and 36 deletions
				
			
		|  | @ -233,11 +233,15 @@ void PlacefilePolygons::Deinitialize() | |||
| 
 | ||||
|    gl.glDeleteVertexArrays(1, &p->vao_); | ||||
|    gl.glDeleteBuffers(2, p->vbo_.data()); | ||||
| 
 | ||||
|    // Clear the current buffers
 | ||||
|    p->currentBuffer_.clear(); | ||||
|    p->currentThresholdBuffer_.clear(); | ||||
| } | ||||
| 
 | ||||
| void PlacefilePolygons::StartPolygons() | ||||
| { | ||||
|    // Clear the new buffer
 | ||||
|    // Clear the new buffers
 | ||||
|    p->newBuffer_.clear(); | ||||
|    p->newThresholdBuffer_.clear(); | ||||
| } | ||||
|  | @ -259,6 +263,10 @@ void PlacefilePolygons::FinishPolygons() | |||
|    p->currentBuffer_.swap(p->newBuffer_); | ||||
|    p->currentThresholdBuffer_.swap(p->newThresholdBuffer_); | ||||
| 
 | ||||
|    // Clear the new buffers
 | ||||
|    p->newBuffer_.clear(); | ||||
|    p->newThresholdBuffer_.clear(); | ||||
| 
 | ||||
|    // Mark the draw item dirty
 | ||||
|    p->dirty_ = true; | ||||
| } | ||||
|  |  | |||
|  | @ -45,7 +45,6 @@ public: | |||
| 
 | ||||
|    std::string placefileName_; | ||||
| 
 | ||||
|    bool dirty_ {false}; | ||||
|    bool thresholded_ {false}; | ||||
| 
 | ||||
|    std::uint32_t textId_ {}; | ||||
|  | @ -59,9 +58,9 @@ public: | |||
| 
 | ||||
|    units::length::nautical_miles<double> mapDistance_ {}; | ||||
| 
 | ||||
|    std::mutex listMutex_ {}; | ||||
|    std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> textList_ {}; | ||||
| 
 | ||||
|    void Update(); | ||||
|    std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> newList_ {}; | ||||
| }; | ||||
| 
 | ||||
| PlacefileText::PlacefileText(std::shared_ptr<GlContext> context, | ||||
|  | @ -84,18 +83,15 @@ void PlacefileText::set_thresholded(bool thresholded) | |||
|    p->thresholded_ = thresholded; | ||||
| } | ||||
| 
 | ||||
| void PlacefileText::Initialize() | ||||
| { | ||||
|    p->dirty_ = true; | ||||
| } | ||||
| void PlacefileText::Initialize() {} | ||||
| 
 | ||||
| void PlacefileText::Render( | ||||
|    const QMapLibreGL::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    std::unique_lock lock {p->listMutex_}; | ||||
| 
 | ||||
|    if (!p->textList_.empty()) | ||||
|    { | ||||
|       p->Update(); | ||||
| 
 | ||||
|       // Reset text ID per frame
 | ||||
|       p->textId_ = 0; | ||||
| 
 | ||||
|  | @ -209,7 +205,14 @@ void PlacefileText::Impl::RenderText( | |||
| 
 | ||||
| void PlacefileText::Deinitialize() | ||||
| { | ||||
|    Reset(); | ||||
|    // Clear the text list
 | ||||
|    p->textList_.clear(); | ||||
| } | ||||
| 
 | ||||
| void PlacefileText::StartText() | ||||
| { | ||||
|    // Clear the new list
 | ||||
|    p->newList_.clear(); | ||||
| } | ||||
| 
 | ||||
| void PlacefileText::AddText( | ||||
|  | @ -217,21 +220,19 @@ void PlacefileText::AddText( | |||
| { | ||||
|    if (di != nullptr) | ||||
|    { | ||||
|       p->textList_.emplace_back(di); | ||||
|       p->dirty_ = true; | ||||
|       p->newList_.emplace_back(di); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void PlacefileText::Reset() | ||||
| void PlacefileText::FinishText() | ||||
| { | ||||
|    // Clear the icon list, and mark the draw item dirty
 | ||||
|    p->textList_.clear(); | ||||
|    p->dirty_ = true; | ||||
| } | ||||
|    std::unique_lock lock {p->listMutex_}; | ||||
| 
 | ||||
| void PlacefileText::Impl::Update() | ||||
| { | ||||
|    dirty_ = false; | ||||
|    // Swap text lists
 | ||||
|    p->textList_.swap(p->newList_); | ||||
| 
 | ||||
|    // Clear the new list
 | ||||
|    p->newList_.clear(); | ||||
| } | ||||
| 
 | ||||
| } // namespace draw
 | ||||
|  |  | |||
|  | @ -33,6 +33,11 @@ public: | |||
|    void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override; | ||||
|    void Deinitialize() override; | ||||
| 
 | ||||
|    /**
 | ||||
|     * Resets and prepares the draw item for adding a new set of text. | ||||
|     */ | ||||
|    void StartText(); | ||||
| 
 | ||||
|    /**
 | ||||
|     * Adds placefile text to the internal draw list. | ||||
|     * | ||||
|  | @ -41,9 +46,9 @@ public: | |||
|    void AddText(const std::shared_ptr<gr::Placefile::TextDrawItem>& di); | ||||
| 
 | ||||
|    /**
 | ||||
|     * Resets the list of text in preparation for rendering a new frame. | ||||
|     * Finalizes the draw item after adding new text. | ||||
|     */ | ||||
|    void Reset(); | ||||
|    void FinishText(); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|  |  | |||
|  | @ -815,6 +815,12 @@ void MapWidgetImpl::UpdatePlacefileLayers() | |||
|          placefileLayers_.push_back(placefileLayer); | ||||
|          AddLayer( | ||||
|             GetPlacefileLayerName(placefileName), placefileLayer, "colorTable"); | ||||
| 
 | ||||
|          // When the layer updates, trigger a map widget update
 | ||||
|          connect(placefileLayer.get(), | ||||
|                  &PlacefileLayer::DataReloaded, | ||||
|                  widget_, | ||||
|                  [this]() { widget_->update(); }); | ||||
|       } | ||||
|    } | ||||
| } | ||||
|  |  | |||
|  | @ -59,6 +59,8 @@ PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context, | |||
|    AddDrawItem(p->placefileIcons_); | ||||
|    AddDrawItem(p->placefilePolygons_); | ||||
|    AddDrawItem(p->placefileText_); | ||||
| 
 | ||||
|    ReloadData(); | ||||
| } | ||||
| 
 | ||||
| PlacefileLayer::~PlacefileLayer() = default; | ||||
|  | @ -128,19 +130,10 @@ void PlacefileLayer::Render( | |||
|          p->placefileIcons_->SetIconFiles(placefile->icon_files(), | ||||
|                                           placefile->name()); | ||||
| 
 | ||||
|          // Reset Placefile Text
 | ||||
|          p->placefileText_->Reset(); | ||||
| 
 | ||||
|          for (auto& drawItem : placefile->GetDrawItems()) | ||||
|          { | ||||
|             switch (drawItem->itemType_) | ||||
|             { | ||||
|             case gr::Placefile::ItemType::Text: | ||||
|                p->placefileText_->AddText( | ||||
|                   std::static_pointer_cast<gr::Placefile::TextDrawItem>( | ||||
|                      drawItem)); | ||||
|                break; | ||||
| 
 | ||||
|             case gr::Placefile::ItemType::Icon: | ||||
|                p->placefileIcons_->AddIcon( | ||||
|                   std::static_pointer_cast<gr::Placefile::IconDrawItem>( | ||||
|  | @ -168,7 +161,7 @@ void PlacefileLayer::Deinitialize() | |||
| 
 | ||||
| void PlacefileLayer::ReloadData() | ||||
| { | ||||
|    // TODO: No longer needed after moving Icon and Text Render items here
 | ||||
|    // TODO: No longer needed after moving Icon Render items here
 | ||||
|    p->dirty_ = true; | ||||
| 
 | ||||
|    boost::asio::post( | ||||
|  | @ -188,15 +181,18 @@ void PlacefileLayer::ReloadData() | |||
|             return; | ||||
|          } | ||||
| 
 | ||||
|          // Reset Placefile Polygons
 | ||||
|          // Start draw items
 | ||||
|          p->placefilePolygons_->StartPolygons(); | ||||
|          p->placefileText_->StartText(); | ||||
| 
 | ||||
|          for (auto& drawItem : placefile->GetDrawItems()) | ||||
|          { | ||||
|             switch (drawItem->itemType_) | ||||
|             { | ||||
|             case gr::Placefile::ItemType::Text: | ||||
|                // TODO
 | ||||
|                p->placefileText_->AddText( | ||||
|                   std::static_pointer_cast<gr::Placefile::TextDrawItem>( | ||||
|                      drawItem)); | ||||
|                break; | ||||
| 
 | ||||
|             case gr::Placefile::ItemType::Icon: | ||||
|  | @ -214,8 +210,11 @@ void PlacefileLayer::ReloadData() | |||
|             } | ||||
|          } | ||||
| 
 | ||||
|          // Finish Placefile Polygons
 | ||||
|          // Finish draw items
 | ||||
|          p->placefilePolygons_->FinishPolygons(); | ||||
|          p->placefileText_->FinishText(); | ||||
| 
 | ||||
|          Q_EMIT DataReloaded(); | ||||
|       }); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,6 +13,8 @@ namespace map | |||
| 
 | ||||
| class PlacefileLayer : public DrawLayer | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit PlacefileLayer(std::shared_ptr<MapContext> context, | ||||
|                            const std::string&          placefileName); | ||||
|  | @ -28,6 +30,9 @@ public: | |||
| 
 | ||||
|    void ReloadData(); | ||||
| 
 | ||||
| signals: | ||||
|    void DataReloaded(); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|    std::unique_ptr<Impl> p; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat