diff options
Diffstat (limited to 'logic')
-rw-r--r-- | logic/extensions.cpp | 26 | ||||
-rw-r--r-- | logic/extensions.hpp | 15 | ||||
-rw-r--r-- | logic/state.hpp | 3 | ||||
-rw-r--r-- | logic/tracker.cpp | 13 | ||||
-rw-r--r-- | logic/tracker.h | 6 | ||||
-rw-r--r-- | logic/work.cpp | 5 | ||||
-rw-r--r-- | logic/work.hpp | 2 |
7 files changed, 44 insertions, 26 deletions
diff --git a/logic/extensions.cpp b/logic/extensions.cpp index c8a6a73b..11c94aef 100644 --- a/logic/extensions.cpp +++ b/logic/extensions.cpp @@ -16,24 +16,24 @@ static constexpr struct event_type_mapping ext_ord idx; } ordinal_to_function[] = { { &IExtension::process_raw, ext_mask::on_raw, ext_ord::ev_raw, }, - { &IExtension::process_after_center, ext_mask::on_after_center, ext_ord::ev_after_center, }, { &IExtension::process_before_filter, ext_mask::on_before_filter, ext_ord::ev_before_filter, }, - { &IExtension::process_before_transform, ext_mask::on_before_transform, ext_ord::ev_before_transform, }, { &IExtension::process_before_mapping, ext_mask::on_before_mapping, ext_ord::ev_before_mapping, }, { &IExtension::process_finished, ext_mask::on_finished, ext_ord::ev_finished, }, }; -bool ext_settings::is_enabled(const QString& name) +bool event_handler::is_enabled(const QString& name) { - static const bundle b = make_bundle("extensions"); - - if (!b->contains(name)) +#if 1 + return true; +#else + if (!ext_bundle->contains(name)) return false; - return b->get<bool>(name); + return ext_bundle->get<bool>(name); +#endif } -event_handler::event_handler(Modules::dylib_list const& extensions) +event_handler::event_handler(Modules::dylib_list const& extensions) : ext_bundle(make_bundle("extensions")) { for (std::shared_ptr<dylib> const& lib : extensions) { @@ -43,16 +43,20 @@ event_handler::event_handler(Modules::dylib_list const& extensions) const ext_mask mask = ext->hook_types(); - if (!ext_settings::is_enabled(lib->module_name)) + if (!is_enabled(lib->module_name)) continue; +#if 1 + qDebug() << "extension" << lib->module_name << "mask" << (void*)mask; +#endif + for (event_type_mapping const& mapping : ordinal_to_function) { const unsigned i = mapping.idx; const ext_mask mask_ = mapping.mask; if (mask & mask_) - extension_events[i].push_back({ ext, dlg, m }); + extensions_for_event[i].push_back({ ext, dlg, m }); } } } @@ -61,7 +65,7 @@ void event_handler::run_events(event_ordinal k, Pose& pose) { auto fun = std::mem_fn(ordinal_to_function[k].ptr); - for (extension& x : extension_events[k]) + for (extension& x : extensions_for_event[k]) fun(*x.logic, pose); } diff --git a/logic/extensions.hpp b/logic/extensions.hpp index 8cb4a989..1c1cf39d 100644 --- a/logic/extensions.hpp +++ b/logic/extensions.hpp @@ -6,7 +6,9 @@ #include <vector> #include <array> -struct event_handler final +#include "export.hpp" + +struct OTR_LOGIC_EXPORT event_handler final { using event_ordinal = IExtension::event_ordinal; @@ -26,11 +28,10 @@ struct event_handler final private: using ext_list = std::vector<extension>; - std::array<ext_list, IExtension::event_count> extension_events; -}; + std::array<ext_list, IExtension::event_count> extensions_for_event; -struct ext_settings final -{ - static bool is_enabled(const QString& name); - ext_settings() = delete; + options::bundle ext_bundle; + + bool is_enabled(const QString& name); }; + diff --git a/logic/state.hpp b/logic/state.hpp index 8bef71ad..589de5ff 100644 --- a/logic/state.hpp +++ b/logic/state.hpp @@ -13,6 +13,7 @@ using namespace options; #include "api/plugin-support.hpp" #include "main-settings.hpp" #include "mappings.hpp" +#include "extensions.hpp" #include "work.hpp" #include <vector> #include <QString> @@ -21,9 +22,11 @@ struct State { State(const QString& library_path) : modules(library_path), + ev(modules.extensions()), pose(std::vector<axis_opts*>{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll}) {} Modules modules; + event_handler ev; main_settings s; Mappings pose; std::shared_ptr<Work> work; diff --git a/logic/tracker.cpp b/logic/tracker.cpp index 798b2cac..d979b0b2 100644 --- a/logic/tracker.cpp +++ b/logic/tracker.cpp @@ -33,8 +33,9 @@ using namespace time_units; constexpr double Tracker::r2d; constexpr double Tracker::d2r; -Tracker::Tracker(Mappings& m, runtime_libraries& libs, TrackLogger& logger) : +Tracker::Tracker(Mappings& m, runtime_libraries& libs, event_handler& ev, TrackLogger& logger) : m(m), + ev(ev), libs(libs), logger(logger), backlog_time(ns(0)), @@ -110,6 +111,7 @@ constexpr double Tracker::c_div; void Tracker::logic() { using namespace euler; + using EV = event_handler::event_ordinal; logger.write_dt(); logger.reset_dt(); @@ -121,10 +123,11 @@ void Tracker::logic() { Pose tmp; libs.pTracker->data(tmp); + ev.run_events(EV::ev_raw, tmp); if (get(f_enabled_p) ^ !get(f_enabled_h)) for (int i = 0; i < 6; i++) - newpose[i] = elide_nan(tmp(i), newpose(i)); + newpose(i) = elide_nan(tmp(i), newpose(i)); } Pose value, raw; @@ -249,6 +252,8 @@ void Tracker::logic() } } + ev.run_events(EV::ev_before_filter, value); + logger.write_pose(value); // "corrected" - after various transformations to account for camera position nanp |= is_nan(value); @@ -268,6 +273,8 @@ void Tracker::logic() nanp |= is_nan(value); { + ev.run_events(EV::ev_before_mapping, value); + euler_t neck, rel; if (s.neck_enable) @@ -347,6 +354,8 @@ void Tracker::logic() for (int i = 0; i < 6; i++) value(i) += m(i).opts.zero * (m(i).opts.invert ? -1 : 1); + ev.run_events(EV::ev_finished, value); + if (!nanp) libs.pProtocol->pose(value); diff --git a/logic/tracker.h b/logic/tracker.h index afd57112..e7b4a76d 100644 --- a/logic/tracker.h +++ b/logic/tracker.h @@ -15,6 +15,7 @@ #include "mappings.hpp" #include "compat/euler.hpp" #include "runtime-libraries.hpp" +#include "extensions.hpp" #include "spline/spline.hpp" #include "main-settings.hpp" @@ -31,7 +32,7 @@ namespace gui_tracker_impl { -struct bits +struct OTR_LOGIC_EXPORT bits { enum flags : unsigned { f_center = 1 << 0, @@ -58,6 +59,7 @@ private: QMutex mtx; main_settings s; Mappings& m; + event_handler& ev; Timer t; Pose output_pose, raw_6dof, last_mapped, last_raw; @@ -98,7 +100,7 @@ private: static constexpr double c_mult = 16; static constexpr double c_div = 1./c_mult; public: - Tracker(Mappings& m, runtime_libraries& libs, TrackLogger& logger); + Tracker(Mappings& m, runtime_libraries& libs, event_handler& ev, TrackLogger& logger); ~Tracker(); void raw_and_mapped_pose(double* mapped, double* raw) const; diff --git a/logic/work.cpp b/logic/work.cpp index 62c15403..1b1b87fa 100644 --- a/logic/work.cpp +++ b/logic/work.cpp @@ -5,7 +5,6 @@ #include <QMessageBox> #include <QFileDialog> - QString Work::browse_datalogging_file(main_settings &s) { QString filename = s.tracklogging_filename; @@ -60,10 +59,10 @@ std::shared_ptr<TrackLogger> Work::make_logger(main_settings &s) } -Work::Work(Mappings& m, QFrame* frame, std::shared_ptr<dylib> tracker_, std::shared_ptr<dylib> filter_, std::shared_ptr<dylib> proto_) : +Work::Work(Mappings& m, event_handler& ev, QFrame* frame, std::shared_ptr<dylib> tracker_, std::shared_ptr<dylib> filter_, std::shared_ptr<dylib> proto_) : libs(frame, tracker_, filter_, proto_), logger(make_logger(s)), - tracker(std::make_shared<Tracker>(m, libs, *logger)), + tracker(std::make_shared<Tracker>(m, libs, ev, *logger)), sc(std::make_shared<Shortcuts>()), keys { key_tuple(s.key_center1, [&](bool) -> void { tracker->center(); }, true), diff --git a/logic/work.hpp b/logic/work.hpp index 1aff5260..1f7551a0 100644 --- a/logic/work.hpp +++ b/logic/work.hpp @@ -35,7 +35,7 @@ struct OTR_LOGIC_EXPORT Work std::shared_ptr<Shortcuts> sc; std::vector<key_tuple> keys; - Work(Mappings& m, QFrame* frame, std::shared_ptr<dylib> tracker, std::shared_ptr<dylib> filter, std::shared_ptr<dylib> proto); + Work(Mappings& m, event_handler& ev, QFrame* frame, std::shared_ptr<dylib> tracker, std::shared_ptr<dylib> filter, std::shared_ptr<dylib> proto); ~Work(); void reload_shortcuts(); bool is_ok() const; |