delta time for loader

This commit is contained in:
Eberhard Graether
2016-07-08 14:37:49 +02:00
parent cad473c097
commit 9550ea1fdc
5 changed files with 30 additions and 3 deletions
+10
View File
@@ -24,6 +24,11 @@ TimePoint::TimePoint(std::string s)
}
}
TimePoint TimePoint::now()
{
return TimePoint(boost::posix_time::microsec_clock::local_time());
}
std::string TimePoint::toString() const
{
std::stringstream stream;
@@ -32,4 +37,9 @@ std::string TimePoint::toString() const
stream.imbue(std::locale(std::locale::classic(), facet));
stream << m_time;
return stream.str();
}
size_t TimePoint::deltaMS(const TimePoint& other) const
{
return (m_time - other.m_time).total_milliseconds();
}
+5 -1
View File
@@ -11,6 +11,8 @@ public:
//TimePoint(time_t t);
TimePoint(std::string s);
static TimePoint now();
std::string toString() const;
inline bool operator==(const TimePoint& rhs){ return m_time == rhs.m_time; }
@@ -20,7 +22,9 @@ public:
inline bool operator<=(const TimePoint& rhs){ return m_time <= rhs.m_time; }
inline bool operator>=(const TimePoint& rhs){ return m_time >= rhs.m_time; }
inline float operator-(const TimePoint& rhs){ return (m_time - rhs.m_time).total_milliseconds() / 1000.0f; }
inline float operator-(const TimePoint& rhs){ return deltaMS(rhs) / 1000.0f; }
size_t deltaMS(const TimePoint& other) const;
private:
boost::posix_time::ptime m_time;
+1 -1
View File
@@ -3,7 +3,7 @@
TimePoint utility::durationStart()
{
return TimePoint(boost::posix_time::microsec_clock::local_time());
return TimePoint::now();
}
float utility::duration(const TimePoint& start)
+11 -1
View File
@@ -34,6 +34,7 @@ QtOverlay::QtOverlay(QWidget* parent)
void QtOverlay::start()
{
m_timePoint = TimePoint::now();
m_timer->start(FRAME_DELAY_MS);
show();
}
@@ -46,7 +47,16 @@ void QtOverlay::stop()
void QtOverlay::animate()
{
m_count += FRAME_DELAY_MS;
TimePoint t = TimePoint::now();
size_t dt = t.deltaMS(m_timePoint);
if (dt < 5)
{
return;
}
m_timePoint = t;
m_count += dt;
QPoint center = geometry().center();
update(QRect(center.x() - m_size / 2, center.y() - m_size / 2, m_size, m_size));
+3
View File
@@ -4,6 +4,7 @@
#include <QWidget>
#include "qt/utility/QtThreadedFunctor.h"
#include "utility/TimePoint.h"
class QTimer;
@@ -49,6 +50,8 @@ private:
size_t m_count;
size_t m_size;
TimePoint m_timePoint;
};