mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 17:40: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.glDeleteVertexArrays(1, &p->vao_);
|
||||||
gl.glDeleteBuffers(2, p->vbo_.data());
|
gl.glDeleteBuffers(2, p->vbo_.data());
|
||||||
|
|
||||||
|
// Clear the current buffers
|
||||||
|
p->currentBuffer_.clear();
|
||||||
|
p->currentThresholdBuffer_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacefilePolygons::StartPolygons()
|
void PlacefilePolygons::StartPolygons()
|
||||||
{
|
{
|
||||||
// Clear the new buffer
|
// Clear the new buffers
|
||||||
p->newBuffer_.clear();
|
p->newBuffer_.clear();
|
||||||
p->newThresholdBuffer_.clear();
|
p->newThresholdBuffer_.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -259,6 +263,10 @@ void PlacefilePolygons::FinishPolygons()
|
||||||
p->currentBuffer_.swap(p->newBuffer_);
|
p->currentBuffer_.swap(p->newBuffer_);
|
||||||
p->currentThresholdBuffer_.swap(p->newThresholdBuffer_);
|
p->currentThresholdBuffer_.swap(p->newThresholdBuffer_);
|
||||||
|
|
||||||
|
// Clear the new buffers
|
||||||
|
p->newBuffer_.clear();
|
||||||
|
p->newThresholdBuffer_.clear();
|
||||||
|
|
||||||
// Mark the draw item dirty
|
// Mark the draw item dirty
|
||||||
p->dirty_ = true;
|
p->dirty_ = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ public:
|
||||||
|
|
||||||
std::string placefileName_;
|
std::string placefileName_;
|
||||||
|
|
||||||
bool dirty_ {false};
|
|
||||||
bool thresholded_ {false};
|
bool thresholded_ {false};
|
||||||
|
|
||||||
std::uint32_t textId_ {};
|
std::uint32_t textId_ {};
|
||||||
|
|
@ -59,9 +58,9 @@ public:
|
||||||
|
|
||||||
units::length::nautical_miles<double> mapDistance_ {};
|
units::length::nautical_miles<double> mapDistance_ {};
|
||||||
|
|
||||||
|
std::mutex listMutex_ {};
|
||||||
std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> textList_ {};
|
std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> textList_ {};
|
||||||
|
std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> newList_ {};
|
||||||
void Update();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PlacefileText::PlacefileText(std::shared_ptr<GlContext> context,
|
PlacefileText::PlacefileText(std::shared_ptr<GlContext> context,
|
||||||
|
|
@ -84,18 +83,15 @@ void PlacefileText::set_thresholded(bool thresholded)
|
||||||
p->thresholded_ = thresholded;
|
p->thresholded_ = thresholded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacefileText::Initialize()
|
void PlacefileText::Initialize() {}
|
||||||
{
|
|
||||||
p->dirty_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlacefileText::Render(
|
void PlacefileText::Render(
|
||||||
const QMapLibreGL::CustomLayerRenderParameters& params)
|
const QMapLibreGL::CustomLayerRenderParameters& params)
|
||||||
{
|
{
|
||||||
|
std::unique_lock lock {p->listMutex_};
|
||||||
|
|
||||||
if (!p->textList_.empty())
|
if (!p->textList_.empty())
|
||||||
{
|
{
|
||||||
p->Update();
|
|
||||||
|
|
||||||
// Reset text ID per frame
|
// Reset text ID per frame
|
||||||
p->textId_ = 0;
|
p->textId_ = 0;
|
||||||
|
|
||||||
|
|
@ -209,7 +205,14 @@ void PlacefileText::Impl::RenderText(
|
||||||
|
|
||||||
void PlacefileText::Deinitialize()
|
void PlacefileText::Deinitialize()
|
||||||
{
|
{
|
||||||
Reset();
|
// Clear the text list
|
||||||
|
p->textList_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlacefileText::StartText()
|
||||||
|
{
|
||||||
|
// Clear the new list
|
||||||
|
p->newList_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacefileText::AddText(
|
void PlacefileText::AddText(
|
||||||
|
|
@ -217,21 +220,19 @@ void PlacefileText::AddText(
|
||||||
{
|
{
|
||||||
if (di != nullptr)
|
if (di != nullptr)
|
||||||
{
|
{
|
||||||
p->textList_.emplace_back(di);
|
p->newList_.emplace_back(di);
|
||||||
p->dirty_ = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacefileText::Reset()
|
void PlacefileText::FinishText()
|
||||||
{
|
{
|
||||||
// Clear the icon list, and mark the draw item dirty
|
std::unique_lock lock {p->listMutex_};
|
||||||
p->textList_.clear();
|
|
||||||
p->dirty_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlacefileText::Impl::Update()
|
// Swap text lists
|
||||||
{
|
p->textList_.swap(p->newList_);
|
||||||
dirty_ = false;
|
|
||||||
|
// Clear the new list
|
||||||
|
p->newList_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace draw
|
} // namespace draw
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ public:
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
||||||
void Deinitialize() 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.
|
* Adds placefile text to the internal draw list.
|
||||||
*
|
*
|
||||||
|
|
@ -41,9 +46,9 @@ public:
|
||||||
void AddText(const std::shared_ptr<gr::Placefile::TextDrawItem>& di);
|
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:
|
private:
|
||||||
class Impl;
|
class Impl;
|
||||||
|
|
|
||||||
|
|
@ -815,6 +815,12 @@ void MapWidgetImpl::UpdatePlacefileLayers()
|
||||||
placefileLayers_.push_back(placefileLayer);
|
placefileLayers_.push_back(placefileLayer);
|
||||||
AddLayer(
|
AddLayer(
|
||||||
GetPlacefileLayerName(placefileName), placefileLayer, "colorTable");
|
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->placefileIcons_);
|
||||||
AddDrawItem(p->placefilePolygons_);
|
AddDrawItem(p->placefilePolygons_);
|
||||||
AddDrawItem(p->placefileText_);
|
AddDrawItem(p->placefileText_);
|
||||||
|
|
||||||
|
ReloadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlacefileLayer::~PlacefileLayer() = default;
|
PlacefileLayer::~PlacefileLayer() = default;
|
||||||
|
|
@ -128,19 +130,10 @@ void PlacefileLayer::Render(
|
||||||
p->placefileIcons_->SetIconFiles(placefile->icon_files(),
|
p->placefileIcons_->SetIconFiles(placefile->icon_files(),
|
||||||
placefile->name());
|
placefile->name());
|
||||||
|
|
||||||
// Reset Placefile Text
|
|
||||||
p->placefileText_->Reset();
|
|
||||||
|
|
||||||
for (auto& drawItem : placefile->GetDrawItems())
|
for (auto& drawItem : placefile->GetDrawItems())
|
||||||
{
|
{
|
||||||
switch (drawItem->itemType_)
|
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:
|
case gr::Placefile::ItemType::Icon:
|
||||||
p->placefileIcons_->AddIcon(
|
p->placefileIcons_->AddIcon(
|
||||||
std::static_pointer_cast<gr::Placefile::IconDrawItem>(
|
std::static_pointer_cast<gr::Placefile::IconDrawItem>(
|
||||||
|
|
@ -168,7 +161,7 @@ void PlacefileLayer::Deinitialize()
|
||||||
|
|
||||||
void PlacefileLayer::ReloadData()
|
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;
|
p->dirty_ = true;
|
||||||
|
|
||||||
boost::asio::post(
|
boost::asio::post(
|
||||||
|
|
@ -188,15 +181,18 @@ void PlacefileLayer::ReloadData()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset Placefile Polygons
|
// Start draw items
|
||||||
p->placefilePolygons_->StartPolygons();
|
p->placefilePolygons_->StartPolygons();
|
||||||
|
p->placefileText_->StartText();
|
||||||
|
|
||||||
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:
|
||||||
// TODO
|
p->placefileText_->AddText(
|
||||||
|
std::static_pointer_cast<gr::Placefile::TextDrawItem>(
|
||||||
|
drawItem));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gr::Placefile::ItemType::Icon:
|
case gr::Placefile::ItemType::Icon:
|
||||||
|
|
@ -214,8 +210,11 @@ void PlacefileLayer::ReloadData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish Placefile Polygons
|
// Finish draw items
|
||||||
p->placefilePolygons_->FinishPolygons();
|
p->placefilePolygons_->FinishPolygons();
|
||||||
|
p->placefileText_->FinishText();
|
||||||
|
|
||||||
|
Q_EMIT DataReloaded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ namespace map
|
||||||
|
|
||||||
class PlacefileLayer : public DrawLayer
|
class PlacefileLayer : public DrawLayer
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PlacefileLayer(std::shared_ptr<MapContext> context,
|
explicit PlacefileLayer(std::shared_ptr<MapContext> context,
|
||||||
const std::string& placefileName);
|
const std::string& placefileName);
|
||||||
|
|
@ -28,6 +30,9 @@ public:
|
||||||
|
|
||||||
void ReloadData();
|
void ReloadData();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void DataReloaded();
|
||||||
|
|
||||||
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