Fix bloating of history with live preview

This commit is contained in:
Filip Sykala 2021-10-19 16:15:27 +02:00
parent 76cbb7c17e
commit 79dd007ec7
2 changed files with 60 additions and 12 deletions

View file

@ -7,6 +7,9 @@
#include "GLGizmoPainterBase.hpp" // for render wireframe
#include "admesh/stl.h" // indexed_triangle_set
#include <thread>
#include <mutex>
#include <condition_variable>
#include <chrono>
#include <optional>
#include <atomic>
@ -47,6 +50,7 @@ private:
void set_its(indexed_triangle_set &its);
void create_gui_cfg();
void request_rerender();
// move to global functions
static ModelVolume *get_volume(const Selection &selection, Model &model);
static const ModelVolume *get_volume(const GLVolume::CompositeID &cid, const Model &model);
@ -62,10 +66,14 @@ private:
size_t m_obj_index;
std::optional<indexed_triangle_set> m_original_its;
bool m_show_wireframe;
bool m_show_wireframe;
volatile bool m_need_reload; // after simplify, glReload must be on main thread
std::thread m_worker;
// wait before process
std::mutex m_state_mutex;
std::condition_variable m_dealy_process_cv;
enum class State {
settings,
@ -87,8 +95,14 @@ private:
void fix_count_by_ratio(size_t triangle_count)
{
wanted_count = static_cast<uint32_t>(
std::round(triangle_count * (100.f-decimate_ratio) / 100.f));
if (decimate_ratio <= 0.f) {
wanted_count = static_cast<uint32_t>(triangle_count);
return;
} else if (decimate_ratio >= 1.f) {
wanted_count = 0;
return;
}
wanted_count = static_cast<uint32_t>(std::round(triangle_count * (100.f-decimate_ratio) / 100.f));
}
} m_configuration;
@ -106,6 +120,10 @@ private:
// trunc model name when longer
size_t max_char_in_name = 30;
// to prevent freezing when move in gui
// delay before process in [ms]
std::chrono::duration<long int, std::milli> prcess_delay = std::chrono::milliseconds(250);
};
std::optional<GuiCfg> m_gui_cfg;
@ -122,6 +140,16 @@ private:
void free_gpu();
GLuint m_wireframe_VBO_id, m_wireframe_IBO_id;
size_t m_wireframe_IBO_size;
// cancel exception
class SimplifyCanceledException: public std::exception
{
public:
const char *what() const throw()
{
return L("Model simplification has been canceled");
}
};
};
} // namespace GUI