diff options
Diffstat (limited to 'logic')
-rw-r--r-- | logic/extensions.cpp | 2 | ||||
-rw-r--r-- | logic/main-settings.cpp | 59 | ||||
-rw-r--r-- | logic/main-settings.hpp | 77 | ||||
-rw-r--r-- | logic/pipeline.cpp | 175 | ||||
-rw-r--r-- | logic/pipeline.hpp | 26 | ||||
-rw-r--r-- | logic/runtime-libraries.cpp | 26 | ||||
-rw-r--r-- | logic/runtime-libraries.hpp | 4 | ||||
-rw-r--r-- | logic/state.cpp | 45 | ||||
-rw-r--r-- | logic/state.hpp | 22 | ||||
-rw-r--r-- | logic/tracklogger.cpp | 2 | ||||
-rw-r--r-- | logic/tracklogger.hpp | 2 | ||||
-rw-r--r-- | logic/win32-shortcuts.cpp | 24 | ||||
-rw-r--r-- | logic/work.cpp | 2 |
13 files changed, 219 insertions, 247 deletions
diff --git a/logic/extensions.cpp b/logic/extensions.cpp index 438f6dde..1c855923 100644 --- a/logic/extensions.cpp +++ b/logic/extensions.cpp @@ -39,7 +39,7 @@ event_handler::event_handler(Modules::dylib_list const& extensions) : ext_bundle { std::shared_ptr<IExtension> ext(reinterpret_cast<IExtension*>(lib->Constructor())); std::shared_ptr<IExtensionDialog> dlg(reinterpret_cast<IExtensionDialog*>(lib->Dialog())); - std::shared_ptr<Metadata_> m(reinterpret_cast<Metadata_*>(lib->Meta())); + std::shared_ptr<Metadata_> m(lib->Meta()); const ext_mask mask = ext->hook_types(); diff --git a/logic/main-settings.cpp b/logic/main-settings.cpp index 2bf0ad1f..3865e602 100644 --- a/logic/main-settings.cpp +++ b/logic/main-settings.cpp @@ -4,57 +4,8 @@ namespace main_settings_impl { using namespace options; -main_settings::main_settings() : - b(make_bundle("opentrack-ui")), - b_map(make_bundle("opentrack-mappings")), - a_x("x", TX), - a_y("y", TY), - a_z("z", TZ), - a_yaw("yaw", Yaw), - a_pitch("pitch", Pitch), - a_roll("roll", Roll), - all_axis_opts { &a_x, &a_y, &a_z, &a_yaw, &a_pitch, &a_roll }, - reltrans_disable_tx(b, "compensate-translation-disable-x-axis", false), - reltrans_disable_ty(b, "compensate-translation-disable-y-axis", false), - reltrans_disable_tz(b, "compensate-translation-disable-z-axis", false), - reltrans_disable_src_yaw(b, "compensate-translation-disable-source-yaw", false), - reltrans_disable_src_pitch(b, "compensate-translation-disable-source-pitch", false), - reltrans_disable_src_roll(b, "compensate-translation-disable-source-roll", false), - tray_enabled(b, "use-system-tray", false), - tray_start(b, "start-in-tray", false), - center_at_startup(b, "center-at-startup", true), - neck_z(b, "neck-depth", 0), - neck_enable(b, "neck-enable", false), - key_start_tracking1(b, "start-tracking"), - key_start_tracking2(b, "start-tracking-alt"), - key_stop_tracking1(b, "stop-tracking"), - key_stop_tracking2(b, "stop-tracking-alt"), - key_toggle_tracking1(b, "toggle-tracking"), - key_toggle_tracking2(b, "toggle-tracking-alt"), - key_restart_tracking1(b, "restart-tracking"), - key_restart_tracking2(b, "restart-tracking-alt"), - key_center1(b, "center"), - key_center2(b, "center-alt"), - key_toggle1(b, "toggle"), - key_toggle2(b, "toggle-alt"), - key_zero1(b, "zero"), - key_zero2(b, "zero-alt"), - key_toggle_press1(b, "toggle-press"), - key_toggle_press2(b, "toggle-press-alt"), - key_zero_press1(b, "zero-press"), - key_zero_press2(b, "zero-press-alt"), - tracklogging_enabled(b, "tracklogging-enabled", false), - tracklogging_filename(b, "tracklogging-filename", QString()) -{ -} - -module_settings::module_settings() : - b(make_bundle("modules")), - tracker_dll(b, "tracker-dll", "pt"), - filter_dll(b, "filter-dll", "accela"), - protocol_dll(b, "protocol-dll", "freetrack") -{ -} +main_settings::main_settings() = default; +module_settings::module_settings() = default; key_opts::key_opts(bundle b, const QString& name) : keycode(b, QString("keycode-%1").arg(name), ""), @@ -66,9 +17,9 @@ key_opts& key_opts::operator=(const key_opts& x) { if (&x != this) { - keycode = x.keycode(); - guid = x.guid(); - button = x.button(); + keycode = x.keycode; + guid = x.guid; + button = x.button; } return *this; diff --git a/logic/main-settings.hpp b/logic/main-settings.hpp index 41edf3e6..8fef7ea7 100644 --- a/logic/main-settings.hpp +++ b/logic/main-settings.hpp @@ -37,36 +37,67 @@ struct OTR_LOGIC_EXPORT key_opts struct OTR_LOGIC_EXPORT module_settings { - bundle b; - value<QString> tracker_dll, filter_dll, protocol_dll; + bundle b { make_bundle("modules") }; + value<QString> tracker_dll { b, "tracker-dll", "pt" }; + value<QString> filter_dll { b, "filter-dll", "accela" }; + value<QString> protocol_dll { b, "protocol-dll", "freetrack" }; module_settings(); }; struct OTR_LOGIC_EXPORT main_settings final { - bundle b, b_map; - axis_opts a_x, a_y, a_z; - axis_opts a_yaw, a_pitch, a_roll; - axis_opts* all_axis_opts[6]; + bundle b { make_bundle("opentrack-ui") }; + bundle b_map { make_bundle("opentrack-mappings") }; + axis_opts a_x{ "x", TX }, a_y { "y", TY }, a_z { "z", TZ }; + axis_opts a_yaw{ "yaw", Yaw }, a_pitch { "pitch", Pitch }, a_roll { "roll", Roll }; + axis_opts* all_axis_opts[6] { &a_x, &a_y, &a_z, &a_yaw, &a_pitch, &a_roll }; value<reltrans_state> reltrans_mode { b, "relative-translation-mode", reltrans_disabled }; - value<bool> reltrans_disable_tx, reltrans_disable_ty, reltrans_disable_tz; - value<bool> reltrans_disable_src_yaw, reltrans_disable_src_pitch, reltrans_disable_src_roll; - value<bool> tray_enabled, tray_start; - value<bool> center_at_startup; + + value<bool> reltrans_disable_tx { b, "compensate-translation-disable-x-axis", false }; + value<bool> reltrans_disable_ty { b, "compensate-translation-disable-y-axis", false }; + value<bool> reltrans_disable_tz { b, "compensate-translation-disable-z-axis", false }; + + value<bool> reltrans_disable_src_yaw { b, "compensate-translation-disable-source-yaw", false }; + value<bool> reltrans_disable_src_pitch { b, "compensate-translation-disable-source-pitch", false }; + value<bool> reltrans_disable_src_roll { b, "compensate-translation-disable-source-roll", false }; + + value<bool> tray_enabled { b, "use-system-tray", false }; + value<bool> tray_start { b, "start-in-tray", false }; + + value<bool> center_at_startup { b, "center-at-startup", true }; //value<int> center_method; - value<int> neck_z; - value<bool> neck_enable; - key_opts key_start_tracking1, key_start_tracking2; - key_opts key_stop_tracking1, key_stop_tracking2; - key_opts key_toggle_tracking1, key_toggle_tracking2; - key_opts key_restart_tracking1, key_restart_tracking2; - key_opts key_center1, key_center2; - key_opts key_toggle1, key_toggle2; - key_opts key_zero1, key_zero2; - key_opts key_toggle_press1, key_toggle_press2; - key_opts key_zero_press1, key_zero_press2; - value<bool> tracklogging_enabled; - value<QString> tracklogging_filename; + value<int> neck_z { b, "neck-depth", 0 }; + value<bool> neck_enable { b, "neck-enable", false }; + + key_opts key_start_tracking1 { b, "start-tracking" }; + key_opts key_start_tracking2 { b, "start-tracking-alt" }; + + key_opts key_stop_tracking1 { b, "stop-tracking" }; + key_opts key_stop_tracking2 { b, "stop-tracking-alt" }; + + key_opts key_toggle_tracking1 { b, "toggle-tracking" }; + key_opts key_toggle_tracking2 { b, "toggle-tracking-alt" }; + + key_opts key_restart_tracking1 { b, "restart-tracking" }; + key_opts key_restart_tracking2 { b, "restart-tracking-alt" }; + + key_opts key_center1 { b, "center" }; + key_opts key_center2 { b, "center-alt" }; + + key_opts key_toggle1 { b, "toggle" }; + key_opts key_toggle2 { b, "toggle-alt" }; + + key_opts key_zero1 { b, "zero" }; + key_opts key_zero2 { b, "zero-alt" }; + + key_opts key_toggle_press1 { b, "toggle-press" }; + key_opts key_toggle_press2 { b, "toggle-press-alt" }; + + key_opts key_zero_press1 { b, "zero-press" }; + key_opts key_zero_press2 { b, "zero-press-alt" }; + + value<bool> tracklogging_enabled { b, "tracklogging-enabled", false }; + value<QString> tracklogging_filename { b, "tracklogging-filename", {} }; main_settings(); }; diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index 021a576b..bc8026ed 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -26,26 +26,18 @@ #ifdef _WIN32 # include <windows.h> -#endif - -#if defined __llvm__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wlanguage-extension-token" -# pragma clang diagnostic ignored "-Wunknown-pragmas" +# include <mmsystem.h> #endif namespace pipeline_impl { -static constexpr inline double r2d = 180 / M_PI; -static constexpr inline double d2r = M_PI / 180; - reltrans::reltrans() = default; void reltrans::on_center() { interp_pos = { 0, 0, 0 }; in_zone = false; - cur = false; + moving_to_reltans = false; } euler_t reltrans::rotate(const rmat& R, const euler_t& in, vec3_bool disable) const @@ -83,20 +75,17 @@ Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, if (state != reltrans_disabled) { - const bool in_zone_ = progn( - if (state == reltrans_non_center) - { - const bool looking_down = value(Pitch) < 20; - return looking_down ? std::fabs(value(Yaw)) > 35 : std::fabs(value(Yaw)) > 65; - } - else - return true; - ); + bool in_zone_ = true; + if (state == reltrans_non_center) + { + const bool looking_down = value(Pitch) < 20; + in_zone_ = looking_down ? std::fabs(value(Yaw)) > 35 : std::fabs(value(Yaw)) > 65; + } - if (!cur && in_zone != in_zone_) + if (!moving_to_reltans && in_zone != in_zone_) { //qDebug() << "reltrans-interp: START" << tcomp_in_zone_; - cur = true; + moving_to_reltans = true; interp_timer.start(); interp_phase_timer.start(); RC_stage = 0; @@ -107,6 +96,8 @@ Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, // only when looking behind or downward if (in_zone) { + constexpr double d2r = M_PI / 180; + const rmat R = euler_to_rmat( euler_t(value(Yaw) * d2r * !disable(Yaw), value(Pitch) * d2r * !disable(Pitch), @@ -124,12 +115,12 @@ Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, } } - if (cur) + if (moving_to_reltans) { const double dt = interp_timer.elapsed_seconds(); - static constexpr float RC_stages[] = { 2, 1, .5, .1, .05 }; - static constexpr float RC_time_deltas[] = { 1, .25, .25, 2 }; + static constexpr double RC_stages[] = { 2, 1, .5, .1, .05 }; + static constexpr double RC_time_deltas[] = { 1, .25, .25, 2 }; interp_timer.start(); @@ -156,7 +147,7 @@ Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, if (delta < eps) { //qDebug() << "reltrans-interp: STOP"; - cur = false; + moving_to_reltans = false; } } else @@ -164,7 +155,7 @@ Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, } else { - cur = false; + moving_to_reltans = false; in_zone = false; } @@ -204,7 +195,7 @@ double pipeline::map(double pos, Map& axis) axis.spline_main.set_tracking_active(!altp); axis.spline_alt.set_tracking_active(altp); auto& fc = altp ? axis.spline_alt : axis.spline_main; - return double(fc.get_value(pos)); + return fc.get_value(pos); } //#define NO_NAN_CHECK @@ -213,10 +204,10 @@ double pipeline::map(double pos, Map& axis) #ifndef NO_NAN_CHECK template<int u, int w> -static bool is_nan(const dmat<u,w>& r) +static inline bool is_nan(const dmat<u,w>& r) { - for (int i = 0; i < u; i++) - for (int j = 0; j < w; j++) + for (unsigned i = 0; i < u; i++) + for (unsigned j = 0; j < w; j++) { int val = std::fpclassify(r(i, j)); if (val == FP_NAN || val == FP_INFINITE) @@ -226,21 +217,8 @@ static bool is_nan(const dmat<u,w>& r) return false; } -template<typename x> -static inline -bool nan_check_(const x& datum) -{ - return is_nan(datum); -} - -template<typename x, typename y, typename... xs> -static inline -bool nan_check_(const x& datum, const y& next, const xs&... rest) -{ - return nan_check_(datum) || nan_check_(next, rest...); -} - -static void emit_nan_check_msg(const char* text, const char* fun, int line) +static never_inline +void emit_nan_check_msg(const char* text, const char* fun, int line) { eval_once( qDebug() << "nan check failed" @@ -251,33 +229,31 @@ static void emit_nan_check_msg(const char* text, const char* fun, int line) } template<typename... xs> -static cc_noinline +static never_inline bool maybe_nan(const char* text, const char* fun, int line, const xs&... vals) { - if (nan_check_(vals...)) - { + bool ret = (is_nan(vals) || ... || false); + + if (ret) emit_nan_check_msg(text, fun, line); - return true; - } - return false; -} -// for MSVC `else' is like `unlikely' for GNU + return ret; +} #define nan_check(...) \ do \ { \ - if (likely(!maybe_nan(#__VA_ARGS__, cc_function_name, __LINE__, __VA_ARGS__))) \ + if (likely(!maybe_nan(#__VA_ARGS__, function_name, __LINE__, __VA_ARGS__))) \ (void)0; \ else \ goto error; \ - } while (false) + } \ + while (false) #else # define nan_check(...) (void)(__VA_ARGS__) #endif - bool pipeline::maybe_enable_center_on_tracking_started() { if (!tracking_started) @@ -299,7 +275,7 @@ bool pipeline::maybe_enable_center_on_tracking_started() return false; } -void pipeline::set_center_pose(const Pose& value, bool own_center_logic) +void pipeline::maybe_set_center_pose(const Pose& value, bool own_center_logic) { if (b.get(f_center | f_held_center)) { @@ -309,26 +285,12 @@ void pipeline::set_center_pose(const Pose& value, bool own_center_logic) libs.pFilter->center(); if (own_center_logic) - { - scaled_state.inv_rot_center = rmat::eye(); - scaled_state.t_center = {}; - } + center = {}; else - { - scaled_state.inv_rot_center = scaled_state.rotation.t(); - scaled_state.t_center = (const double*)(value); - } + center = value; } } -void pipeline::store_tracker_pose(const Pose& value) -{ - // alas, this is poor man's gimbal lock "prevention" - // this is some kind of "canonical" representation, - // if we can even talk of one - scaled_state.rotation = euler_to_rmat(scale_inv_c * d2r * euler_t(&value[Yaw])); -} - Pose pipeline::clamp_value(Pose value) const { // hatire, udp, and freepie trackers can mess up here @@ -347,28 +309,14 @@ Pose pipeline::clamp_value(Pose value) const Pose pipeline::apply_center(Pose value) const { - euler_t T = euler_t(value) - scaled_state.t_center; - euler_t R = scale_c * rmat_to_euler(scaled_state.rotation * scaled_state.inv_rot_center); - - // XXX check these lines, it's been here forever - T = rel.rotate(euler_to_rmat(R), T, {}); + // this is incorrect but people like it + value = value - center; - for (int i = 0; i < 3; i++) - { + for (int i = 0; i < 6; i++) // don't invert after reltrans // inverting here doesn't break centering - - if (m(i+3).opts.invert) - R(i) = -R(i); if (m(i).opts.invert) - T(i) = -T(i); - } - - for (int i = 0; i < 3; i++) - { - value(i) = T(i); - value(i+3) = R(i) * r2d; - } + value(i) = -value(i); return value; } @@ -408,7 +356,6 @@ Pose pipeline::maybe_apply_filter(const Pose& value) const Pose pipeline::apply_zero_pos(Pose value) const { - // custom zero position for (int i = 0; i < 6; i++) value(i) += m(i).opts.zero * (m(i).opts.invert ? -1 : 1); @@ -466,11 +413,9 @@ void pipeline::logic() value = clamp_value(value); { - store_tracker_pose(value); - maybe_enable_center_on_tracking_started(); - set_center_pose(value, own_center_logic); - value = apply_center(value); + maybe_set_center_pose(value, own_center_logic); + value = clamp_value(apply_center(value)); // "corrected" - after various transformations to account for camera position logger.write_pose(value); @@ -480,10 +425,11 @@ void pipeline::logic() ev.run_events(EV::ev_before_filter, value); // we must proceed with all the filtering since the filter // needs fresh values to prevent deconvergence - Pose tmp = maybe_apply_filter(value); - nan_check(tmp); - if (!center_ordered) - value = tmp; + if (center_ordered) + (void)maybe_apply_filter(value); + else + value = maybe_apply_filter(value); + nan_check(value); logger.write_pose(value); // "filtered" } @@ -631,7 +577,7 @@ void pipeline::run() void pipeline::raw_and_mapped_pose(double* mapped, double* raw) const { - QMutexLocker foo(&const_cast<pipeline&>(*this).mtx); + QMutexLocker foo(&mtx); for (int i = 0; i < 6; i++) { @@ -655,31 +601,28 @@ void pipeline::toggle_enabled() { b.negate(f_enabled_p); } void bits::set(bit_flags flag, bool val) { - const unsigned flag_ = unsigned(flag); - const unsigned val_ = unsigned(val); - unsigned b_ = 0; + QMutexLocker l(&lock); - for (;;) - if (b.compare_exchange_weak(b_, unsigned((b_ & ~flag_) | (flag_ * val_)))) - break; + flags &= ~flag; + if (val) + flags |= flag; } void bits::negate(bit_flags flag) { - const unsigned flag_= flag; - unsigned b_ = 0; + QMutexLocker l(&lock); - for (;;) - if (b.compare_exchange_weak(b_, b_ ^ flag_)) - break; + flags ^= flag; } bool bits::get(bit_flags flag) { - return !!(b & flag); + QMutexLocker l(&lock); + + return !!(flags & flag); } -bits::bits() : b(0u) +bits::bits() { set(f_center, false); set(f_held_center, false); @@ -689,7 +632,3 @@ 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 91dfc668..545a7836 100644 --- a/logic/pipeline.hpp +++ b/logic/pipeline.hpp @@ -31,16 +31,6 @@ using namespace time_units; using vec6_bool = Mat<bool, 6, 1>; using vec3_bool = Mat<bool, 6, 1>; -static constexpr inline double scale_c = 8; -static constexpr inline double scale_inv_c = 1/scale_c; - -struct state_ -{ - rmat inv_rot_center { rmat::eye() }; - rmat rotation { rmat::eye() }; - euler_t t_center; -}; - class reltrans { euler_t interp_pos; @@ -51,7 +41,7 @@ class reltrans Timer interp_phase_timer; unsigned RC_stage = 0; - bool cur = false; + bool moving_to_reltans = false; bool in_zone = false; public: @@ -68,6 +58,7 @@ public: using namespace time_units; enum bit_flags : unsigned { + f_none = 0, f_center = 1 << 0, f_held_center = 1 << 1, f_enabled_h = 1 << 2, @@ -77,7 +68,8 @@ enum bit_flags : unsigned { struct OTR_LOGIC_EXPORT bits { - std::atomic<unsigned> b; + bit_flags flags{0}; + QMutex lock; void set(bit_flags flag, bool val); void negate(bit_flags flag); @@ -91,13 +83,13 @@ class OTR_LOGIC_EXPORT pipeline : private QThread { Q_OBJECT - QMutex mtx; + mutable QMutex mtx; main_settings s; Mappings& m; event_handler& ev; Timer t; - Pose output_pose, raw_6dof, last_mapped, last_raw; + Pose output_pose, raw_6dof; Pose newpose; runtime_libraries const& libs; @@ -108,8 +100,7 @@ class OTR_LOGIC_EXPORT pipeline : private QThread reltrans rel; - //state_ state, scaled_state; - state_ scaled_state; + Pose center; ns backlog_time {}; @@ -119,8 +110,7 @@ class OTR_LOGIC_EXPORT pipeline : private QThread void logic(); void run() override; bool maybe_enable_center_on_tracking_started(); - void set_center_pose(const Pose& value, bool own_center_logic); - void store_tracker_pose(const Pose& value); + void maybe_set_center_pose(const Pose& value, bool own_center_logic); Pose clamp_value(Pose value) const; Pose apply_center(Pose value) const; std::tuple<Pose, Pose, vec6_bool> get_selected_axis_values(const Pose& newpose) const; diff --git a/logic/runtime-libraries.cpp b/logic/runtime-libraries.cpp index b91c9635..754f52cd 100644 --- a/logic/runtime-libraries.cpp +++ b/logic/runtime-libraries.cpp @@ -3,10 +3,16 @@ #include <QMessageBox> #include <QDebug> +#ifdef __clang__ +# pragma clang diagnostic ignored "-Wcomma" +#endif + runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f) { + auto error = [](const QString& msg) { return module_status_mixin::error(msg); }; + module_status status = - module_status_mixin::error(tr("Library load failure")); + error(tr("Library load failure")); using namespace options; @@ -22,8 +28,8 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli if(status = pProtocol->initialize(), !status.is_ok()) { - status = tr("Error occurred while loading protocol %1\n\n%2\n") - .arg(p->name, status.error); + status = error(tr("Error occurred while loading protocol %1\n\n%2\n") + .arg(p->name, status.error)); goto end; } @@ -36,7 +42,7 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli goto end; } - if (f && !pFilter) + if (f && f->Constructor && !pFilter) { qDebug() << "filter load failure"; goto end; @@ -45,15 +51,15 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli if (pFilter) if(status = pFilter->initialize(), !status.is_ok()) { - status = tr("Error occurred while loading filter %1\n\n%2\n") - .arg(f->name, status.error); + status = error(tr("Error occurred while loading filter %1\n\n%2\n") + .arg(f->name, status.error)); goto end; } if (status = pTracker->start_tracker(frame), !status.is_ok()) { - status = tr("Error occurred while loading tracker %1\n\n%2\n") - .arg(t->name, status.error); + status = error(tr("Error occurred while loading tracker %1\n\n%2\n") + .arg(t->name, status.error)); goto end; } @@ -66,6 +72,8 @@ end: pProtocol = nullptr; if (!status.is_ok()) - QMessageBox::critical(nullptr, tr("Startup failure"), status.error, QMessageBox::Cancel, QMessageBox::NoButton); + QMessageBox::critical(nullptr, + tr("Startup failure"), status.error, + QMessageBox::Cancel, QMessageBox::NoButton); } diff --git a/logic/runtime-libraries.hpp b/logic/runtime-libraries.hpp index acf5bf30..8c7fedd1 100644 --- a/logic/runtime-libraries.hpp +++ b/logic/runtime-libraries.hpp @@ -12,7 +12,7 @@ #include "compat/tr.hpp" #include "export.hpp" -#include <QFrame> +class QFrame; class OTR_LOGIC_EXPORT runtime_libraries final : public TR { @@ -26,7 +26,7 @@ public: std::shared_ptr<IProtocol> pProtocol; runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f); - runtime_libraries() : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), correct(false) {} + runtime_libraries() = default; bool correct = false; }; diff --git a/logic/state.cpp b/logic/state.cpp new file mode 100644 index 00000000..afdf5b12 --- /dev/null +++ b/logic/state.cpp @@ -0,0 +1,45 @@ +#include "state.hpp" + +#include <iterator> + +using dylib_ptr = Modules::dylib_ptr; +using dylib_list = Modules::dylib_list; + +std::tuple<dylib_ptr, int> State::module_by_name(const QString& name, dylib_list& list) +{ + auto it = std::find_if(list.cbegin(), list.cend(), [&name](const dylib_ptr& lib) { + if (!lib) + return name.isEmpty(); + else + return name == lib->module_name; + }); + + if (it == list.cend()) + return { nullptr, -1 }; + else + return { *it, int(std::distance(list.cbegin(), it)) }; +} + +State::State(const QString& library_path) : + modules(library_path), + ev(modules.extensions()), + pose(s.all_axis_opts) +{} + +dylib_ptr State::current_tracker() +{ + auto [ptr, idx] = module_by_name(m.tracker_dll, modules.trackers()); + return ptr; +} + +dylib_ptr State::current_protocol() +{ + auto [ptr, idx] = module_by_name(m.protocol_dll, modules.protocols()); + return ptr; +} + +dylib_ptr State::current_filter() +{ + auto [ptr, idx] = module_by_name(m.filter_dll, modules.filters()); + return ptr; +} diff --git a/logic/state.hpp b/logic/state.hpp index c400df18..abce1daf 100644 --- a/logic/state.hpp +++ b/logic/state.hpp @@ -14,19 +14,27 @@ #include "mappings.hpp" #include "extensions.hpp" #include "work.hpp" -#include <vector> +#include "export.hpp" + +#include <memory> #include <QString> -struct State +struct OTR_LOGIC_EXPORT State { - explicit State(const QString& library_path) : - modules(library_path), - ev(modules.extensions()), - pose(s.all_axis_opts) - {} + using dylib_ptr = Modules::dylib_ptr; + using dylib_list = Modules::dylib_list; + + explicit State(const QString& library_path); + static std::tuple<dylib_ptr, int> module_by_name(const QString& name, dylib_list& list); + + dylib_ptr current_tracker(); + dylib_ptr current_protocol(); + dylib_ptr current_filter(); + Modules modules; event_handler ev; main_settings s; + module_settings m; Mappings pose; std::shared_ptr<Work> work; }; diff --git a/logic/tracklogger.cpp b/logic/tracklogger.cpp index a287b633..758c2478 100644 --- a/logic/tracklogger.cpp +++ b/logic/tracklogger.cpp @@ -3,6 +3,8 @@ #include <QMessageBox> +TrackLogger::~TrackLogger() = default; + void TrackLogger::write_pose(const double* p) { write(p, 6); diff --git a/logic/tracklogger.hpp b/logic/tracklogger.hpp index d6c34157..134a27fd 100644 --- a/logic/tracklogger.hpp +++ b/logic/tracklogger.hpp @@ -13,7 +13,7 @@ class OTR_LOGIC_EXPORT TrackLogger public: TrackLogger() = default; - virtual ~TrackLogger() = default; + virtual ~TrackLogger(); virtual void write(const char *) {} virtual void write(const double *, int) {} diff --git a/logic/win32-shortcuts.cpp b/logic/win32-shortcuts.cpp index 1e2f1b77..c2920071 100644 --- a/logic/win32-shortcuts.cpp +++ b/logic/win32-shortcuts.cpp @@ -15,6 +15,7 @@ #include <QVariant> #include <QDebug> +#if 0 win_key const windows_key_mods[] { {DIK_LCONTROL, Qt::Key_Control}, {DIK_RCONTROL, Qt::Key_Control}, @@ -25,6 +26,7 @@ win_key const windows_key_mods[] { {DIK_LWIN, Qt::Key_Super_L}, {DIK_RWIN, Qt::Key_Super_R}, }; +#endif static const win_key windows_key_sequences[] { { DIK_F1, Qt::Key_F1 }, @@ -119,7 +121,7 @@ static const win_key windows_key_sequences[] { { DIK_PAUSE, Qt::Key_Pause}, { DIK_NUMLOCK, Qt::Key_NumLock}, { DIK_CAPSLOCK, Qt::Key_CapsLock}, -#define key_mod(x, y) Qt::Key(int(x) | int((y))) +#define key_mod(x, y) Qt::Key(int((x)) | int((y))) { DIK_NUMPAD0, key_mod(Qt::Key_0, Qt::KeypadModifier)}, { DIK_NUMPAD0, key_mod(Qt::Key_0, Qt::KeypadModifier)}, { DIK_NUMPAD1, key_mod(Qt::Key_1, Qt::KeypadModifier)}, @@ -161,26 +163,22 @@ bool win_key::to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods bool win_key::from_qt(const QKeySequence& qt_, int& dik, Qt::KeyboardModifiers& mods) { // CAVEAT don't use QVariant::toUInt() or conversion fails -#if 0 - const unsigned qt = QVariant(qt_).toInt(); // verbose -#endif - const unsigned qt = int(qt_); // deprecated - const unsigned our_mods = qt & Qt::KeyboardModifierMask; + const unsigned qt = (unsigned)QVariant(qt_).toInt(); + const unsigned our_mods = qt & (unsigned)Qt::KeyboardModifierMask; if (qt == 0) return false; + for (const win_key& wk : windows_key_sequences) { - for (const win_key& wk : windows_key_sequences) + if (unsigned(wk.qt) == qt) { - if (unsigned(wk.qt) == qt) - { - dik = wk.win; - mods = Qt::NoModifier; - return true; - } + dik = wk.win; + mods = Qt::NoModifier; + return true; } } + { const unsigned key = qt & ~Qt::KeyboardModifierMask; for (const win_key& wk : windows_key_sequences) diff --git a/logic/work.cpp b/logic/work.cpp index da61b348..e0c13ac8 100644 --- a/logic/work.cpp +++ b/logic/work.cpp @@ -53,7 +53,7 @@ std::unique_ptr<TrackLogger> Work::make_logger(main_settings &s) QMessageBox::Ok, QMessageBox::NoButton); } else - return logger; + return std::move(logger); } } |