From 6a0b654228494fec577f0245f0ca07aaab1722e2 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sun, 14 Jul 2019 21:56:43 +0200 Subject: [PATCH] fix checkbox icon update, add unique check on async tasks --- src/app.cpp | 31 ++++--------------------- src/app.h | 47 +++++++++++++++++++++++++++----------- src/app_layout.cpp | 2 +- src/main.cpp | 2 +- src/node_panel_stroke.cpp | 48 +++++++++++++++++++-------------------- 5 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 4034b4a..654ac5e 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -27,14 +27,14 @@ void destroy_window(); App* App::I = nullptr; // singleton -std::deque> App::render_tasklist; +std::deque 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> App::ui_tasklist; +std::deque 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> working_list; + std::deque 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> working_list; + std::deque working_list; // move the task list locally to free the queue for other threads { diff --git a/src/app.h b/src/app.h index f02e16e..84a3fa4 100644 --- a/src/app.h +++ b/src/app.h @@ -59,6 +59,20 @@ struct VRController virtual float get_trigger_value() const { return 1.f; } }; +struct AppTask : public std::packaged_task +{ + size_t task_id; +#ifdef _DEBUG + std::string name; +#endif + template AppTask(F f) : std::packaged_task(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> render_tasklist; + static std::deque 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 - std::future render_task_async(T task) + std::future render_task_async(T task, bool unique = false) { - std::packaged_task pt(task); - std::future 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 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 R render_task(T task) { - std::packaged_task pt(task); - std::future 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> ui_tasklist; + static std::deque 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 - std::future ui_task_async(T task) + std::future ui_task_async(T task, bool unique = false) { - std::packaged_task pt(task); - std::future 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 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 R ui_task(T task) { - std::packaged_task pt(task); - std::future f = pt.get_future(); + AppTask pt(task); + auto f = pt.get_future(); if (is_ui_thread()) { pt(); diff --git a/src/app_layout.cpp b/src/app_layout.cpp index b016f59..abfcd44 100644 --- a/src/app_layout.cpp +++ b/src/app_layout.cpp @@ -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() diff --git a/src/main.cpp b/src/main.cpp index 1ed7241..8adba61 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; } diff --git a/src/node_panel_stroke.cpp b/src/node_panel_stroke.cpp index a60f6aa..0db8d0c 100644 --- a/src/node_panel_stroke.cpp +++ b/src/node_panel_stroke.cpp @@ -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;