summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-02-23 06:06:20 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-02-23 08:54:32 +0100
commit6f69cdc4305740ed9f54b296a62a8c59ff98da0c (patch)
treea3ff480d2766c2429f8697983edd6ac8ef4f750b
parent21329f2428143140d7884b37c7db1f15a7953dc6 (diff)
logic, gui: move selected-libraries to struct work
-rw-r--r--gui/main-window.cpp42
-rw-r--r--logic/state.hpp2
-rw-r--r--logic/work.cpp12
-rw-r--r--logic/work.hpp8
4 files changed, 32 insertions, 32 deletions
diff --git a/gui/main-window.cpp b/gui/main-window.cpp
index 3bef4da5..8a04cab4 100644
--- a/gui/main-window.cpp
+++ b/gui/main-window.cpp
@@ -441,39 +441,31 @@ void MainWindow::startTracker()
if (work)
return;
- // tracker dtor needs run first
- work = nullptr;
-
- libs = SelectedLibraries(ui.video_frame, current_tracker(), current_protocol(), current_filter());
-
{
double p[6] = {0,0,0, 0,0,0};
display_pose(p, p);
}
- if (!libs.correct)
+ work = std::make_shared<Work>(pose, ui.video_frame, current_tracker(), current_protocol(), current_filter());
+
+ if (!work->is_ok())
{
QMessageBox::warning(this, tr("Library load error"),
tr("One of libraries failed to load. Check installation."),
QMessageBox::Ok,
QMessageBox::NoButton);
- libs = SelectedLibraries();
+ work = nullptr;
return;
}
- save_modules();
-
- work = std::make_shared<Work>(pose, libs, winId());
- work->reload_shortcuts();
-
if (pTrackerDialog)
- pTrackerDialog->register_tracker(libs.pTracker.get());
+ pTrackerDialog->register_tracker(work->libs.pTracker.get());
if (pFilterDialog)
- pFilterDialog->register_filter(libs.pFilter.get());
+ pFilterDialog->register_filter(work->libs.pFilter.get());
if (pProtocolDialog)
- pProtocolDialog->register_protocol(libs.pProtocol.get());
+ pProtocolDialog->register_protocol(work->libs.pProtocol.get());
pose_update_timer.start(50);
@@ -505,7 +497,6 @@ void MainWindow::stopTracker()
pFilterDialog->unregister_filter();
work = nullptr;
- libs = SelectedLibraries();
{
double p[6] = {0,0,0, 0,0,0};
@@ -521,6 +512,9 @@ void MainWindow::stopTracker()
void MainWindow::display_pose(const double *mapped, const double *raw)
{
+ if (!work)
+ return;
+
ui.pose_display->rotateBy(mapped[Yaw], mapped[Pitch], -mapped[Roll],
mapped[TX], mapped[TY], mapped[TZ]);
@@ -544,8 +538,8 @@ void MainWindow::display_pose(const double *mapped, const double *raw)
}
QString game_title;
- if (libs.pProtocol)
- game_title = libs.pProtocol->game_name();
+ if (work->libs.pProtocol)
+ game_title = work->libs.pProtocol->game_name();
set_title(game_title);
}
@@ -623,20 +617,20 @@ bool MainWindow::mk_dialog(mem<dylib> lib, ptr<t>& d)
void MainWindow::showTrackerSettings()
{
- if (mk_dialog(current_tracker(), pTrackerDialog) && libs.pTracker)
- pTrackerDialog->register_tracker(libs.pTracker.get());
+ if (mk_dialog(current_tracker(), pTrackerDialog) && work && work->libs.pTracker)
+ pTrackerDialog->register_tracker(work->libs.pTracker.get());
}
void MainWindow::showProtocolSettings()
{
- if (mk_dialog(current_protocol(), pProtocolDialog) && libs.pProtocol)
- pProtocolDialog->register_protocol(libs.pProtocol.get());
+ if (mk_dialog(current_protocol(), pProtocolDialog) && work && work->libs.pProtocol)
+ pProtocolDialog->register_protocol(work->libs.pProtocol.get());
}
void MainWindow::showFilterSettings()
{
- if (mk_dialog(current_filter(), pFilterDialog) && libs.pFilter)
- pFilterDialog->register_filter(libs.pFilter.get());
+ if (mk_dialog(current_filter(), pFilterDialog) && work && work->libs.pFilter)
+ pFilterDialog->register_filter(work->libs.pFilter.get());
}
void MainWindow::show_options_dialog()
diff --git a/logic/state.hpp b/logic/state.hpp
index 4e021949..f5892557 100644
--- a/logic/state.hpp
+++ b/logic/state.hpp
@@ -13,7 +13,6 @@ using namespace options;
#include "api/plugin-support.hpp"
#include "main-settings.hpp"
#include "mappings.hpp"
-#include "selected-libraries.hpp"
#include "work.hpp"
#include <vector>
#include <QString>
@@ -25,7 +24,6 @@ struct State
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;
- SelectedLibraries libs;
main_settings s;
Mappings pose;
mem<Work> work;
diff --git a/logic/work.cpp b/logic/work.cpp
index ebac4c39..102b859e 100644
--- a/logic/work.cpp
+++ b/logic/work.cpp
@@ -60,12 +60,11 @@ std::shared_ptr<TrackLogger> Work::make_logger(main_settings &s)
}
-Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) :
- libs(libs),
+Work::Work(Mappings& m, QFrame* frame, mem<dylib>& tracker_, mem<dylib>& filter_, mem<dylib>& proto_) :
+ libs(frame, tracker_, filter_, proto_),
logger(make_logger(s)),
tracker(std::make_shared<Tracker>(m, libs, *logger)),
sc(std::make_shared<Shortcuts>()),
- handle(handle),
keys {
key_tuple(s.key_center1, [&](bool) -> void { tracker->center(); }, true),
key_tuple(s.key_center2, [&](bool) -> void { tracker->center(); }, true),
@@ -83,6 +82,8 @@ Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) :
key_tuple(s.key_zero_press2, [&](bool x) -> void { tracker->set_zero(x); }, false),
}
{
+ if (!is_ok())
+ return;
reload_shortcuts();
tracker->start();
}
@@ -92,6 +93,11 @@ void Work::reload_shortcuts()
sc->reload(keys);
}
+bool Work::is_ok() const
+{
+ return libs.correct;
+}
+
Work::~Work()
{
// order matters, otherwise use-after-free -sh
diff --git a/logic/work.hpp b/logic/work.hpp
index b614c580..ff0524bd 100644
--- a/logic/work.hpp
+++ b/logic/work.hpp
@@ -14,6 +14,8 @@
#include "shortcuts.h"
#include "export.hpp"
#include "tracklogger.hpp"
+#include "logic/selected-libraries.hpp"
+#include "api/plugin-support.hpp"
#include <QObject>
#include <QFrame>
@@ -27,16 +29,16 @@ struct OPENTRACK_LOGIC_EXPORT Work
using fn_t = std::function<void(bool)>;
using key_tuple = std::tuple<key_opts&, fn_t, bool>;
main_settings s; // tracker needs settings, so settings must come before it
- SelectedLibraries& libs;
std::shared_ptr<TrackLogger> logger; // must come before tracker, since tracker depends on it
+ SelectedLibraries libs; // idem
std::shared_ptr<Tracker> tracker;
std::shared_ptr<Shortcuts> sc;
- WId handle;
std::vector<key_tuple> keys;
- Work(Mappings& m, SelectedLibraries& libs, WId handle);
+ Work(Mappings& m, QFrame* frame, mem<dylib>& tracker, mem<dylib>& filter, mem<dylib>& proto);
~Work();
void reload_shortcuts();
+ bool is_ok() const;
private:
static std::shared_ptr<TrackLogger> make_logger(main_settings &s);