summaryrefslogtreecommitdiffhomepage
path: root/logic
diff options
context:
space:
mode:
authorStanisław Halik <sthalik@misaki.pl>2017-05-14 16:22:09 +0200
committerGitHub <noreply@github.com>2017-05-14 16:22:09 +0200
commit5c23666b58bb1dd4aea15c0d62a2f716d5be7f52 (patch)
treee6497e9b55c073be209ec673ef05e62bf57a2c8f /logic
parent4701dd3b0c8323a11cf7d5ad09c579a9864a41bd (diff)
parentc392181211b245e74292424500265323c960c1aa (diff)
Merge branch 'unstable' into unstable
Diffstat (limited to 'logic')
-rw-r--r--logic/mappings.cpp6
-rw-r--r--logic/mappings.hpp2
-rw-r--r--logic/selected-libraries.hpp11
-rw-r--r--logic/state.hpp2
-rw-r--r--logic/tracker.cpp22
-rw-r--r--logic/tracker.h2
-rw-r--r--logic/work.cpp2
-rw-r--r--logic/work.hpp2
8 files changed, 27 insertions, 22 deletions
diff --git a/logic/mappings.cpp b/logic/mappings.cpp
index d7764375..bae8c2c0 100644
--- a/logic/mappings.cpp
+++ b/logic/mappings.cpp
@@ -11,10 +11,10 @@ Map::Map(QString primary, QString secondary, int max_x, int max_y, axis_opts& op
spline_alt.set_max_input(opts.clamp);
}
-void Map::save(QSettings& s)
+void Map::save()
{
- spline_main.save(s);
- spline_alt.save(s);
+ spline_main.save();
+ spline_alt.save();
}
void Map::load()
diff --git a/logic/mappings.hpp b/logic/mappings.hpp
index 4e0f7218..b3587749 100644
--- a/logic/mappings.hpp
+++ b/logic/mappings.hpp
@@ -17,7 +17,7 @@ struct OTR_LOGIC_EXPORT Map final
{
Map(QString primary, QString secondary, int max_x, int max_y, axis_opts& opts);
- void save(QSettings& s);
+ void save();
void load();
axis_opts& opts;
diff --git a/logic/selected-libraries.hpp b/logic/selected-libraries.hpp
index 689cbec3..65e9733e 100644
--- a/logic/selected-libraries.hpp
+++ b/logic/selected-libraries.hpp
@@ -15,11 +15,14 @@
struct OTR_LOGIC_EXPORT SelectedLibraries
{
- using dylibptr = mem<dylib>;
- mem<ITracker> pTracker;
- mem<IFilter> pFilter;
- mem<IProtocol> pProtocol;
+ using dylibptr = std::shared_ptr<dylib>;
+
+ std::shared_ptr<ITracker> pTracker;
+ std::shared_ptr<IFilter> pFilter;
+ std::shared_ptr<IProtocol> pProtocol;
+
SelectedLibraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f);
SelectedLibraries() : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), correct(false) {}
+
bool correct;
};
diff --git a/logic/state.hpp b/logic/state.hpp
index f5892557..8bef71ad 100644
--- a/logic/state.hpp
+++ b/logic/state.hpp
@@ -26,5 +26,5 @@ struct State
Modules modules;
main_settings s;
Mappings pose;
- mem<Work> work;
+ std::shared_ptr<Work> work;
};
diff --git a/logic/tracker.cpp b/logic/tracker.cpp
index 7411d3b4..8367ee2f 100644
--- a/logic/tracker.cpp
+++ b/logic/tracker.cpp
@@ -24,6 +24,7 @@
using namespace euler;
using namespace gui_tracker_impl;
+using namespace time_units;
constexpr double Tracker::r2d;
constexpr double Tracker::d2r;
@@ -32,7 +33,7 @@ Tracker::Tracker(Mappings& m, SelectedLibraries& libs, TrackLogger& logger) :
m(m),
libs(libs),
logger(logger),
- backlog_time(0),
+ backlog_time(ns(0)),
tracking_started(false)
{
}
@@ -403,21 +404,22 @@ void Tracker::run()
{
logic();
- static constexpr long const_sleep_us = 4000;
- const long elapsed_usecs = t.elapsed_usecs();
- t.start();
+ static constexpr ns const_sleep_ms(time_cast<ns>(ms(4)));
+ const ns elapsed_nsecs = prog1(t.elapsed<ns>(), t.start());
- backlog_time += elapsed_usecs - const_sleep_us;
+ backlog_time += ns(elapsed_nsecs - const_sleep_ms);
- if (std::fabs(backlog_time) > 3000 * 1000)
+ if (backlog_time > secs_(3) || backlog_time < secs_(-3))
{
- qDebug() << "tracker: backlog interval overflow" << backlog_time;
- backlog_time = 0;
+ qDebug() << "tracker: backlog interval overflow"
+ << time_cast<ms>(backlog_time).count() << "ms";
+ backlog_time = backlog_time.zero();
}
- const unsigned sleep_time = unsigned(std::round(clamp((const_sleep_us - backlog_time)/1000., 0, const_sleep_us*2.5/1000)));
+ const int sleep_time_ms = iround(clamp(const_sleep_ms - backlog_time,
+ ns(0), ms(50)).count());
- portable::sleep(sleep_time);
+ portable::sleep(sleep_time_ms);
}
{
diff --git a/logic/tracker.h b/logic/tracker.h
index 85bd1ed8..2f29aca7 100644
--- a/logic/tracker.h
+++ b/logic/tracker.h
@@ -85,7 +85,7 @@ private:
state real_rotation, scaled_rotation;
euler_t t_center;
- long backlog_time;
+ time_units::ns backlog_time;
bool tracking_started;
diff --git a/logic/work.cpp b/logic/work.cpp
index 7b9e550e..6829e62b 100644
--- a/logic/work.cpp
+++ b/logic/work.cpp
@@ -60,7 +60,7 @@ std::shared_ptr<TrackLogger> Work::make_logger(main_settings &s)
}
-Work::Work(Mappings& m, QFrame* frame, mem<dylib> tracker_, mem<dylib> filter_, mem<dylib> proto_) :
+Work::Work(Mappings& m, 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)),
diff --git a/logic/work.hpp b/logic/work.hpp
index f1d5e401..dc32536c 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, mem<dylib> tracker, mem<dylib> filter, mem<dylib> proto);
+ Work(Mappings& m, 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;