diff --git a/include/nana/gui/animation.hpp b/include/nana/gui/animation.hpp
index 42a338d9..d9a62e26 100644
--- a/include/nana/gui/animation.hpp
+++ b/include/nana/gui/animation.hpp
@@ -51,6 +51,7 @@ namespace nana
class performance_manager;
public:
animation(std::size_t fps = 23);
+ ~animation();
void push_back(frameset frms);
/*
diff --git a/source/gui/animation.cpp b/source/gui/animation.cpp
index 5f252e8c..4b1c8e59 100644
--- a/source/gui/animation.cpp
+++ b/source/gui/animation.cpp
@@ -182,12 +182,11 @@ namespace nana
//Only list whos iterator would not invalided after a insertion.
std::list frames;
std::list::iterator this_frame;
- std::size_t pos_in_this_frame;
- mutable bool good_frame_by_frmbuilder; //It indicates the state of frame whether is valid.
+ std::size_t pos_in_this_frame{ 0 };
+ mutable bool good_frame_by_frmbuilder{ false }; //It indicates the state of frame whether is valid.
impl()
- : this_frame(frames.end()), pos_in_this_frame(0),
- good_frame_by_frmbuilder(false)
+ : this_frame(frames.end())
{}
//Render A frame on the set of windows.
@@ -343,8 +342,6 @@ namespace nana
void set_fps(impl*, std::size_t new_fps);
void close(impl* p);
bool empty() const;
- private:
- void _m_perf_thread(thread_variable* thrvar);
private:
mutable std::recursive_mutex mutex_;
std::vector threads_;
@@ -458,7 +455,48 @@ namespace nana
thr->interval = 1000.0 / double(p->fps);
thr->thread = std::make_shared([this, thr]()
{
- _m_perf_thread(thr);
+ nana::system::timepiece tmpiece;
+ while (true)
+ {
+ thr->active = 0;
+ tmpiece.start();
+
+ {
+ std::lock_guardmutex)> lock(thr->mutex);
+ for (auto ani : thr->animations)
+ {
+ if (ani->paused)
+ continue;
+
+ ani->render_this_frame();
+ if (false == ani->move_to_next())
+ {
+ if (ani->looped)
+ {
+ ani->reset();
+ ++thr->active;
+ }
+ }
+ else
+ ++thr->active;
+ }
+ }
+
+ if (thr->active)
+ {
+ thr->performance_parameter = tmpiece.calc();
+ if (thr->performance_parameter < thr->interval)
+ nana::system::sleep(static_cast(thr->interval - thr->performance_parameter));
+ }
+ else
+ {
+ //There isn't an active frame, then let the thread
+ //wait for a signal for an active animation
+ std::unique_lock lock(thr->mutex);
+ if (0 == thr->active)
+ thr->condvar.wait(lock);
+ }
+ }
});
threads_.push_back(thr);
@@ -520,58 +558,16 @@ namespace nana
}
return true;
}
-
- void animation::performance_manager::_m_perf_thread(thread_variable* thrvar)
- {
- nana::system::timepiece tmpiece;
- while(true)
- {
- thrvar->active = 0;
- tmpiece.start();
-
- {
- std::lock_guardmutex)> lock(thrvar->mutex);
- for(auto ani : thrvar->animations)
- {
- if(ani->paused)
- continue;
-
- ani->render_this_frame();
- if(false == ani->move_to_next())
- {
- if(ani->looped)
- {
- ani->reset();
- ++thrvar->active;
- }
- }
- else
- ++thrvar->active;
- }
- }
-
- if(thrvar->active)
- {
- thrvar->performance_parameter = tmpiece.calc();
- if(thrvar->performance_parameter < thrvar->interval)
- nana::system::sleep(static_cast(thrvar->interval - thrvar->performance_parameter));
- }
- else
- {
- //There isn't an active frame, then let the thread
- //wait for a signal for an active animation
- std::unique_lock lock(thrvar->mutex);
- if(0 == thrvar->active)
- thrvar->condvar.wait(lock);
- }
- }
- }
//end class animation::performance_manager
animation::animation(std::size_t fps)
: impl_(new impl(fps))
{
+ }
+ animation::~animation()
+ {
+ delete impl_;
}
void animation::push_back(frameset frms)