render timer

This commit is contained in:
David Kocik 2020-12-16 13:59:16 +01:00
parent 0592d15c50
commit 3ae40139b3
4 changed files with 33 additions and 25 deletions

View File

@ -2409,7 +2409,6 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
{
if (!m_initialized)
return;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
/*NotificationManager* notification_mgr = wxGetApp().plater()->get_notification_manager();
if (notification_mgr->requires_update())
@ -2982,7 +2981,17 @@ void GLCanvas3D::on_timer(wxTimerEvent& evt)
void GLCanvas3D::on_render_timer(wxTimerEvent& evt)
{
render();
// If slicer is not top window -> restart timer with one second to try again
wxWindow* p = dynamic_cast<wxWindow*>(wxGetApp().plater());
while (p->GetParent() != nullptr)
p = p->GetParent();
wxTopLevelWindow* top_level_wnd = dynamic_cast<wxTopLevelWindow*>(p);
if (!top_level_wnd->IsActive()) {
request_extra_frame_delayed(1000);
return;
}
//render();
m_dirty = true;
}
void GLCanvas3D::request_extra_frame_delayed(wxLongLong miliseconds)
@ -2995,6 +3004,7 @@ void GLCanvas3D::request_extra_frame_delayed(wxLongLong miliseconds)
} else {
const wxLongLong remaining_time = m_extra_frame_requested_delayed - (wxGetLocalTimeMillis() - m_render_timer_start);
if(miliseconds < remaining_time) {
m_render_timer.Stop();
m_extra_frame_requested_delayed = miliseconds;
m_render_timer.StartOnce((int)miliseconds.ToLong());
m_render_timer_start = wxGetLocalTimeMillis();

View File

@ -22,6 +22,9 @@ static constexpr float SPACE_RIGHT_PANEL = 10.0f;
static constexpr float FADING_OUT_DURATION = 2.0f;
// Time in Miliseconds after next render is requested
static constexpr int FADING_OUT_TIMEOUT = 100;
// If timeout is changed to higher than 1 second, substract_time call should be revorked
static constexpr int MAX_TIMEOUT_MILISECONDS = 1000;
static constexpr int MAX_TIMEOUT_SECONDS = 1;
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
namespace Slic3r {
@ -136,7 +139,7 @@ NotificationManager::PopNotification::PopNotification(const NotificationData &n,
, m_hypertext (n.hypertext)
, m_text2 (n.text2)
, m_evt_handler (evt_handler)
, m_notification_start (wxGetLocalTimeMillis())
// , m_notification_start (wxGetLocalTimeMillis())
{
//init();
}
@ -763,24 +766,26 @@ void NotificationManager::PopNotification::update_state()
m_fading_out = false;
m_current_fade_opacity = 1.0f;
m_remaining_time = m_data.duration;
// m_notification_start = wxGetLocalTimeMillis();
BOOST_LOG_TRIVIAL(error) << "hover";
}
if (m_counting_down) {
wxMilliClock_t up_time = wxGetLocalTimeMillis() - m_notification_start;
//wxMilliClock_t up_time = wxGetLocalTimeMillis() - m_notification_start;
if (m_fading_out && m_current_fade_opacity <= 0.0f)
m_finished = true;
else if (!m_fading_out && up_time >= m_remaining_time * 1000) {
else if (!m_fading_out && m_remaining_time <=0/*up_time >= m_data.duration * 1000*/) {
m_fading_out = true;
m_fading_start = wxGetLocalTimeMillis();
m_last_render_fading = wxGetLocalTimeMillis();
} else if (!m_fading_out) {
m_next_render = m_remaining_time * 1000 - up_time;
BOOST_LOG_TRIVIAL(error) << (boost::format("next render %1%") % m_next_render);
m_next_render = std::min<wxLongLong>(/*m_data.duration * 1000 - up_time*/m_remaining_time * 1000, MAX_TIMEOUT_MILISECONDS);
//BOOST_LOG_TRIVIAL(error) << (boost::format("up time %1% next render %2%") % up_time % m_next_render);
}
}
if (m_finished) {
m_state = EState::Finished;
m_next_render = 0;
@ -802,15 +807,15 @@ void NotificationManager::PopNotification::update_state()
m_current_fade_opacity = std::clamp(1.0f - 0.001f * static_cast<float>(curr_time.GetValue()) / FADING_OUT_DURATION, 0.0f, 1.0f);
auto next_render = FADING_OUT_TIMEOUT - no_render_time;
if (next_render <= 0) {
m_last_render_fading = wxGetLocalTimeMillis();
//m_last_render_fading = wxGetLocalTimeMillis();
m_state = EState::FadingOutRender;
m_next_render = 0;
} else
m_next_render = next_render;
BOOST_LOG_TRIVIAL(error) << (boost::format("fade render %1%") % m_next_render);
//BOOST_LOG_TRIVIAL(error) << (boost::format("fade render %1%") % m_next_render);
}
}
BOOST_LOG_TRIVIAL(error) << (boost::format("remaining time %1% fading %2% next render %3%") % m_remaining_time % m_fading_out % m_next_render);
}
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
@ -1399,11 +1404,6 @@ void NotificationManager::update_notifications()
break;
}
}
if (m_hovered) {
for (const std::unique_ptr<PopNotification>& notification : m_pop_notifications) {
notification->reset_start_time();
}
}
// Reuire render if some notification was just deleted.
@ -1450,13 +1450,13 @@ void NotificationManager::update_notifications()
long now = wxGetLocalTime();
// Pausing fade-out when the mouse is over some notification.
if (!m_hovered && m_last_time < now) {
if (now - m_last_time >= 1) {
if (now - m_last_time >= MAX_TIMEOUT_SECONDS) {
for (auto& notification : m_pop_notifications) {
//if (notification->get_state() != PopNotification::EState::Static)
notification->substract_remaining_time();
notification->substract_remaining_time(MAX_TIMEOUT_SECONDS);
}
m_last_time = now;
}
m_last_time = now;
}
}
}

View File

@ -232,7 +232,7 @@ private:
const NotificationData get_data() const { return m_data; }
const bool is_gray() const { return m_is_gray; }
// Call equals one second down
void substract_remaining_time() { m_remaining_time--; }
void substract_remaining_time(int seconds) { m_remaining_time -= seconds; }
void set_gray(bool g) { m_is_gray = g; }
void set_paused(bool p) { m_paused = p; }
bool compare_text(const std::string& text);
@ -243,7 +243,7 @@ private:
bool requires_update() const { return m_state != EState::Hidden; }
EState get_state() const { return m_state; }
wxLongLong next_render() const { return m_next_render; }
void reset_start_time() { m_notification_start = wxGetLocalTimeMillis(); }
// void reset_start_time() { m_notification_start = wxGetLocalTimeMillis(); }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
protected:
@ -303,7 +303,7 @@ private:
// time of last done render when fading
wxLongLong m_last_render_fading { 0LL };
// first appereance of notification or last hover;
wxLongLong m_notification_start;
// wxLongLong m_notification_start;
// time to next must-do render
wxLongLong m_next_render { std::numeric_limits<wxLongLong>::max() };
#else

View File

@ -741,8 +741,6 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3
{
if (! p->enabled_config_update) { return R_NOOP; }
GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::PresetUpdateAvailable);
auto updates = p->get_config_updates(old_slic3r_version);
if (updates.incompats.size() > 0) {
BOOST_LOG_TRIVIAL(info) << format("%1% bundles incompatible. Asking for action...", updates.incompats.size());