diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-12-07 08:43:03 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-12-08 21:30:48 +0100 |
commit | 709fe557a3a5c2dc8675472dac9325f8efdff004 (patch) | |
tree | fa257eae76fc50d3cbe7b69b5c423108c170af90 | |
parent | 788cfe69a1668dfd7e6bca16907de696e6063fbe (diff) |
clean up a bit
-rw-r--r-- | api/plugin-api.cpp | 46 | ||||
-rw-r--r-- | api/plugin-support.hpp | 29 | ||||
-rw-r--r-- | compat/math.hpp | 2 | ||||
-rw-r--r-- | csv/csv.cpp | 41 | ||||
-rw-r--r-- | cv/affine.cpp | 5 | ||||
-rw-r--r-- | cv/affine.hpp | 8 | ||||
-rw-r--r-- | cv/translation-calibrator.cpp | 2 | ||||
-rw-r--r-- | cv/video-property-page.cpp | 2 | ||||
-rw-r--r-- | cv/video-widget.cpp | 4 | ||||
-rw-r--r-- | dinput/keybinding-worker.hpp | 8 | ||||
-rw-r--r-- | dinput/win32-joystick.cpp | 6 | ||||
-rw-r--r-- | logic/extensions.cpp | 2 | ||||
-rw-r--r-- | pose-widget/pose-widget.cpp | 4 | ||||
-rw-r--r-- | proto-mouse/ftnoir_protocol_mouse.h | 29 | ||||
-rw-r--r-- | proto-mouse/mouse-settings.hpp | 2 | ||||
-rw-r--r-- | spline/axis-opts.cpp | 4 | ||||
-rw-r--r-- | tracker-pt/point_tracker.cpp | 7 | ||||
-rw-r--r-- | variant/default/main-window.cpp | 62 |
18 files changed, 131 insertions, 132 deletions
diff --git a/api/plugin-api.cpp b/api/plugin-api.cpp index 5a485d62..404ed434 100644 --- a/api/plugin-api.cpp +++ b/api/plugin-api.cpp @@ -2,7 +2,28 @@ #include <utility> -using namespace plugin_api::detail; +namespace plugin_api::detail { + +BaseDialog::BaseDialog() = default; +void BaseDialog::closeEvent(QCloseEvent*) +{ + if (isVisible()) + { + hide(); + emit closing(); + } +} + +void BaseDialog::done(int) +{ + if (isVisible()) + { + hide(); + close(); + } +} + +} // ns plugin_api::detail // these exist so that vtable is emitted in a single compilation unit, not all of them. @@ -15,17 +36,6 @@ IExtension::~IExtension() = default; void ITrackerDialog::register_tracker(ITracker*) {} void ITrackerDialog::unregister_tracker() {} -BaseDialog::BaseDialog() = default; - -void BaseDialog::closeEvent(QCloseEvent*) -{ - if (isVisible()) - { - hide(); - emit closing(); - } -} - bool ITracker::center() { return false; } module_status ITracker::status_ok() @@ -46,15 +56,6 @@ IProtocolDialog::IProtocolDialog() = default; ITracker::ITracker() = default; ITrackerDialog::ITrackerDialog() = default; -void BaseDialog::done(int) -{ - if (isVisible()) - { - hide(); - close(); - } -} - IExtensionDialog::~IExtensionDialog() = default; bool module_status::is_ok() const @@ -71,6 +72,7 @@ module_status module_status_mixin::error(const QString& error) return module_status(error.isEmpty() ? "Unknown error" : error); } - Metadata::Metadata() = default; Metadata::~Metadata() = default; + + diff --git a/api/plugin-support.hpp b/api/plugin-support.hpp index 5062a688..34eee1a4 100644 --- a/api/plugin-support.hpp +++ b/api/plugin-support.hpp @@ -31,8 +31,10 @@ #define OPENTRACK_SOLIB_PREFIX "" -extern "C" typedef void* (*OPENTRACK_CTOR_FUNPTR)(void); -extern "C" typedef Metadata_* (*OPENTRACK_METADATA_FUNPTR)(void); +extern "C" { + using module_ctor_t = void* (*)(void); + using module_metadata_t = Metadata_* (*)(void); +} struct dylib final { @@ -63,26 +65,25 @@ struct dylib final if (check(!handle.load())) return; - if (check((Dialog = (OPENTRACK_CTOR_FUNPTR) handle.resolve("GetDialog"), !Dialog))) + if (check((Dialog = (module_ctor_t) handle.resolve("GetDialog"), !Dialog))) return; - if (check((Constructor = (OPENTRACK_CTOR_FUNPTR) handle.resolve("GetConstructor"), !Constructor))) + if (check((Constructor = (module_ctor_t) handle.resolve("GetConstructor"), !Constructor))) return; - if (check((Meta = (OPENTRACK_METADATA_FUNPTR) handle.resolve("GetMetadata"), !Meta))) + if (check((Meta = (module_metadata_t) handle.resolve("GetMetadata"), !Meta))) return; - auto m = std::unique_ptr<Metadata_>(Meta()); + std::unique_ptr<Metadata_> m{Meta()}; icon = m->icon(); name = m->name(); type = t; } - ~dylib() - { - // QLibrary refcounts the .dll's so don't forcefully unload - } + + // QLibrary refcounts the .dll's so don't forcefully unload + ~dylib() = default; static QList<std::shared_ptr<dylib>> enum_libraries(const QString& library_path) { @@ -134,9 +135,9 @@ struct dylib final QIcon icon; QString name; - OPENTRACK_CTOR_FUNPTR Dialog; - OPENTRACK_CTOR_FUNPTR Constructor; - OPENTRACK_METADATA_FUNPTR Meta; + module_ctor_t Dialog; + module_ctor_t Constructor; + module_metadata_t Meta; private: QLibrary handle; @@ -242,6 +243,6 @@ static inline std::shared_ptr<t> make_dylib_instance(const std::shared_ptr<dylib { std::shared_ptr<t> ret; if (lib != nullptr && lib->Constructor) - ret = std::shared_ptr<t>(reinterpret_cast<t*>(reinterpret_cast<OPENTRACK_CTOR_FUNPTR>(lib->Constructor)())); + ret = std::shared_ptr<t>(reinterpret_cast<t*>(reinterpret_cast<module_ctor_t>(lib->Constructor)())); return ret; } diff --git a/compat/math.hpp b/compat/math.hpp index 656e10a8..fa4ff4a6 100644 --- a/compat/math.hpp +++ b/compat/math.hpp @@ -50,7 +50,7 @@ template<typename t, typename u, typename v> inline auto clamp(const t& val, const u& min, const v& max) { using w = cv_qualified<decltype(val + min + max)>; - return ::util_detail::clamp<w>::clamp_(val, min, max); + return util_detail::clamp<w>::clamp_(val, min, max); } template<typename t> diff --git a/csv/csv.cpp b/csv/csv.cpp index 73c56aed..aa518673 100644 --- a/csv/csv.cpp +++ b/csv/csv.cpp @@ -137,43 +137,32 @@ bool CSV::getGameData(int id, unsigned char* table, QString& gamename) const QByteArray id_cstr = gameLine[7].toLatin1(); - if (proto == QStringLiteral("V160")) - { - /* nothing */ - } - else if (id_cstr.length() != 22 || - sscanf(id_cstr.constData(), - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - fuzz + 2, - fuzz + 0, - tmp + 3, - tmp + 2, - tmp + 1, - tmp + 0, - tmp + 7, - tmp + 6, - tmp + 5, - tmp + 4, - fuzz + 1) != 11) - { + auto do_scanf = [&]() { + return sscanf(id_cstr.constData(), + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + fuzz + 2, + fuzz + 0, + tmp + 3, tmp + 2, tmp + 1, tmp + 0, + tmp + 7, tmp + 6, tmp + 5, tmp + 4, + fuzz + 1); + }; + + if (proto == QStringLiteral("V160") || id_cstr.length() != 22) + (void)0; + else if (id_cstr.length() != 22 || do_scanf() != 11) qDebug() << "scanf failed" << lineno; - } else { + using uchar = unsigned char; for (int i = 0; i < 8; i++) - { - using t = unsigned char; - table[i] = t(tmp[i]); - } + table[i] = uchar(tmp[i]); } gamename = std::move(name); return true; } } else - { qDebug() << "malformed csv line" << lineno; - } } if (id) diff --git a/cv/affine.cpp b/cv/affine.cpp index 4ec63e57..66e21aa6 100644 --- a/cv/affine.cpp +++ b/cv/affine.cpp @@ -9,9 +9,8 @@ namespace affine_impl { -Affine::Affine() : R(mat33::eye()), t(0,0,0) {} - -Affine::Affine(const mat33& R, const vec3& t) : R(R),t(t) {} +Affine::Affine() = default; +Affine::Affine(const mat33& R, const vec3& t) : R(R), t(t) {} Affine operator*(const Affine& X, const Affine& Y) { diff --git a/cv/affine.hpp b/cv/affine.hpp index 3bc85c95..5d344138 100644 --- a/cv/affine.hpp +++ b/cv/affine.hpp @@ -20,8 +20,8 @@ public: Affine(); Affine(const mat33& R, const vec3& t); - mat33 R; - vec3 t; + mat33 R { mat33::eye() }; + vec3 t { 0, 0, 0 }; }; Affine operator*(const Affine& X, const Affine& Y); @@ -31,5 +31,5 @@ vec3 operator*(const Affine& X, const vec3& v); } // ns affine_impl -using affine_impl::Affine; -using affine_impl::operator *; +using Affine = affine_impl::Affine; +//using affine_impl::operator *; diff --git a/cv/translation-calibrator.cpp b/cv/translation-calibrator.cpp index 708cc593..9ead888e 100644 --- a/cv/translation-calibrator.cpp +++ b/cv/translation-calibrator.cpp @@ -94,7 +94,7 @@ bool TranslationCalibrator::check_bucket(const cv::Matx33d& R_CM_k) const euler_t ypr = rmat_to_euler(r) * r2d; auto array_index = [](double val, double spacing) { - return iround((val + 180)/spacing); + return (unsigned)iround((val + 180)/spacing); }; const unsigned yaw_k = array_index(ypr(yaw_rdof), yaw_spacing_in_degrees); diff --git a/cv/video-property-page.cpp b/cv/video-property-page.cpp index e76f8bc3..e6177c5c 100644 --- a/cv/video-property-page.cpp +++ b/cv/video-property-page.cpp @@ -48,7 +48,7 @@ struct prop_settings_worker final : QThread prop_settings_worker::prop_settings_worker(int idx) { - int ret = cap.get(cv::CAP_PROP_SETTINGS); + int ret = (int)cap.get(cv::CAP_PROP_SETTINGS); if (ret != 0) run_in_thread_async(qApp, [] { diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp index d93429cb..c80bd96b 100644 --- a/cv/video-widget.cpp +++ b/cv/video-widget.cpp @@ -53,7 +53,7 @@ void cv_video_widget::update_image(const cv::Mat& frame) else img = &_frame2; - const unsigned nbytes = 4 * img->rows * img->cols; + const unsigned nbytes = unsigned(4 * img->rows * img->cols); vec.resize(nbytes); @@ -70,7 +70,7 @@ void cv_video_widget::update_image(const QImage& img) if (freshp) return; - const unsigned nbytes = img.bytesPerLine() * img.height(); + const unsigned nbytes = unsigned(img.bytesPerLine() * img.height()); vec.resize(nbytes); diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp index ec403c15..d1dc4149 100644 --- a/dinput/keybinding-worker.hpp +++ b/dinput/keybinding-worker.hpp @@ -41,6 +41,9 @@ struct OTR_DINPUT_EXPORT KeybindingWorker : private QThread { using fun = std::function<void(const Key&)>; + KeybindingWorker(const KeybindingWorker&) = delete; + KeybindingWorker& operator=(KeybindingWorker&) = delete; + private: LPDIRECTINPUTDEVICE8 dinkeyboard { nullptr }; win32_joy_ctx joy_ctx; @@ -62,13 +65,10 @@ private: static KeybindingWorker& make(); fun* _add_receiver(fun &receiver); void remove_receiver(fun* pos); - ~KeybindingWorker(); + ~KeybindingWorker() override; static constexpr int num_keyboard_states = 64; DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states] {}; - - KeybindingWorker(const KeybindingWorker&) = delete; - KeybindingWorker& operator=(KeybindingWorker&) = delete; public: class Token { diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp index 71c93543..d1546df3 100644 --- a/dinput/win32-joystick.cpp +++ b/dinput/win32-joystick.cpp @@ -49,7 +49,7 @@ bool win32_joy_ctx::poll_axis(const QString &guid, int* axes) auto& joy_handle = j->joy_handle; bool ok = false; - HRESULT hr; + HRESULT hr = S_OK; (void)hr; if (SUCCEEDED(hr = joy_handle->Poll())) ok = true; @@ -84,7 +84,7 @@ bool win32_joy_ctx::poll_axis(const QString &guid, int* axes) js.rglSlider[1] }; - for (int i = 0; i < 8; i++) + for (unsigned i = 0; i < 8; i++) axes[i] = values[i]; return true; @@ -184,7 +184,7 @@ bool win32_joy_ctx::joy::poll(fn const& f) default: if (event.dwOfs >= BUTTON_OFFSET(0) && event.dwOfs <= BUTTON_OFFSET(max_buttons - 1)) { - i = event.dwOfs - BUTTON_OFFSET(0); + i = int(event.dwOfs - BUTTON_OFFSET(0)); i /= sizeof(DIJOYSTATE2().rgbButtons[0]); i %= max_buttons; // defensive programming } 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/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 12de49d3..b10578d9 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -277,8 +277,8 @@ void pose_transform::project_quad_texture() Triangle t(pt[0], pt[1], pt[2]); - const unsigned orig_pitch = tex.bytesPerLine(); - const unsigned dest_pitch = image.bytesPerLine(); + const unsigned orig_pitch = (unsigned)tex.bytesPerLine(); + const unsigned dest_pitch = (unsigned)image.bytesPerLine(); unsigned char const* __restrict orig = tex.constBits(); unsigned char* __restrict dest = image.bits(); diff --git a/proto-mouse/ftnoir_protocol_mouse.h b/proto-mouse/ftnoir_protocol_mouse.h index 2b88ae1d..c8709604 100644 --- a/proto-mouse/ftnoir_protocol_mouse.h +++ b/proto-mouse/ftnoir_protocol_mouse.h @@ -20,39 +20,40 @@ class mouse : public TR, public IProtocol { Q_OBJECT + static int get_delta(int val, int prev); + static int get_value(double val, double sensitivity, bool is_rotation); + + int last_x = 0, last_y = 0; + mouse_settings s; + public: mouse() = default; module_status initialize() override { return status_ok(); } void pose(const double* headpose) override; QString game_name() override; - - int last_x = 0, last_y = 0; -private: - static int get_delta(int val, int prev); - static int get_value(double val, double sensitivity, bool is_rotation); - - struct mouse_settings s; }; class MOUSEControls: public IProtocolDialog { Q_OBJECT -public: - MOUSEControls(); - void register_protocol(IProtocol *) {} - void unregister_protocol() {} -private: + Ui::UICMOUSEControls ui; mouse_settings s; + private slots: void doOK(); void doCancel(); + +public: + MOUSEControls(); + void register_protocol(IProtocol *) override {} + void unregister_protocol() override {} }; class mouseDll : public Metadata { Q_OBJECT - QString name() { return tr("mouse emulation"); } - QIcon icon() { return QIcon(":/images/mouse.png"); } + QString name() override { return tr("mouse emulation"); } + QIcon icon() override { return QIcon(":/images/mouse.png"); } }; diff --git a/proto-mouse/mouse-settings.hpp b/proto-mouse/mouse-settings.hpp index 71726588..c485e534 100644 --- a/proto-mouse/mouse-settings.hpp +++ b/proto-mouse/mouse-settings.hpp @@ -20,4 +20,4 @@ struct mouse_settings : opts { } // ns mouse_impl -using mouse_impl::mouse_settings; +using mouse_settings = mouse_impl::mouse_settings; diff --git a/spline/axis-opts.cpp b/spline/axis-opts.cpp index b5f11aaa..fa527877 100644 --- a/spline/axis-opts.cpp +++ b/spline/axis-opts.cpp @@ -1,5 +1,7 @@ #include "axis-opts.hpp" +namespace axis_opts_impl { + using max_clamp = axis_opts::max_clamp; static max_clamp get_max_x(Axis k) @@ -43,3 +45,5 @@ QString axis_opts::n(QString const& pfx, QString const& name) { return QString("%1-%2").arg(pfx, name); } + +} // ns axis_opts_impl diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index e86e686b..103228f5 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -8,14 +8,16 @@ #include "point_tracker.h" #include "compat/math-imports.hpp" -using namespace types; - #include <vector> #include <algorithm> #include <cmath> #include <QDebug> +namespace pt_module { + +using namespace types; + static void get_row(const mat33& m, int i, vec3& v) { v[0] = m(i,0); @@ -414,3 +416,4 @@ void PointTracker::reset_state() init_phase = true; } +} // ns pt_module diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp index 0112e2cc..5cb1af42 100644 --- a/variant/default/main-window.cpp +++ b/variant/default/main-window.cpp @@ -637,25 +637,22 @@ void main_window::show_pose() display_pose(mapped, raw); } -template<typename t, typename... Args> -bool mk_window(std::unique_ptr<t>& place, Args&&... params) -{ - return mk_window_common(place, [&] { - return std::make_unique<t>(params...); - }); -} - -template<typename t> -bool mk_dialog(std::unique_ptr<t>& place, const std::shared_ptr<dylib>& lib) +void show_window(QWidget& d, bool fresh) { - using u = std::unique_ptr<t>; + if (fresh) + { + d.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | d.windowFlags()); + d.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - return mk_window_common(place, [&] { - if (lib && lib->Dialog) - return u{ (t*)lib->Dialog() }; - else - return u{}; - }); + d.show(); + d.adjustSize(); + d.raise(); + } + else + { + d.show(); + d.raise(); + } } template<typename t, typename F> @@ -672,22 +669,25 @@ bool mk_window_common(std::unique_ptr<t>& d, F&& fun) return fresh; } -void show_window(QWidget& d, bool fresh) +template<typename t, typename... Args> +bool mk_window(std::unique_ptr<t>& place, Args&&... params) { - if (fresh) - { - d.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | d.windowFlags()); - d.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + return mk_window_common(place, [&] { + return std::make_unique<t>(params...); + }); +} - d.show(); - d.adjustSize(); - d.raise(); - } - else - { - d.show(); - d.raise(); - } +template<typename t> +bool mk_dialog(std::unique_ptr<t>& place, const std::shared_ptr<dylib>& lib) +{ + using u = std::unique_ptr<t>; + + return mk_window_common(place, [&] { + if (lib && lib->Dialog) + return u{ (t*)lib->Dialog() }; + else + return u{}; + }); } void main_window::show_tracker_settings() |