diff options
32 files changed, 123 insertions, 112 deletions
diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp index b23a5010..53d4fac6 100644 --- a/api/plugin-api.hpp +++ b/api/plugin-api.hpp @@ -27,8 +27,7 @@ enum Axis { NonAxis = -1, }; -namespace plugin_api { -namespace detail { +namespace plugin_api::detail { class OTR_API_EXPORT BaseDialog : public QDialog { @@ -44,7 +43,6 @@ private slots: }; } // ns -} // ns #define OTR_PLUGIN_EXPORT OTR_GENERIC_EXPORT diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp index 0f4c6e6d..0e154dd0 100644 --- a/compat/check-visible.cpp +++ b/compat/check-visible.cpp @@ -4,7 +4,7 @@ #include "timer.hpp" -#include <QMutexLocker> +#include <QMutex> #include <windows.h> diff --git a/compat/correlation-calibrator.cpp b/compat/correlation-calibrator.cpp index 70455818..b2e83153 100644 --- a/compat/correlation-calibrator.cpp +++ b/compat/correlation-calibrator.cpp @@ -61,7 +61,7 @@ bool correlation_calibrator::check_buckets(const vec6& data) if (pos[k] >= nbuckets[k]) { - once_only(qDebug() << "idx" << k + eval_once(qDebug() << "idx" << k << "bucket" << (int)pos[k] << "outside bounds" << nbuckets[k]); diff --git a/compat/macros.hpp b/compat/macros.hpp index 61c49975..0807df4c 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -44,8 +44,13 @@ // from now only C++ +#include <utility> + //#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false) -#define once_only(expr) ([&] { static decltype(auto) ret___1132 = (expr); return ret___1132; }()) +//#define once_only(expr) ([&] { static decltype(auto) ret___1132 = (expr); return (decltype(ret___1132) const&) ret___1132; }()) + +#define eval_once__2(expr, ident) (([&] { static bool ident = ((expr), true); (void)(ident); })) +#define eval_once(expr) eval_once__2(expr, PP_CAT(eval_once_init__, __COUNTER__)) #include <type_traits> diff --git a/compat/meta.hpp b/compat/meta.hpp index 8682fdc8..11c5ca0f 100644 --- a/compat/meta.hpp +++ b/compat/meta.hpp @@ -11,9 +11,7 @@ static_assert(sizeof...(x) == ~0ul); \ static_assert(sizeof...(x) == 0u) -namespace meta { - -namespace detail { +namespace meta::detail { template<typename... xs> struct tuple; @@ -47,27 +45,26 @@ namespace detail { { using type = to<xs...>; }; -} // ns detail - - -template<typename... xs> -using reverse = typename detail::reverse_<detail::tuple<xs...>, detail::tuple<>>::type; +} // ns meta::detail -// the to/from order is awkward but mimics function composition -template<template<typename...> class to, typename from> -using lift = typename detail::lift_<to, from>::type; +namespace meta { + template<typename... xs> + using reverse = typename detail::reverse_<detail::tuple<xs...>, detail::tuple<>>::type; -template<typename x, typename... xs> -using first = x; + // the to/from order is awkward but mimics function composition + template<template<typename...> class to, typename from> + using lift = typename detail::lift_<to, from>::type; -template<typename x, typename... xs> -using rest = detail::tuple<xs...>; + template<typename x, typename... xs> + using first = x; -template<typename... xs> -using butlast = reverse<rest<reverse<xs...>>>; + template<typename x, typename... xs> + using rest = detail::tuple<xs...>; -template<typename... xs> -using last = lift<first, reverse<xs...>>; + template<typename... xs> + using butlast = reverse<rest<reverse<xs...>>>; + template<typename... xs> + using last = lift<first, reverse<xs...>>; } // ns meta diff --git a/compat/timer.cpp b/compat/timer.cpp index dc9808b1..b9664263 100644 --- a/compat/timer.cpp +++ b/compat/timer.cpp @@ -6,9 +6,8 @@ * notice appear in all copies. */ -#include <cassert> - #include "timer.hpp" +#include <cassert> #include <cmath> using time_type = Timer::time_type; diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index bf264315..c8cdc72d 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -248,7 +248,7 @@ static cc_forceinline bool nan_check_(const x& datum, const y& next, const xs&.. static cc_noinline void emit_nan_check_msg(const char* text, const char* fun, int line) { - once_only( + eval_once( qDebug() << "nan check failed" << "for:" << text << "function:" << fun diff --git a/logic/win32-shortcuts.cpp b/logic/win32-shortcuts.cpp index 170d16fe..11764807 100644 --- a/logic/win32-shortcuts.cpp +++ b/logic/win32-shortcuts.cpp @@ -119,7 +119,7 @@ static const win_key windows_key_sequences[] { { DIK_PAUSE, Qt::Key_Pause}, { DIK_NUMLOCK, Qt::Key_NumLock}, { DIK_CAPSLOCK, Qt::Key_CapsLock}, -#define mod(x, y) static_cast<Qt::Key>((x) | (y)) +#define mod(x, y) Qt::Key(int(x) | int((y))) { DIK_NUMPAD0, mod(Qt::Key_0, Qt::KeypadModifier)}, { DIK_NUMPAD0, mod(Qt::Key_0, Qt::KeypadModifier)}, { DIK_NUMPAD1, mod(Qt::Key_1, Qt::KeypadModifier)}, diff --git a/logic/win32-shortcuts.h b/logic/win32-shortcuts.h index 8cd6bdc9..437d251a 100644 --- a/logic/win32-shortcuts.h +++ b/logic/win32-shortcuts.h @@ -10,7 +10,7 @@ struct OTR_LOGIC_EXPORT win_key { - win_key(int win, Qt::Key qt) : win(win), qt(qt) {} + //win_key(int win, Qt::Key qt) : win(win), qt(qt) {} int win; Qt::Key qt; static bool from_qt(QKeySequence qt_, int& dik, Qt::KeyboardModifiers &mods); diff --git a/options/base-value.cpp b/options/base-value.cpp index dbeabbea..d900ad0f 100644 --- a/options/base-value.cpp +++ b/options/base-value.cpp @@ -26,8 +26,7 @@ void value_::store(const QVariant& datum) b->store_kv(self_name, datum); } -namespace options { -namespace detail { +namespace options::detail { void set_base_value_to_default(value_* val) { @@ -35,5 +34,4 @@ void set_base_value_to_default(value_* val) } } // ns options::detail -} // ns options diff --git a/options/bundle.cpp b/options/bundle.cpp index e0db3fb3..b722338b 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -14,10 +14,7 @@ using options::value_; -namespace options -{ - -namespace detail { +namespace options::detail { bundle::bundle(const QString& group_name) : mtx(QMutex::Recursive), @@ -152,7 +149,7 @@ void bundler::after_profile_changed_() void bundler::refresh_all_bundles() { - singleton().after_profile_changed_(); + bundler_singleton().after_profile_changed_(); } bundler::bundler() : implsgl_mtx(QMutex::Recursive) @@ -164,7 +161,7 @@ bundler::~bundler() //qDebug() << "exit: bundle singleton"; } -std::shared_ptr<bundler::v> bundler::make_bundle(const bundler::k& key) +std::shared_ptr<bundler::v> bundler::make_bundle_(const bundler::k& key) { QMutexLocker l(&implsgl_mtx); @@ -193,7 +190,7 @@ std::shared_ptr<bundler::v> bundler::make_bundle(const bundler::k& key) return shr; } -OTR_OPTIONS_EXPORT bundler& singleton() +bundler& bundler::bundler_singleton() { static bundler ret; return ret; @@ -201,14 +198,16 @@ OTR_OPTIONS_EXPORT bundler& singleton() QMutex* bundle::get_mtx() const { return mtx; } -} // end options::detail +} // ns options::detail + +namespace options { OTR_OPTIONS_EXPORT std::shared_ptr<bundle_> make_bundle(const QString& name) { if (name.size()) - return detail::singleton().make_bundle(name); + return detail::bundler::bundler_singleton().make_bundle_(name); else return std::make_shared<bundle_>(QString()); } -} // end options +} // ns options diff --git a/options/bundle.hpp b/options/bundle.hpp index 98e194db..a12a335c 100644 --- a/options/bundle.hpp +++ b/options/bundle.hpp @@ -27,11 +27,17 @@ #include "export.hpp" -namespace options { +namespace options::detail { + class bundle; +} // ns options::detail -namespace detail { +namespace options { + using bundle_ = detail::bundle; + using bundle = std::shared_ptr<bundle_>; + OTR_OPTIONS_EXPORT std::shared_ptr<detail::bundle> make_bundle(const QString& name); +} // ns options -void set_base_value_to_default(value_* val); +namespace options::detail { struct bundler; @@ -52,17 +58,18 @@ private: group saved; group transient; +signals: + void reloading(); + void saving() const; + void changed() const; + +public: bundle(const bundle&) = delete; bundle(bundle&&) = delete; bundle& operator=(bundle&&) = delete; bundle& operator=(const bundle&) = delete; QMutex* get_mtx() const override; -signals: - void reloading(); - void saving() const; - void changed() const; -public: cc_noinline bundle(const QString& group_name); cc_noinline ~bundle() override; QString name() const { return group_name; } @@ -82,32 +89,34 @@ public slots: void set_all_to_default(); }; -OTR_OPTIONS_EXPORT bundler& singleton(); - -struct OTR_OPTIONS_EXPORT bundler +struct OTR_OPTIONS_EXPORT bundler final { -public: using k = QString; using v = bundle; using weak = std::weak_ptr<v>; using shared = std::shared_ptr<v>; + private: QMutex implsgl_mtx; std::map<k, weak> implsgl_data; void after_profile_changed_(); + public: + static void refresh_all_bundles(); + +private: + friend OTR_OPTIONS_EXPORT + std::shared_ptr<v> options::make_bundle(const QString& name); + + std::shared_ptr<v> make_bundle_(const k& key); + + static bundler& bundler_singleton(); + bundler(); ~bundler(); - std::shared_ptr<v> make_bundle(const k& key); - static void refresh_all_bundles(); }; -OTR_OPTIONS_EXPORT bundler& singleton(); -} // ns options::detail - -using bundle_ = detail::bundle; -using bundle = std::shared_ptr<bundle_>; +void set_base_value_to_default(value_* val); -OTR_OPTIONS_EXPORT std::shared_ptr<bundle_> make_bundle(const QString& name); +} // ns options::detail -} // ns options diff --git a/options/connector.cpp b/options/connector.cpp index 2d039ccf..0efac8f1 100644 --- a/options/connector.cpp +++ b/options/connector.cpp @@ -11,8 +11,7 @@ #include <utility> -namespace options { -namespace detail { +namespace options::detail { static bool generic_is_equal(const QVariant& val1, const QVariant& val2) { @@ -129,6 +128,4 @@ connector::connector() { } -} - -} +} // ns options::detail diff --git a/options/connector.hpp b/options/connector.hpp index 68e86096..26812e7f 100644 --- a/options/connector.hpp +++ b/options/connector.hpp @@ -21,10 +21,10 @@ #include "export.hpp" namespace options { + class value_; +} -class value_; - -namespace detail { +namespace options::detail { class OTR_OPTIONS_EXPORT connector { @@ -67,5 +67,4 @@ public: connector& operator=(connector&&) = default; }; -} // ns detail -} // ns options +} // ns options::detail diff --git a/options/defs.hpp b/options/defs.hpp index 58846cc3..2467a7a0 100644 --- a/options/defs.hpp +++ b/options/defs.hpp @@ -24,8 +24,7 @@ #define OPENTRACK_DEFINE_METATYPE(t) OPENTRACK_DEFINE_METATYPE2(t, __COUNTER__) -namespace options { -namespace detail { +namespace options::detail { struct custom_type_initializer final { @@ -39,4 +38,4 @@ struct custom_type_initializer final }; } // ns options::detail -} // ns options + diff --git a/options/slider.cpp b/options/slider.cpp index 4f4124c6..56d9ba16 100644 --- a/options/slider.cpp +++ b/options/slider.cpp @@ -24,8 +24,21 @@ slider_value::slider_value(double cur, double min, double max) : cur_ = min_; } -slider_value::slider_value(const slider_value& v) : slider_value(v.cur(), v.min(), v.max()) +slider_value& slider_value::operator=(const slider_value& v) { + if (this != &v) + { + cur_ = v.cur(); + min_ = v.min(); + max_ = v.max(); + } + + return *this; +} + +slider_value::slider_value(const slider_value& v) +{ + *this = v; } slider_value::slider_value() : slider_value(0, 0, 0) diff --git a/options/slider.hpp b/options/slider.hpp index 6c9c5a23..360c85b8 100644 --- a/options/slider.hpp +++ b/options/slider.hpp @@ -40,6 +40,8 @@ namespace options return t(cur_); } + slider_value& operator=(const slider_value& v); + slider_value(const slider_value& v); slider_value(); bool operator==(const slider_value& v) const; diff --git a/options/value-traits.hpp b/options/value-traits.hpp index 0b30248e..b507874c 100644 --- a/options/value-traits.hpp +++ b/options/value-traits.hpp @@ -8,8 +8,7 @@ #include <type_traits> -namespace options { -namespace detail { +namespace options::detail { template<typename t, typename u = t, typename Enable = void> struct default_value_traits @@ -49,5 +48,5 @@ struct value_traits<float> : public default_value_traits<float, double, void> { }; -} // ns detail -} // ns options +} // ns options::detail + diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp index bf99a94f..7bc85afa 100644 --- a/proto-ft/ftnoir_protocol_ft.cpp +++ b/proto-ft/ftnoir_protocol_ft.cpp @@ -20,8 +20,8 @@ freetrack::~freetrack() dummyTrackIR.close(); } -static_assert(sizeof(LONG) == sizeof(std::int32_t), ""); -static_assert(sizeof(LONG) == 4u, ""); +static_assert(sizeof(LONG) == sizeof(std::int32_t)); +static_assert(sizeof(LONG) == 4u); static constexpr inline float d2r = float(M_PI/180); @@ -35,8 +35,8 @@ cc_noinline void store(float volatile& place, const float value) value_.f32 = value; - static_assert(sizeof(value_) == sizeof(float), ""); - static_assert(offsetof(decltype(value_), f32) == offsetof(decltype(value_), i32), ""); + static_assert(sizeof(value_) == sizeof(float)); + static_assert(offsetof(decltype(value_), f32) == offsetof(decltype(value_), i32)); (void)InterlockedExchange((LONG volatile*)&place, value_.i32); } @@ -44,7 +44,7 @@ cc_noinline void store(float volatile& place, const float value) template<typename t> cc_forceinline void store(t volatile& place, t value) { - static_assert(sizeof(t) == 4u, ""); + static_assert(sizeof(t) == 4u); (void)InterlockedExchange((LONG volatile*) &place, value); } diff --git a/proto-ft/lang/nl_NL.ts b/proto-ft/lang/nl_NL.ts index e2b72543..ec4f58da 100644 --- a/proto-ft/lang/nl_NL.ts +++ b/proto-ft/lang/nl_NL.ts @@ -56,11 +56,11 @@ Starting tracking will again overwrite the DLL locations.</source> <context> <name>freetrack</name> <message> - <source>Can't load freetrack memory mapping</source> + <source>Unknown game</source> <translation type="unfinished"></translation> </message> <message> - <source>Unknown game</source> + <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> </context> diff --git a/proto-ft/lang/ru_RU.ts b/proto-ft/lang/ru_RU.ts index d749121c..c793ae6b 100644 --- a/proto-ft/lang/ru_RU.ts +++ b/proto-ft/lang/ru_RU.ts @@ -58,11 +58,11 @@ Starting tracking will again overwrite the DLL locations.</source> <context> <name>freetrack</name> <message> - <source>Can't load freetrack memory mapping</source> + <source>Unknown game</source> <translation type="unfinished"></translation> </message> <message> - <source>Unknown game</source> + <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> </context> diff --git a/proto-ft/lang/stub.ts b/proto-ft/lang/stub.ts index 4962332f..635844a5 100644 --- a/proto-ft/lang/stub.ts +++ b/proto-ft/lang/stub.ts @@ -56,11 +56,11 @@ Starting tracking will again overwrite the DLL locations.</source> <context> <name>freetrack</name> <message> - <source>Can't load freetrack memory mapping</source> + <source>Unknown game</source> <translation type="unfinished"></translation> </message> <message> - <source>Unknown game</source> + <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> </context> diff --git a/proto-ft/lang/zh_CN.ts b/proto-ft/lang/zh_CN.ts index 903ce19b..442a1aa1 100644 --- a/proto-ft/lang/zh_CN.ts +++ b/proto-ft/lang/zh_CN.ts @@ -56,11 +56,11 @@ Starting tracking will again overwrite the DLL locations.</source> <context> <name>freetrack</name> <message> - <source>Can't load freetrack memory mapping</source> + <source>Unknown game</source> <translation type="unfinished"></translation> </message> <message> - <source>Unknown game</source> + <source>Can't load freetrack memory mapping</source> <translation type="unfinished"></translation> </message> </context> diff --git a/proto-simconnect/ftnoir_protocol_sc.cpp b/proto-simconnect/ftnoir_protocol_sc.cpp index ab4a85dd..75815f1b 100644 --- a/proto-simconnect/ftnoir_protocol_sc.cpp +++ b/proto-simconnect/ftnoir_protocol_sc.cpp @@ -22,7 +22,7 @@ simconnect::~simconnect() void simconnect::run() { - HANDLE event = CreateEventA(NULL, FALSE, FALSE, nullptr); + HANDLE event = CreateEventA(nullptr, FALSE, FALSE, nullptr); if (event == nullptr) { diff --git a/spline/axis-opts.cpp b/spline/axis-opts.cpp index d7616939..b5f11aaa 100644 --- a/spline/axis-opts.cpp +++ b/spline/axis-opts.cpp @@ -39,7 +39,7 @@ QString const& axis_opts::prefix() const { return prefix_; } Axis axis_opts::axis() const { return axis_; } -QString axis_opts::n(QString pfx, QString name) +QString axis_opts::n(QString const& pfx, QString const& name) { return QString("%1-%2").arg(pfx, name); } diff --git a/spline/axis-opts.hpp b/spline/axis-opts.hpp index 2f0d8432..a76ea3cf 100644 --- a/spline/axis-opts.hpp +++ b/spline/axis-opts.hpp @@ -50,7 +50,7 @@ struct OTR_SPLINE_EXPORT axis_opts final QString const& prefix() const; Axis axis() const; private: - static inline QString n(QString pfx, QString name); + static inline QString n(QString const& pfx, QString const& name); QString prefix_; Axis axis_; diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp index 6025d74c..07e97d78 100644 --- a/tracker-hatire/thread.cpp +++ b/tracker-hatire/thread.cpp @@ -25,7 +25,7 @@ void hatire_thread::sendcmd_impl(const QByteArray &cmd) Log(logMess); com_port.write(cmd); if (!com_port.waitForBytesWritten(1000)) { - emit serial_debug_info_str(tr("Timeout during writing command")); + serial_debug_info_str(tr("Timeout during writing command")); } else { Msg.append("\r\n"); @@ -43,7 +43,7 @@ void hatire_thread::sendcmd_impl(const QByteArray &cmd) emit serial_debug_info(Msg); #endif } else { - emit serial_debug_info_str(tr("COM port not open")); + serial_debug_info_str(tr("COM port not open")); } } #endif @@ -146,7 +146,7 @@ void hatire_thread::run() void hatire_thread::serial_debug_info_str(const QString& str) { - serial_debug_info(str.toUtf8()); + emit serial_debug_info(str.toLatin1()); } serial_result hatire_thread::init_serial_port_impl() diff --git a/tracker-pt/module/frame.cpp b/tracker-pt/module/frame.cpp index f54c2e36..6734edf6 100644 --- a/tracker-pt/module/frame.cpp +++ b/tracker-pt/module/frame.cpp @@ -2,9 +2,6 @@ #include "compat/math.hpp" -#include <cstring> -#include <tuple> - #include <opencv2/imgproc.hpp> using namespace pt_module; @@ -16,7 +13,7 @@ Preview& Preview::operator=(const pt_frame& frame_) if (frame.channels() != 3) { - once_only(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels()); + eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels()); return *this; } @@ -42,7 +39,7 @@ QImage Preview::get_bitmap() if (stride < 64 || stride < frame_out.cols * 4) { - once_only(qDebug() << "bad stride" << stride + eval_once(qDebug() << "bad stride" << stride << "for bitmap size" << frame_copy.cols << frame_copy.rows); return QImage(); } diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index 1208da4e..00248029 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -147,7 +147,7 @@ void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) break; } default: - once_only(qDebug() << "wrong pt_color_type enum value" << int(s.blob_color)); + eval_once(qDebug() << "wrong pt_color_type enum value" << int(s.blob_color)); /*FALLTHROUGH*/ case pt_color_natural: cv::cvtColor(frame, output, cv::COLOR_BGR2GRAY); diff --git a/tracker-pt/pt-settings.hpp b/tracker-pt/pt-settings.hpp index a8e3497a..a35c248b 100644 --- a/tracker-pt/pt-settings.hpp +++ b/tracker-pt/pt-settings.hpp @@ -18,8 +18,8 @@ struct pt_settings final : options::opts { using slider_value = options::slider_value; - pt_settings(const QString& name) : opts(name) {} - ~pt_settings() {} + explicit pt_settings(const QString& name) : opts(name) {} + ~pt_settings() override = default; value<QString> camera_name { b, "camera-name", "" }; value<int> cam_res_x { b, "camera-res-width", 640 }, diff --git a/tracker-steamvr/steamvr.cpp b/tracker-steamvr/steamvr.cpp index e4ac8835..cafdc556 100644 --- a/tracker-steamvr/steamvr.cpp +++ b/tracker-steamvr/steamvr.cpp @@ -140,7 +140,7 @@ device_list::maybe_pose device_list::get_pose(int k) if (pose.bPoseIsValid && pose.bDeviceIsConnected) return maybe_pose{ true, poses[k] }; else - once_only(qDebug() << "steamvr:" + eval_once(qDebug() << "steamvr:" << "no valid pose from device" << k << "valid" << pose.bPoseIsValid << "connected" << pose.bDeviceIsConnected); diff --git a/tracker-wii/wii_frame.cpp b/tracker-wii/wii_frame.cpp index 92e7fd35..df7b9ca4 100644 --- a/tracker-wii/wii_frame.cpp +++ b/tracker-wii/wii_frame.cpp @@ -27,7 +27,7 @@ WIIPreview& WIIPreview::operator=(const pt_frame& frame_) if (frame.channels() != 3) { - once_only(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels()); + eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels()); return *this; } @@ -61,7 +61,7 @@ QImage WIIPreview::get_bitmap() if (stride < 64 || stride < frame_out.cols * 4) { - once_only(qDebug() << "bad stride" << stride + eval_once(qDebug() << "bad stride" << stride << "for bitmap size" << frame_copy.cols << frame_copy.rows); return QImage(); } |