FIX: extra frame request

Do not freeze bargraph in Siplify dialog when no mouse move.
This commit is contained in:
Filip Sykala 2021-08-17 15:28:08 +02:00
parent 090728b9d5
commit 11c91d781e
4 changed files with 22 additions and 35 deletions

View File

@ -2780,11 +2780,10 @@ void GLCanvas3D::on_timer(wxTimerEvent& evt)
void GLCanvas3D::on_render_timer(wxTimerEvent& evt)
{
// no need to do anything here
// right after this event is recieved, idle event is fired
//m_dirty = true;
//wxWakeUpIdle();
m_dirty = true;
// wxWakeUpIdle();
// no need to wake up idle
// right after this event, idle event is fired
}
@ -2802,21 +2801,15 @@ void GLCanvas3D::schedule_extra_frame(int miliseconds)
return;
}
}
// Start timer
int64_t now = timestamp_now();
int remaining_time = m_render_timer.GetInterval();
// Timer is not running
if (! m_render_timer.IsRunning()) {
m_extra_frame_requested_delayed = miliseconds;
if (!m_render_timer.IsRunning()) {
m_render_timer.StartOnce(miliseconds);
m_render_timer_start = now;
// Timer is running - restart only if new period is shorter than remaning period
} else {
const int64_t remaining_time = (m_render_timer_start + m_extra_frame_requested_delayed) - now;
if (miliseconds + 20 < remaining_time) {
m_render_timer.Stop();
m_extra_frame_requested_delayed = miliseconds;
m_render_timer.StartOnce(miliseconds);
m_render_timer_start = now;
}
}
}

View File

@ -464,14 +464,12 @@ private:
// when true renders an extra frame by not resetting m_dirty to false
// see request_extra_frame()
bool m_extra_frame_requested;
int m_extra_frame_requested_delayed { std::numeric_limits<int>::max() };
bool m_event_handlers_bound{ false };
GLVolumeCollection m_volumes;
GCodeViewer m_gcode_viewer;
RenderTimer m_render_timer;
int64_t m_render_timer_start;
Selection m_selection;
const DynamicPrintConfig* m_config;

View File

@ -184,7 +184,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
}
ImGui::SameLine(m_gui_cfg->bottom_left_width);
if (m_imgui->button(_L("Preview"))) {
m_state = State::simplifying;
m_state = State::preview;
// simplify but not aply on mesh
process();
}
@ -270,16 +270,11 @@ void GLGizmoSimplify::process()
};
indexed_triangle_set collapsed;
if (m_last_error.has_value()) {
// is chance to continue with last reduction
const indexed_triangle_set &its = m_volume->mesh().its;
uint32_t last_triangle_count = static_cast<uint32_t>(its.indices.size());
if ((!m_configuration.use_count || triangle_count <= last_triangle_count) &&
if (m_last_error.has_value() && m_last_count.has_value() &&
(!m_configuration.use_count || triangle_count <= *m_last_count) &&
(!m_configuration.use_error || m_configuration.max_error <= *m_last_error)) {
collapsed = its; // small copy
} else {
collapsed = *m_original_its; // copy
}
// continue from last reduction - speed up
collapsed = m_volume->mesh().its; // small copy
} else {
collapsed = *m_original_its; // copy
}
@ -288,14 +283,14 @@ void GLGizmoSimplify::process()
its_quadric_edge_collapse(collapsed, triangle_count, &max_error, throw_on_cancel, statusfn);
set_its(collapsed);
m_is_valid_result = true;
m_last_count = triangle_count; // need to store last requirement, collapsed count could be count-1
m_last_error = max_error;
} catch (SimplifyCanceledException &) {
// set state out of main thread
m_last_error = {};
m_state = State::settings;
}
// need to render last status fn
// without sleep it freezes until mouse move
std::this_thread::sleep_for(std::chrono::milliseconds(50));
// need to render last status fn to change bar graph to buttons
m_parent.schedule_extra_frame(0);
});
}

View File

@ -36,17 +36,18 @@ private:
size_t m_obj_index;
std::optional<indexed_triangle_set> m_original_its;
std::optional<float> m_last_error; // for use previous reduction
std::optional<uint32_t> m_last_count;
volatile bool m_need_reload; // after simplify, glReload must be on main thread
std::thread m_worker;
enum class State {
settings,
simplifying, // start processing
canceling, // canceled
successfull, // successful simplified
close_on_end
preview, // simplify to show preview
close_on_end, // simplify with close on end
canceling // after button click, before canceled
};
volatile State m_state;