diff options
-rw-r--r-- | gui/options-dialog.cpp | 3 | ||||
-rw-r--r-- | gui/options-dialog.ui | 154 | ||||
-rw-r--r-- | logic/main-settings.hpp | 2 | ||||
-rw-r--r-- | logic/tracker.cpp | 24 | ||||
-rw-r--r-- | logic/tracker.h | 73 | ||||
-rw-r--r-- | logic/work.cpp | 5 |
6 files changed, 169 insertions, 92 deletions
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp index 3c3012b5..dfd99e7b 100644 --- a/gui/options-dialog.cpp +++ b/gui/options-dialog.cpp @@ -92,7 +92,8 @@ OptionsDialog::OptionsDialog(std::function<void(bool)> pause_keybindings) : { main.key_start_tracking, ui.start_tracking_text, ui.bind_start }, { main.key_stop_tracking, ui.stop_tracking_text , ui.bind_stop}, { main.key_toggle_tracking, ui.toggle_tracking_text, ui.bind_toggle_tracking }, - { main.key_restart_tracking, ui.restart_tracking_text, ui.bind_restart_tracking } + { main.key_restart_tracking, ui.restart_tracking_text, ui.bind_restart_tracking }, + { main.key_disable_tcomp_press, ui.tcomp_off_held_text, ui.bind_tcomp_off_held }, }; for (const tmp& val_ : tuples) diff --git a/gui/options-dialog.ui b/gui/options-dialog.ui index aa06b407..97ccffff 100644 --- a/gui/options-dialog.ui +++ b/gui/options-dialog.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>468</width> + <width>546</width> <height>622</height> </rect> </property> @@ -68,23 +68,61 @@ <string notr="true">QGroupBox { border: 0; }</string> </property> <layout class="QGridLayout" name="gridLayout_8"> - <item row="11" column="2"> - <widget class="QPushButton" name="bind_toggle_tracking"> + <property name="horizontalSpacing"> + <number>20</number> + </property> + <item row="8" column="1"> + <widget class="QLabel" name="zero_held_text"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="6" column="2"> + <widget class="QPushButton" name="bind_toggle_held"> <property name="text"> <string>Bind</string> </property> </widget> </item> - <item row="11" column="0"> - <widget class="QLabel" name="textLabel2_9"> + <item row="8" column="2"> + <widget class="QPushButton" name="bind_zero_held"> <property name="text"> - <string>Toggle tracking</string> + <string>Bind</string> + </property> + </widget> + </item> + <item row="12" column="0"> + <widget class="QLabel" name="textLabel2_10"> + <property name="text"> + <string>Restart tracking</string> </property> <property name="wordWrap"> <bool>false</bool> </property> </widget> </item> + <item row="6" column="1"> + <widget class="QLabel" name="toggle_held_text"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="12" column="1"> + <widget class="QLabel" name="restart_tracking_text"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="12" column="2"> + <widget class="QPushButton" name="bind_restart_tracking"> + <property name="text"> + <string>Bind</string> + </property> + </widget> + </item> <item row="6" column="0"> <widget class="QLabel" name="label_27"> <property name="text"> @@ -92,17 +130,20 @@ </property> </widget> </item> - <item row="9" column="1"> - <widget class="QLabel" name="start_tracking_text"> + <item row="11" column="2"> + <widget class="QPushButton" name="bind_toggle_tracking"> <property name="text"> - <string/> + <string>Bind</string> </property> </widget> </item> - <item row="9" column="2"> - <widget class="QPushButton" name="bind_start"> + <item row="11" column="0"> + <widget class="QLabel" name="textLabel2_9"> <property name="text"> - <string>Bind</string> + <string>Toggle tracking</string> + </property> + <property name="wordWrap"> + <bool>false</bool> </property> </widget> </item> @@ -113,6 +154,20 @@ </property> </widget> </item> + <item row="9" column="2"> + <widget class="QPushButton" name="bind_start"> + <property name="text"> + <string>Bind</string> + </property> + </widget> + </item> + <item row="9" column="1"> + <widget class="QLabel" name="start_tracking_text"> + <property name="text"> + <string/> + </property> + </widget> + </item> <item row="10" column="1"> <widget class="QLabel" name="stop_tracking_text"> <property name="text"> @@ -144,6 +199,13 @@ </property> </widget> </item> + <item row="0" column="1"> + <widget class="QLabel" name="center_text"> + <property name="text"> + <string/> + </property> + </widget> + </item> <item row="10" column="0"> <widget class="QLabel" name="textLabel2_8"> <property name="text"> @@ -154,13 +216,6 @@ </property> </widget> </item> - <item row="0" column="1"> - <widget class="QLabel" name="center_text"> - <property name="text"> - <string/> - </property> - </widget> - </item> <item row="0" column="0"> <widget class="QLabel" name="textLabel2_3"> <property name="text"> @@ -178,13 +233,6 @@ </property> </widget> </item> - <item row="5" column="1"> - <widget class="QLabel" name="toggle_text"> - <property name="text"> - <string/> - </property> - </widget> - </item> <item row="7" column="0"> <widget class="QLabel" name="textLabel2_6"> <property name="text"> @@ -195,6 +243,13 @@ </property> </widget> </item> + <item row="5" column="1"> + <widget class="QLabel" name="toggle_text"> + <property name="text"> + <string/> + </property> + </widget> + </item> <item row="8" column="0"> <widget class="QLabel" name="label_28"> <property name="text"> @@ -226,53 +281,22 @@ </property> </widget> </item> - <item row="6" column="2"> - <widget class="QPushButton" name="bind_toggle_held"> - <property name="text"> - <string>Bind</string> - </property> - </widget> - </item> - <item row="8" column="1"> - <widget class="QLabel" name="zero_held_text"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="8" column="2"> - <widget class="QPushButton" name="bind_zero_held"> + <item row="13" column="0"> + <widget class="QLabel" name="label_30"> <property name="text"> - <string>Bind</string> + <string>Translation compensation off while held</string> </property> </widget> </item> - <item row="6" column="1"> - <widget class="QLabel" name="toggle_held_text"> + <item row="13" column="1"> + <widget class="QLabel" name="tcomp_off_held_text"> <property name="text"> <string/> </property> </widget> </item> - <item row="12" column="0"> - <widget class="QLabel" name="textLabel2_10"> - <property name="text"> - <string>Restart tracking</string> - </property> - <property name="wordWrap"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="12" column="1"> - <widget class="QLabel" name="restart_tracking_text"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="12" column="2"> - <widget class="QPushButton" name="bind_restart_tracking"> + <item row="13" column="2"> + <widget class="QPushButton" name="bind_tcomp_off_held"> <property name="text"> <string>Bind</string> </property> @@ -1383,6 +1407,7 @@ It won't work properly with translation compensation enabled.</string> <tabstop>bind_stop</tabstop> <tabstop>bind_toggle_tracking</tabstop> <tabstop>bind_restart_tracking</tabstop> + <tabstop>bind_tcomp_off_held</tabstop> <tabstop>center_at_startup</tabstop> <tabstop>trayp</tabstop> <tabstop>camera_yaw</tabstop> @@ -1412,7 +1437,6 @@ It won't work properly with translation compensation enabled.</string> <tabstop>invert_z</tabstop> <tabstop>tracklogging_enabled</tabstop> <tabstop>tracklogging_fileselectbtn</tabstop> - <tabstop>tracklogging_filenameedit</tabstop> </tabstops> <resources/> <connections/> diff --git a/logic/main-settings.hpp b/logic/main-settings.hpp index 0922ed37..04a5c6fd 100644 --- a/logic/main-settings.hpp +++ b/logic/main-settings.hpp @@ -76,6 +76,7 @@ struct main_settings key_opts key_start_tracking, key_stop_tracking, key_toggle_tracking, key_restart_tracking; key_opts key_center, key_toggle, key_zero; key_opts key_toggle_press, key_zero_press; + key_opts key_disable_tcomp_press; value<bool> tracklogging_enabled; value<QString> tracklogging_filename; main_settings() : @@ -105,6 +106,7 @@ struct main_settings key_zero(b, "zero"), key_toggle_press(b, "toggle-press"), key_zero_press(b, "zero-press"), + key_disable_tcomp_press(b, "disable-translation-compensation-while-held"), tracklogging_enabled(b, "tracklogging-enabled", false), tracklogging_filename(b, "tracklogging-filename", QString()) { diff --git a/logic/tracker.cpp b/logic/tracker.cpp index c5db5239..3a8df56e 100644 --- a/logic/tracker.cpp +++ b/logic/tracker.cpp @@ -15,6 +15,7 @@ #include "compat/sleep.hpp" #include "tracker.h" + #include <cmath> #include <algorithm> #include <cstdio> @@ -26,17 +27,14 @@ Tracker::Tracker(Mappings &m, SelectedLibraries &libs, TrackLogger &logger) : m(m), libs(libs), - logger(logger), - centerp(s.center_at_startup), - enabledp(true), - zero_(false), - should_quit(false) + logger(logger) { + set(f_center, s.center_at_startup); } Tracker::~Tracker() { - should_quit = true; + set(f_should_quit, true); wait(); } @@ -58,7 +56,7 @@ double Tracker::map(double pos, Map& axis) axis.spline_main.setTrackingActive( !altp ); axis.spline_alt.setTrackingActive( altp ); auto& fc = altp ? axis.spline_alt : axis.spline_main; - return fc.getValue(pos); + return double(fc.getValue(pos)); } void Tracker::t_compensate(const rmat& rmat, const euler_t& xyz_, euler_t& output, bool rz) @@ -146,7 +144,7 @@ void Tracker::logic() { bool can_center = false; - if (centerp && !nanp) + if (get(f_center) && !nanp) { using std::fabs; @@ -160,7 +158,7 @@ void Tracker::logic() if (can_center) { - centerp = false; + set(f_center, false); if (libs.pFilter) libs.pFilter->center(); @@ -264,7 +262,7 @@ void Tracker::logic() for (int i = 0; i < 6; i++) value(i) += m(i).opts.zero; - if (zero_) + if (get(f_zero)) for (int i = 0; i < 6; i++) value(i) = 0; @@ -272,7 +270,7 @@ void Tracker::logic() nanp = true; } - if (s.tcomp_p) + if (s.tcomp_p && !get(f_tcomp_disabled)) { euler_t value_(value(TX), value(TY), value(TZ)); t_compensate(euler_to_rmat(euler_t(value(Yaw) * d2r, value(Pitch) * d2r, value(Roll) * d2r)), @@ -343,12 +341,12 @@ void Tracker::run() t.start(); logger.reset_dt(); - while (!should_quit) + while (!get(f_should_quit)) { Pose tmp; libs.pTracker->data(tmp); - if (enabledp) + if (get(f_enabled)) for (int i = 0; i < 6; i++) newpose[i] = elide_nan(tmp(i), newpose(i)); diff --git a/logic/tracker.h b/logic/tracker.h index 873e0936..9c100ea7 100644 --- a/logic/tracker.h +++ b/logic/tracker.h @@ -25,11 +25,63 @@ #include <QMutex> #include <QThread> +#include <atomic> + #include "export.hpp" using Pose = Mat<double, 6, 1>; -class OPENTRACK_LOGIC_EXPORT Tracker : private QThread +struct bits +{ + enum flags { + f_center = 1 << 0, + f_enabled = 1 << 1, + f_zero = 1 << 2, + f_tcomp_disabled = 1 << 3, + f_should_quit = 1 << 4, + }; + + std::atomic<unsigned> b; + + void set(flags flag_, bool val_) + { + unsigned b_(b); + const unsigned flag = unsigned(flag_); + const unsigned val = unsigned(!!val_); + while (!b.compare_exchange_weak(b_, + unsigned((b_ & ~flag) | (flag * val)), + std::memory_order_seq_cst, + std::memory_order_seq_cst)) + { /* empty */ } + } + + void negate(flags flag_) + { + unsigned b_(b); + const unsigned flag = unsigned(flag_); + while (!b.compare_exchange_weak(b_, + (b_ & ~flag) | (flag & ~b_), + std::memory_order_seq_cst, + std::memory_order_seq_cst)) + { /* empty */ } + } + + bool get(flags flag) + { + return !!(b & flag); + } + + bits() : b(0u) + { + set(f_center, true); + set(f_enabled, true); + set(f_zero, false); + set(f_tcomp_disabled, false); + set(f_should_quit, false); + } +}; + +class OPENTRACK_LOGIC_EXPORT Tracker : private QThread, private bits { Q_OBJECT private: @@ -64,11 +116,6 @@ private: state real_rotation, scaled_rotation; euler_t t_center; - volatile bool centerp; - volatile bool enabledp; - volatile bool zero_; - volatile bool should_quit; - double map(double pos, Map& axis); void logic(); void t_compensate(const rmat& rmat, const euler_t& ypr, euler_t& output, bool rz); @@ -88,9 +135,13 @@ public: rmat get_camera_offset_matrix(double c); void get_raw_and_mapped_poses(double* mapped, double* raw) const; void start() { QThread::start(); } - void toggle_enabled() { enabledp = !enabledp; } - void set_toggle(bool value) { enabledp = value; } - void set_zero(bool value) { zero_ = value; } - void center() { centerp = !centerp; } - void zero() { zero_ = !zero_; } + + void center() { set(f_center, true); } + + void set_toggle(bool value) { set(f_enabled, value); } + void set_zero(bool value) { set(f_zero, value); } + void set_tcomp_disabled(bool x) { set(f_tcomp_disabled, x); } + + void zero() { negate(f_zero); } + void toggle_enabled() { negate(f_enabled); } }; diff --git a/logic/work.cpp b/logic/work.cpp index 8d00270b..c369921c 100644 --- a/logic/work.cpp +++ b/logic/work.cpp @@ -53,7 +53,8 @@ Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) : key_tuple(s.key_zero, [&](bool) -> void { tracker->zero(); }, true), key_tuple(s.key_toggle_press, [&](bool x) -> void { tracker->set_toggle(!x); }, false), key_tuple(s.key_zero_press, [&](bool x) -> void { tracker->set_zero(x); }, false), - } + key_tuple(s.key_disable_tcomp_press, [&](bool x) { tracker->set_tcomp_disabled(x); }, false), + } { reload_shortcuts(); tracker->start(); @@ -66,8 +67,8 @@ void Work::reload_shortcuts() Work::~Work() { - sc = nullptr; // order matters, otherwise use-after-free -sh + sc = nullptr; tracker = nullptr; libs = SelectedLibraries(); } |