summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-05-12 15:45:18 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-05-12 15:48:17 +0200
commiteebafd92fc40f303cef38746a4007b0554a49299 (patch)
tree9e16d6367e86f47a35086c4f0eeb0c53fe8ca31f
parentf7ab2dc5a54c573cd7408a68cb1e93174827719e (diff)
logic/tracker: use std::chrono
-rw-r--r--logic/tracker.cpp22
-rw-r--r--logic/tracker.h2
2 files changed, 13 insertions, 11 deletions
diff --git a/logic/tracker.cpp b/logic/tracker.cpp
index 7411d3b4..8367ee2f 100644
--- a/logic/tracker.cpp
+++ b/logic/tracker.cpp
@@ -24,6 +24,7 @@
using namespace euler;
using namespace gui_tracker_impl;
+using namespace time_units;
constexpr double Tracker::r2d;
constexpr double Tracker::d2r;
@@ -32,7 +33,7 @@ Tracker::Tracker(Mappings& m, SelectedLibraries& libs, TrackLogger& logger) :
m(m),
libs(libs),
logger(logger),
- backlog_time(0),
+ backlog_time(ns(0)),
tracking_started(false)
{
}
@@ -403,21 +404,22 @@ void Tracker::run()
{
logic();
- static constexpr long const_sleep_us = 4000;
- const long elapsed_usecs = t.elapsed_usecs();
- t.start();
+ static constexpr ns const_sleep_ms(time_cast<ns>(ms(4)));
+ const ns elapsed_nsecs = prog1(t.elapsed<ns>(), t.start());
- backlog_time += elapsed_usecs - const_sleep_us;
+ backlog_time += ns(elapsed_nsecs - const_sleep_ms);
- if (std::fabs(backlog_time) > 3000 * 1000)
+ if (backlog_time > secs_(3) || backlog_time < secs_(-3))
{
- qDebug() << "tracker: backlog interval overflow" << backlog_time;
- backlog_time = 0;
+ qDebug() << "tracker: backlog interval overflow"
+ << time_cast<ms>(backlog_time).count() << "ms";
+ backlog_time = backlog_time.zero();
}
- const unsigned sleep_time = unsigned(std::round(clamp((const_sleep_us - backlog_time)/1000., 0, const_sleep_us*2.5/1000)));
+ const int sleep_time_ms = iround(clamp(const_sleep_ms - backlog_time,
+ ns(0), ms(50)).count());
- portable::sleep(sleep_time);
+ portable::sleep(sleep_time_ms);
}
{
diff --git a/logic/tracker.h b/logic/tracker.h
index 85bd1ed8..2f29aca7 100644
--- a/logic/tracker.h
+++ b/logic/tracker.h
@@ -85,7 +85,7 @@ private:
state real_rotation, scaled_rotation;
euler_t t_center;
- long backlog_time;
+ time_units::ns backlog_time;
bool tracking_started;