summaryrefslogtreecommitdiffhomepage
path: root/logic/tracker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/tracker.cpp')
-rw-r--r--logic/tracker.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/logic/tracker.cpp b/logic/tracker.cpp
index 1a37a8a1..a7b19a48 100644
--- a/logic/tracker.cpp
+++ b/logic/tracker.cpp
@@ -12,9 +12,13 @@
* originally written by Wim Vriend.
*/
+#include "compat/nan.hpp"
#include "compat/sleep.hpp"
#include "compat/util.hpp"
-#include "compat/timer-resolution.hpp"
+
+#if defined _WIN32
+# include "compat/timer-resolution.hpp"
+#endif
#include "tracker.h"
@@ -22,6 +26,10 @@
#include <algorithm>
#include <cstdio>
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
using namespace euler;
using namespace gui_tracker_impl;
using namespace time_units;
@@ -90,8 +98,6 @@ void Tracker::t_compensate(const rmat& rmat, const euler_t& xyz, euler_t& output
output(TX) = -ret(tb_X);
}
-#include "compat/nan.hpp"
-
static inline double elide_nan(double value, double def)
{
if (nanp(value))
@@ -376,8 +382,6 @@ void Tracker::run()
{
setPriority(QThread::HighPriority);
- timer_resolution res(1);
-
{
static constexpr const char* posechannels[6] = { "TX", "TY", "TZ", "Yaw", "Pitch", "Roll" };
static constexpr const char* datachannels[5] = { "dt", "raw", "corrected", "filtered", "mapped" };
@@ -398,15 +402,18 @@ void Tracker::run()
t.start();
+#if defined _WIN32
+ timer_resolution res;
+ (void) res;
+#endif
+
while (!get(f_should_quit))
{
logic();
- static constexpr ns const_sleep_ms(time_cast<ns>(ms(4)));
+ static constexpr ns const_sleep_ms(time_cast<ns>(ms_(4)));
const ns elapsed_nsecs = prog1(t.elapsed<ns>(), t.start());
- backlog_time += ns(elapsed_nsecs - const_sleep_ms);
-
if (backlog_time > secs_(3) || backlog_time < secs_(-3))
{
qDebug() << "tracker: backlog interval overflow"
@@ -414,23 +421,25 @@ void Tracker::run()
backlog_time = backlog_time.zero();
}
- const int sleep_time_ms = iround(time_cast<ms>(clamp(const_sleep_ms - backlog_time,
- ns(0), ms(50)))
- .count());
+ backlog_time += ns(elapsed_nsecs - const_sleep_ms);
+
+ const int sleep_time_ms = iround(std::fmax(0.,
+ (time_cast<ms>(clamp(const_sleep_ms - backlog_time,
+ ms_::zero(), ms_(50)))).count()));
portable::sleep(sleep_time_ms);
- }
- {
- // filter may inhibit exact origin
- Pose p;
- libs.pProtocol->pose(p);
- }
+ {
+ // filter may inhibit exact origin
+ Pose p;
+ libs.pProtocol->pose(p);
+ }
- for (int i = 0; i < 6; i++)
- {
- m(i).spline_main.set_tracking_active(false);
- m(i).spline_alt.set_tracking_active(false);
+ for (int i = 0; i < 6; i++)
+ {
+ m(i).spline_main.set_tracking_active(false);
+ m(i).spline_alt.set_tracking_active(false);
+ }
}
}