fix checkbox icon update, add unique check on async tasks

This commit is contained in:
2019-07-14 21:56:43 +02:00
parent fc7301a9a8
commit 6a0b654228
5 changed files with 65 additions and 65 deletions

View File

@@ -27,14 +27,14 @@ void destroy_window();
App* App::I = nullptr; // singleton
std::deque<std::packaged_task<void()>> App::render_tasklist;
std::deque<AppTask> App::render_tasklist;
std::mutex App::render_task_mutex;
std::condition_variable App::render_cv;
std::thread App::render_thread;
std::thread::id App::render_thread_id;
bool App::render_running = false;
std::deque<std::packaged_task<void()>> App::ui_tasklist;
std::deque<AppTask> App::ui_tasklist;
std::mutex App::ui_task_mutex;
std::condition_variable App::ui_cv;
std::thread App::ui_thread;
@@ -425,28 +425,6 @@ void App::async_start()
#endif
}
void App::async_update()
{
#if __IOS__
[ios_view->glview bindDrawable];
#elif _WIN32
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
redraw = true;
clear();
update(0);
#if __OSX__
[osx_view async_swap];
#elif __IOS__
[ios_view->glview bindDrawable];
[ios_view async_swap];
#elif __ANDROID__
android_async_swap(and_engine);
#elif _WIN32
async_swap();
#endif
}
void App::async_redraw()
{
redraw = true;
@@ -822,7 +800,7 @@ void App::render_thread_main()
render_running = true;
while (render_running)
{
std::deque<std::packaged_task<void()>> working_list;
std::deque<AppTask> working_list;
// move the task list locally to free the queue for other threads
{
@@ -838,6 +816,7 @@ void App::render_thread_main()
while (!working_list.empty())
{
//LOG("render task %d", count);
//LOG("task %s", working_list.front().name.c_str());
count++;
working_list.front()();
working_list.pop_front();
@@ -867,7 +846,7 @@ void App::ui_thread_main()
int rendered_frames = 0;
while (ui_running)
{
std::deque<std::packaged_task<void()>> working_list;
std::deque<AppTask> working_list;
// move the task list locally to free the queue for other threads
{

View File

@@ -59,6 +59,20 @@ struct VRController
virtual float get_trigger_value() const { return 1.f; }
};
struct AppTask : public std::packaged_task<void()>
{
size_t task_id;
#ifdef _DEBUG
std::string name;
#endif
template<typename F> AppTask(F f) : std::packaged_task<void()>(f)
{
task_id = typeid(f).hash_code();
#ifdef _DEBUG
name = typeid(f).name();
#endif
}
};
class App
{
@@ -177,7 +191,6 @@ public:
void vr_digital(const VRController& c, VRController::kButton b, VRController::kAction a, glm::vec2 axis);
void vr_draw_ui();
void async_start();
void async_update();
void async_redraw();
void async_swap();
void async_end();
@@ -257,7 +270,7 @@ public:
// RENDER THREAD
//////////////////////////////////////////////////////////////////////////
static std::deque<std::packaged_task<void()>> render_tasklist;
static std::deque<AppTask> render_tasklist;
static std::mutex render_task_mutex;
static std::condition_variable render_cv;
static std::thread render_thread;
@@ -275,10 +288,10 @@ public:
// don't capture a reference to this ptr as the object may be destroyed
// by the time the task is executed
template<typename T, typename R = void>
std::future<R> render_task_async(T task)
std::future<R> render_task_async(T task, bool unique = false)
{
std::packaged_task<R()> pt(task);
std::future<R> f = pt.get_future();
AppTask pt(task);
auto f = pt.get_future();
if (is_render_thread())
{
pt();
@@ -287,6 +300,10 @@ public:
{
{
std::lock_guard<std::mutex> lock(render_task_mutex);
// remove any previously queued task from the same lambda
if (unique && !render_tasklist.empty())
render_tasklist.erase(std::remove_if(render_tasklist.begin(), render_tasklist.end(),
[id = pt.task_id](AppTask const& t){ return t.task_id == id; }), render_tasklist.end());
render_tasklist.push_back(std::move(pt));
}
render_cv.notify_all();
@@ -297,8 +314,8 @@ public:
template<typename T, typename R = void>
R render_task(T task)
{
std::packaged_task<R()> pt(task);
std::future<R> f = pt.get_future();
AppTask pt(task);
auto f = pt.get_future();
if (is_render_thread())
{
pt();
@@ -323,7 +340,7 @@ public:
// UI THREAD
//////////////////////////////////////////////////////////////////////////
static std::deque<std::packaged_task<void()>> ui_tasklist;
static std::deque<AppTask> ui_tasklist;
static std::mutex ui_task_mutex;
static std::condition_variable ui_cv;
static std::thread ui_thread;
@@ -341,10 +358,10 @@ public:
// don't capture a reference to this ptr as the object may be destroyed
// by the time the task is executed
template<typename T, typename R = void>
std::future<R> ui_task_async(T task)
std::future<R> ui_task_async(T task, bool unique = false)
{
std::packaged_task<R()> pt(task);
std::future<R> f = pt.get_future();
AppTask pt(task);
auto f = pt.get_future();
if (is_ui_thread())
{
pt();
@@ -353,6 +370,10 @@ public:
{
{
std::lock_guard<std::mutex> lock(ui_task_mutex);
// remove any previously queued task from the same lambda
if (unique && !ui_tasklist.empty())
ui_tasklist.erase(std::remove_if(ui_tasklist.begin(), ui_tasklist.end(),
[id = pt.task_id](AppTask const& t){ return t.task_id == id; }), ui_tasklist.end());
ui_tasklist.push_back(std::move(pt));
}
ui_cv.notify_all();
@@ -363,8 +384,8 @@ public:
template<typename T, typename R = void>
R ui_task(T task)
{
std::packaged_task<R()> pt(task);
std::future<R> f = pt.get_future();
AppTask pt(task);
auto f = pt.get_future();
if (is_ui_thread())
{
pt();

View File

@@ -1112,7 +1112,7 @@ void App::brush_update()
floating_picker->set_color(Canvas::I->m_current_brush->m_tip_color);
if (floating_color)
floating_color->set_color(Canvas::I->m_current_brush->m_tip_color);
});
}, true);
}
void App::init_menu_layer()

View File

@@ -1109,7 +1109,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
App::I->resize(w, h);
App::I->redraw = true;
});
}, true);
}
break;
}

View File

@@ -149,27 +149,27 @@ void NodePanelStroke::update_controls()
m_jitter_hue->m_value = b->m_jitter_hue;
m_jitter_sat->m_value = b->m_jitter_sat;
m_jitter_val->m_value = b->m_jitter_val;
m_jitter_hsv_eachsample->checked = b->m_jitter_hsv_eachsample;
m_jitter_hsv_eachsample->set_value(b->m_jitter_hsv_eachsample);
m_jitter_aspect->m_value = b->m_jitter_aspect;
m_tip_angle_follow->checked = b->m_tip_angle_follow;
m_tip_angle_init->checked = b->m_tip_angle_init;
m_tip_flow_pressure->checked = b->m_tip_flow_pressure;
m_tip_opacity_pressure->checked = b->m_tip_opacity_pressure;
m_tip_size_pressure->checked = b->m_tip_size_pressure;
m_jitter_aspect_bothaxis->checked = b->m_jitter_aspect_bothaxis;
m_tip_angle_follow->set_value(b->m_tip_angle_follow);
m_tip_angle_init->set_value(b->m_tip_angle_init);
m_tip_flow_pressure->set_value(b->m_tip_flow_pressure);
m_tip_opacity_pressure->set_value(b->m_tip_opacity_pressure);
m_tip_size_pressure->set_value(b->m_tip_size_pressure);
m_jitter_aspect_bothaxis->set_value(b->m_jitter_aspect_bothaxis);
m_tip_invert->checked = b->m_tip_invert;
m_tip_flipx->checked = b->m_tip_flipx;
m_tip_flipy->checked = b->m_tip_flipy;
m_pattern_enabled->checked = b->m_pattern_enabled;
m_dual_enabled->checked = b->m_dual_enabled;
m_dual_scatter_bothaxis->checked = b->m_dual_scatter_bothaxis;
m_dual_invert->checked = b->m_dual_invert;
m_dual_flipx->checked = b->m_dual_flipx;
m_dual_flipy->checked = b->m_dual_flipy;
m_dual_randflip->checked = b->m_dual_randflip;
m_tip_randflipx->checked = b->m_tip_randflipx;
m_tip_randflipy->checked = b->m_tip_randflipy;
m_tip_invert->set_value(b->m_tip_invert);
m_tip_flipx->set_value(b->m_tip_flipx);
m_tip_flipy->set_value(b->m_tip_flipy);
m_pattern_enabled->set_value(b->m_pattern_enabled);
m_dual_enabled->set_value(b->m_dual_enabled);
m_dual_scatter_bothaxis->set_value(b->m_dual_scatter_bothaxis);
m_dual_invert->set_value(b->m_dual_invert);
m_dual_flipx->set_value(b->m_dual_flipx);
m_dual_flipy->set_value(b->m_dual_flipy);
m_dual_randflip->set_value(b->m_dual_randflip);
m_tip_randflipx->set_value(b->m_tip_randflipx);
m_tip_randflipy->set_value(b->m_tip_randflipy);
m_dual_size->m_value = m_curves[m_dual_size].to_slider(b->m_dual_size);
m_dual_spacing->m_value = m_curves[m_dual_spacing].to_slider(b->m_dual_spacing);
@@ -179,11 +179,11 @@ void NodePanelStroke::update_controls()
m_dual_opacity->m_value = b->m_dual_opacity;
m_dual_rotate->m_value = b->m_dual_rotate;
m_pattern_eachsample->checked = b->m_pattern_eachsample;
m_pattern_invert->checked = b->m_pattern_invert;
m_pattern_flipx->checked = b->m_pattern_flipx;
m_pattern_flipy->checked = b->m_pattern_flipy;
m_pattern_rand_offset->checked = b->m_pattern_rand_offset;
m_pattern_eachsample->set_value(b->m_pattern_eachsample);
m_pattern_invert->set_value(b->m_pattern_invert);
m_pattern_flipx->set_value(b->m_pattern_flipx);
m_pattern_flipy->set_value(b->m_pattern_flipy);
m_pattern_rand_offset->set_value(b->m_pattern_rand_offset);
m_pattern_scale->m_value = m_curves[m_pattern_scale].to_slider(b->m_pattern_scale);
m_pattern_brightness->m_value = b->m_pattern_brightness;
m_pattern_contrast->m_value = b->m_pattern_contrast;