Own grid workers and thin Apple platform bridge
This commit is contained in:
@@ -7,9 +7,89 @@
|
||||
#include "image.h"
|
||||
#include "node_panel_grid.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <stop_token>
|
||||
#include <thread>
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
class LegacyGridWorker final {
|
||||
public:
|
||||
LegacyGridWorker()
|
||||
: worker_([this](std::stop_token stop_token) {
|
||||
run(stop_token);
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
~LegacyGridWorker()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
void post(std::function<void()> task)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (stopping_)
|
||||
return;
|
||||
tasks_.push_back(std::move(task));
|
||||
}
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
private:
|
||||
void shutdown()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
stopping_ = true;
|
||||
}
|
||||
cv_.notify_all();
|
||||
}
|
||||
|
||||
void run(std::stop_token stop_token)
|
||||
{
|
||||
for (;;) {
|
||||
std::function<void()> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
cv_.wait(lock, [&] {
|
||||
return stopping_ || stop_token.stop_requested() || !tasks_.empty();
|
||||
});
|
||||
if ((stopping_ || stop_token.stop_requested()) && tasks_.empty())
|
||||
break;
|
||||
task = std::move(tasks_.front());
|
||||
tasks_.pop_front();
|
||||
}
|
||||
|
||||
if (task) {
|
||||
try {
|
||||
task();
|
||||
} catch (...) {
|
||||
LOG("grid worker task failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
std::deque<std::function<void()>> tasks_;
|
||||
bool stopping_ = false;
|
||||
std::jthread worker_;
|
||||
};
|
||||
|
||||
LegacyGridWorker& grid_worker()
|
||||
{
|
||||
static LegacyGridWorker worker;
|
||||
return worker;
|
||||
}
|
||||
|
||||
class LegacyGridUiServices final : public pp::app::GridUiServices {
|
||||
public:
|
||||
explicit LegacyGridUiServices(NodePanelGrid& panel) noexcept
|
||||
@@ -66,13 +146,17 @@ public:
|
||||
if (!renders_lightmap)
|
||||
return;
|
||||
|
||||
auto* panel = &panel_;
|
||||
std::thread([panel] {
|
||||
auto panel = std::static_pointer_cast<NodePanelGrid>(panel_.shared_from_this());
|
||||
grid_worker().post([panel] {
|
||||
BT_SetTerminate();
|
||||
panel->bake_uvs();
|
||||
panel->m_hm_shading->set_index(3);
|
||||
panel->m_shade_mode = NodePanelGrid::ShadeMode::Textured;
|
||||
}).detach();
|
||||
if (App::I) {
|
||||
App::I->ui_task([panel] {
|
||||
panel->m_hm_shading->set_index(3);
|
||||
panel->m_shade_mode = NodePanelGrid::ShadeMode::Textured;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void commit_heightmap(bool updates_ground_opacity) override
|
||||
|
||||
Reference in New Issue
Block a user