From eca907d3c1240d04bbcfdf84a3a726353e56bc64 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 25 Sep 2017 16:24:58 +0200 Subject: api, logic: support "extensions" for pose transform --- CMakeLists.txt | 1 + api/plugin-api.hpp | 2 ++ api/plugin-support.hpp | 18 +++++++++++++++--- logic/selected-libraries.cpp | 30 ++++++++++++++++++++++++++++++ logic/selected-libraries.hpp | 22 ++++++++++++++++++++-- logic/tracker.h | 2 -- 6 files changed, 68 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5e45c64..6d478ea3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ file(GLOB opentrack-subprojects "tracker-*/${C}" "proto-*/${C}" "filter-*/${C}" + "ext-*/${C}" "options/${C}" "api/${C}" "compat/${C}" diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp index 3d66d5c1..1e7822c2 100644 --- a/api/plugin-api.hpp +++ b/api/plugin-api.hpp @@ -17,6 +17,8 @@ #include "export.hpp" +using Pose = Mat; + enum Axis { TX, TY, TZ, Yaw, Pitch, Roll, }; diff --git a/api/plugin-support.hpp b/api/plugin-support.hpp index b9d2d503..9df11169 100644 --- a/api/plugin-support.hpp +++ b/api/plugin-support.hpp @@ -40,7 +40,14 @@ extern "C" typedef Metadata* (*OPENTRACK_METADATA_FUNPTR)(void); struct dylib final { - enum Type : unsigned { Filter = 0xdeadbabeu, Tracker = 0xcafebeefu, Protocol = 0xdeadf00du, Invalid = 0xcafebabeu }; + enum Type : unsigned + { + Filter = 0xdeadbabeu, + Tracker = 0xcafebeefu, + Protocol = 0xdeadf00du, + Extension = 0xdeadf001u, + Invalid = 0xcafebabeu, + }; dylib(const QString& filename_, Type t) : type(Invalid), @@ -93,6 +100,7 @@ struct dylib final { Filter, QStringLiteral(OPENTRACK_SOLIB_PREFIX "opentrack-filter-*." OPENTRACK_SOLIB_EXT), }, { Tracker, QStringLiteral(OPENTRACK_SOLIB_PREFIX "opentrack-tracker-*." OPENTRACK_SOLIB_EXT), }, { Protocol, QStringLiteral(OPENTRACK_SOLIB_PREFIX "opentrack-proto-*." OPENTRACK_SOLIB_EXT), }, + { Extension, QStringLiteral(OPENTRACK_SOLIB_PREFIX "opentrack-ext-*." OPENTRACK_SOLIB_EXT), }, }; for (const filter_& filter : filters) @@ -158,6 +166,7 @@ private: "opentrack-tracker-", "opentrack-proto-", "opentrack-filter-", + "opentrack-ext-", }; for (auto name : names) @@ -167,7 +176,7 @@ private: } } } - return QStringLiteral(""); + return QString(); } bool check(bool fail) @@ -199,16 +208,19 @@ struct Modules final module_list(dylib::enum_libraries(library_path)), filter_modules(filter(dylib::Filter)), tracker_modules(filter(dylib::Tracker)), - protocol_modules(filter(dylib::Protocol)) + protocol_modules(filter(dylib::Protocol)), + extension_modules(filter(dylib::Extension)) {} dylib_list& filters() { return filter_modules; } dylib_list& trackers() { return tracker_modules; } dylib_list& protocols() { return protocol_modules; } + dylib_list& extensions() { return extension_modules; } private: dylib_list module_list; dylib_list filter_modules; dylib_list tracker_modules; dylib_list protocol_modules; + dylib_list extension_modules; static dylib_list& sorted(dylib_list& xs) { diff --git a/logic/selected-libraries.cpp b/logic/selected-libraries.cpp index ffa3e496..1fc3da86 100644 --- a/logic/selected-libraries.cpp +++ b/logic/selected-libraries.cpp @@ -2,6 +2,24 @@ #include "options/scoped.hpp" #include +using ext_ord = IExtension::event_ordinal; +using ext_mask = IExtension::event_mask; +using ext_fun_type = void(IExtension::*)(Pose&); + +static constexpr struct event_type_mapping +{ + ext_fun_type ptr; + ext_mask m; + 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, }, +}; + SelectedLibraries::SelectedLibraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f) : pTracker(nullptr), pFilter(nullptr), @@ -44,3 +62,15 @@ SelectedLibraries::SelectedLibraries(QFrame* frame, dylibptr t, dylibptr p, dyli end: opts::set_teardown_flag(prev_teardown_flag); } + +void runtime_event_handler::run_events(ext_event_ordinal k, Pose& pose) +{ + auto fun = std::mem_fn(ordinal_to_function[k].ptr); + + for (ext& x : extension_events[k]) + { + if (x == nullptr) + break; + fun(x, pose); + } +} diff --git a/logic/selected-libraries.hpp b/logic/selected-libraries.hpp index 65e9733e..041c77e5 100644 --- a/logic/selected-libraries.hpp +++ b/logic/selected-libraries.hpp @@ -9,11 +9,29 @@ #pragma once #include "api/plugin-support.hpp" +#include "export.hpp" + +#include +#include + #include -#include "export.hpp" +// XXX todo remove camel case in identifier + +struct runtime_event_handler +{ + using ext_event_ordinal = IExtension::event_ordinal; + using ext = std::shared_ptr; + + enum : unsigned { ext_max_events = 64 }; + using ext_list = std::array; + + std::array extension_events; + + void run_events(ext_event_ordinal k, Pose& pose); +}; -struct OTR_LOGIC_EXPORT SelectedLibraries +struct OTR_LOGIC_EXPORT SelectedLibraries : runtime_event_handler { using dylibptr = std::shared_ptr; diff --git a/logic/tracker.h b/logic/tracker.h index 282b5c5b..ab0cc323 100644 --- a/logic/tracker.h +++ b/logic/tracker.h @@ -31,8 +31,6 @@ namespace gui_tracker_impl { -using Pose = Mat; - struct bits { enum flags : unsigned { -- cgit v1.2.3