summaryrefslogtreecommitdiffhomepage
path: root/logic
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-12 18:56:26 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-10-12 17:08:59 +0000
commitc57b524d3038dd1d94379038d362dea5b2896c60 (patch)
treee6946995a856f91d6e0f069fa8aa0a88e38d164d /logic
parent95d18c6a04b83943b0c3d095fedb681a2a0a2c0b (diff)
logic/pipeline: cleanup only
Diffstat (limited to 'logic')
-rw-r--r--logic/main-settings.cpp1
-rw-r--r--logic/pipeline.cpp53
-rw-r--r--logic/pipeline.hpp5
-rw-r--r--logic/shortcuts.h4
-rw-r--r--logic/work.cpp24
-rw-r--r--logic/work.hpp21
6 files changed, 62 insertions, 46 deletions
diff --git a/logic/main-settings.cpp b/logic/main-settings.cpp
index 901e1845..2bf0ad1f 100644
--- a/logic/main-settings.cpp
+++ b/logic/main-settings.cpp
@@ -23,7 +23,6 @@ main_settings::main_settings() :
tray_enabled(b, "use-system-tray", false),
tray_start(b, "start-in-tray", false),
center_at_startup(b, "center-at-startup", true),
- //center_method(b, "centering-method", 1),
neck_z(b, "neck-depth", 0),
neck_enable(b, "neck-enable", false),
key_start_tracking1(b, "start-tracking"),
diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp
index 9c50b100..e506b7cf 100644
--- a/logic/pipeline.cpp
+++ b/logic/pipeline.cpp
@@ -28,10 +28,16 @@
# include <windows.h>
#endif
+#if defined __llvm__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wlanguage-extension-token"
+# pragma clang diagnostic ignored "-Wunknown-pragmas"
+#endif
+
namespace pipeline_impl {
-static constexpr inline double r2d = 180. / M_PI;
-static constexpr inline double d2r = M_PI / 180.;
+static constexpr inline double r2d = 180 / M_PI;
+static constexpr inline double d2r = M_PI / 180;
reltrans::reltrans() = default;
@@ -183,7 +189,8 @@ euler_t reltrans::apply_neck(const rmat& R, int nz, bool disable_tz) const
pipeline::pipeline(Mappings& m, runtime_libraries& libs, event_handler& ev, TrackLogger& logger) :
m(m), ev(ev), libs(libs), logger(logger)
-{}
+{
+}
pipeline::~pipeline()
{
@@ -200,6 +207,11 @@ double pipeline::map(double pos, Map& axis)
return double(fc.get_value(pos));
}
+//#define NO_NAN_CHECK
+//#define DEBUG_TIMINGS
+
+#ifndef NO_NAN_CHECK
+
template<int u, int w>
static bool is_nan(const dmat<u,w>& r)
{
@@ -228,8 +240,7 @@ bool nan_check_(const x& datum, const y& next, const xs&... rest)
return nan_check_(datum) || nan_check_(next, rest...);
}
-static cc_noinline
-void emit_nan_check_msg(const char* text, const char* fun, int line)
+static void emit_nan_check_msg(const char* text, const char* fun, int line)
{
eval_once(
qDebug() << "nan check failed"
@@ -262,6 +273,10 @@ bool maybe_nan(const char* text, const char* fun, int line, const xs&... vals)
goto error; \
} while (false)
+#else
+# define nan_check(...) (void)(__VA_ARGS__)
+#endif
+
bool pipeline::maybe_enable_center_on_tracking_started()
{
if (!tracking_started)
@@ -275,7 +290,7 @@ bool pipeline::maybe_enable_center_on_tracking_started()
if (tracking_started && s.center_at_startup)
{
- b.set(f_center, true);
+ set_center(true);
return true;
}
}
@@ -283,10 +298,12 @@ bool pipeline::maybe_enable_center_on_tracking_started()
return false;
}
-void pipeline::maybe_set_center_pose(const Pose& value, bool own_center_logic)
+void pipeline::set_center_pose(const Pose& value, bool own_center_logic)
{
if (b.get(f_center | f_held_center))
{
+ set_center(false);
+
if (libs.pFilter)
libs.pFilter->center();
@@ -448,10 +465,12 @@ void pipeline::logic()
value = clamp_value(value);
{
- maybe_enable_center_on_tracking_started();
store_tracker_pose(value);
- maybe_set_center_pose(value, own_center_logic);
+
+ maybe_enable_center_on_tracking_started();
+ set_center_pose(value, own_center_logic);
value = apply_center(value);
+
// "corrected" - after various transformations to account for camera position
logger.write_pose(value);
}
@@ -500,7 +519,7 @@ error:
ok:
- b.set(f_center, false);
+ set_center(false);
if (b.get(f_zero))
for (int i = 0; i < 6; i++)
@@ -533,9 +552,9 @@ void pipeline::run()
logger.write(datachannels[0]);
char buffer[16];
- for (unsigned j = 1; j < 5; ++j)
+ for (unsigned j = 1; j < 5; ++j) // NOLINT(modernize-loop-convert)
{
- for (unsigned i = 0; i < 6; ++i)
+ for (unsigned i = 0; i < 6; ++i) // NOLINT(modernize-loop-convert)
{
std::sprintf(buffer, "%s%s", datachannels[j], posechannels[i]);
logger.write(buffer);
@@ -568,7 +587,7 @@ void pipeline::run()
const int sleep_time_ms = ms{clamp(const_sleep_ms - backlog_time,
ms{}, ms{10})}.count() + .1f;
-#if 0
+#ifdef DEBUG_TIMINGS
{
static int cnt;
static Timer tt;
@@ -577,7 +596,7 @@ void pipeline::run()
tt.start();
qDebug() << cnt << "Hz"
<< "sleepy time" << sleep_time_ms
- << "elapsed" << ms{elapsed_nsecs}.count()
+ << "diff" << ms{elapsed_nsecs}.count() - ms{const_sleep_ms}.count()
<< "backlog" << ms{backlog_time}.count();
cnt = 0;
}
@@ -615,7 +634,7 @@ void pipeline::raw_and_mapped_pose(double* mapped, double* raw) const
}
}
-void pipeline::set_center() { b.set(f_center, true); }
+void pipeline::set_center(bool x) { b.set(f_center, x); }
void pipeline::set_held_center(bool value)
{
@@ -664,3 +683,7 @@ bits::bits() : b(0u)
}
} // ns pipeline_impl
+
+#if defined __llvm__
+# pragma clang diagnostic pop
+#endif
diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp
index d8129ebb..1cae6db4 100644
--- a/logic/pipeline.hpp
+++ b/logic/pipeline.hpp
@@ -124,7 +124,7 @@ class OTR_LOGIC_EXPORT pipeline : private QThread
void logic();
void run() override;
bool maybe_enable_center_on_tracking_started();
- void maybe_set_center_pose(const Pose& value, bool own_center_logic);
+ void set_center_pose(const Pose& value, bool own_center_logic);
void store_tracker_pose(const Pose& value);
Pose clamp_value(Pose value) const;
Pose apply_center(Pose value) const;
@@ -133,6 +133,8 @@ class OTR_LOGIC_EXPORT pipeline : private QThread
Pose apply_reltrans(Pose value, vec6_bool disabled, bool centerp);
Pose apply_zero_pos(Pose value) const;
+ void set_center(bool x);
+
bits b;
public:
@@ -145,7 +147,6 @@ public:
void toggle_zero();
void toggle_enabled();
- void set_center();
void set_held_center(bool value);
void set_enabled(bool value);
void set_zero(bool value);
diff --git a/logic/shortcuts.h b/logic/shortcuts.h
index dc62ba63..87926f66 100644
--- a/logic/shortcuts.h
+++ b/logic/shortcuts.h
@@ -58,8 +58,8 @@ public:
KeybindingWorker::Token key_token {[this](const Key& k) { receiver(k); }};
#endif
- Shortcuts() {}
- ~Shortcuts();
+ Shortcuts() = default;
+ ~Shortcuts() override;
void reload(const t_keys& keys_);
private:
diff --git a/logic/work.cpp b/logic/work.cpp
index c70864ae..da61b348 100644
--- a/logic/work.cpp
+++ b/logic/work.cpp
@@ -64,29 +64,7 @@ std::unique_ptr<TrackLogger> Work::make_logger(main_settings &s)
Work::Work(Mappings& m, event_handler& ev, QFrame* frame,
const dylibptr& tracker_, const dylibptr& filter_, const dylibptr& proto_) :
libs(frame, tracker_, filter_, proto_),
- logger{make_logger(s)},
- pipeline_{ m, libs, ev, *logger },
- keys {
-#if defined OTR_HAS_KEY_UP_SUPPORT
- key_tuple(s.key_center1, [&](bool x) { pipeline_.set_center(); pipeline_.set_held_center(x); }, false),
- key_tuple(s.key_center2, [&](bool x) { pipeline_.set_center(); pipeline_.set_held_center(x); }, false),
-#else
- key_tuple(s.key_center1, [&](bool) { pipeline_.set_center(); }, true),
- key_tuple(s.key_center2, [&](bool) { pipeline_.set_center(); }, true),
-#endif
-
- key_tuple(s.key_toggle1, [&](bool) { pipeline_.toggle_enabled(); }, true),
- key_tuple(s.key_toggle2, [&](bool) { pipeline_.toggle_enabled(); }, true),
-
- key_tuple(s.key_zero1, [&](bool) { pipeline_.toggle_zero(); }, true),
- key_tuple(s.key_zero2, [&](bool) { pipeline_.toggle_zero(); }, true),
-
- key_tuple(s.key_toggle_press1, [&](bool x) { pipeline_.set_enabled(!x); }, false),
- key_tuple(s.key_toggle_press2, [&](bool x) { pipeline_.set_enabled(!x); }, false),
-
- key_tuple(s.key_zero_press1, [&](bool x) { pipeline_.set_zero(x); }, false),
- key_tuple(s.key_zero_press2, [&](bool x) { pipeline_.set_zero(x); }, false),
- }
+ pipeline_{ m, libs, ev, *logger }
{
if (!is_ok())
return;
diff --git a/logic/work.hpp b/logic/work.hpp
index 212bb15d..8177e654 100644
--- a/logic/work.hpp
+++ b/logic/work.hpp
@@ -37,12 +37,27 @@ class OTR_LOGIC_EXPORT Work final : public TR
public:
using fn_t = std::function<void(bool)>;
using key_tuple = std::tuple<key_opts&, fn_t, bool>;
- main_settings s; // tracker needs settings, so settings must come before it
+ main_settings s; // pipeline needs settings, so settings must come before it
runtime_libraries libs; // idem
- std::unique_ptr<TrackLogger> logger; // must come before tracker, since tracker depends on it
+ std::unique_ptr<TrackLogger> logger { make_logger(s) }; // must come before pipeline, since pipeline depends on it
pipeline pipeline_;
Shortcuts sc;
- std::vector<key_tuple> keys;
+
+ std::vector<key_tuple> keys {
+ // third argument means "keydown only"
+ key_tuple(s.key_center1, [&](bool x) { pipeline_.set_held_center(x); }, false),
+ key_tuple(s.key_center2, [&](bool x) { pipeline_.set_held_center(x); }, false),
+
+ key_tuple(s.key_toggle1, [&](bool) { pipeline_.toggle_enabled(); }, true),
+ key_tuple(s.key_toggle2, [&](bool) { pipeline_.toggle_enabled(); }, true),
+ key_tuple(s.key_toggle_press1, [&](bool x) { pipeline_.set_enabled(!x); }, false),
+ key_tuple(s.key_toggle_press2, [&](bool x) { pipeline_.set_enabled(!x); }, false),
+
+ key_tuple(s.key_zero1, [&](bool) { pipeline_.toggle_zero(); }, true),
+ key_tuple(s.key_zero2, [&](bool) { pipeline_.toggle_zero(); }, true),
+ key_tuple(s.key_zero_press1, [&](bool x) { pipeline_.set_zero(x); }, false),
+ key_tuple(s.key_zero_press2, [&](bool x) { pipeline_.set_zero(x); }, false),
+ };
Work(Mappings& m, event_handler& ev, QFrame* frame,
const dylibptr& tracker, const dylibptr& filter, const dylibptr& proto);