From 359875cf3328fbf8fbfe83fd8c061dd27d836bc2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 12 Nov 2016 12:01:59 +0100 Subject: logic/tracker: move from header --- logic/tracker.cpp | 39 ++++++++++++++++++++++++++++++++++++++- logic/tracker.h | 44 ++++++-------------------------------------- 2 files changed, 44 insertions(+), 39 deletions(-) (limited to 'logic') diff --git a/logic/tracker.cpp b/logic/tracker.cpp index 448cb9de..8757e98e 100644 --- a/logic/tracker.cpp +++ b/logic/tracker.cpp @@ -30,7 +30,7 @@ using namespace euler; constexpr double Tracker::r2d; constexpr double Tracker::d2r; -Tracker::Tracker(Mappings &m, SelectedLibraries &libs, TrackLogger &logger) : +Tracker::Tracker(Mappings& m, SelectedLibraries& libs, TrackLogger& logger) : m(m), libs(libs), logger(logger), @@ -449,3 +449,40 @@ void Tracker::get_raw_and_mapped_poses(double* mapped, double* raw) const } } + +void bits::set(bits::flags flag_, bool val_) +{ + unsigned b_(b); + const unsigned flag = unsigned(flag_); + const unsigned val = unsigned(!!val_); + while (!b.compare_exchange_weak(b_, + unsigned((b_ & ~flag) | (flag * val)), + std::memory_order_seq_cst, + std::memory_order_seq_cst)) + { /* empty */ } +} + +void bits::negate(bits::flags flag_) +{ + unsigned b_(b); + const unsigned flag = unsigned(flag_); + while (!b.compare_exchange_weak(b_, + (b_ & ~flag) | (flag & ~b_), + std::memory_order_seq_cst, + std::memory_order_seq_cst)) + { /* empty */ } +} + +bool bits::get(bits::flags flag) +{ + return !!(b & flag); +} + +bits::bits() : b(0u) +{ + set(f_center, true); + set(f_enabled, true); + set(f_zero, false); + set(f_tcomp_disabled, false); + set(f_should_quit, false); +} diff --git a/logic/tracker.h b/logic/tracker.h index 9230ef98..b9012910 100644 --- a/logic/tracker.h +++ b/logic/tracker.h @@ -43,42 +43,10 @@ struct bits std::atomic b; - void set(flags flag_, bool val_) - { - unsigned b_(b); - const unsigned flag = unsigned(flag_); - const unsigned val = unsigned(!!val_); - while (!b.compare_exchange_weak(b_, - unsigned((b_ & ~flag) | (flag * val)), - std::memory_order_seq_cst, - std::memory_order_seq_cst)) - { /* empty */ } - } - - void negate(flags flag_) - { - unsigned b_(b); - const unsigned flag = unsigned(flag_); - while (!b.compare_exchange_weak(b_, - (b_ & ~flag) | (flag & ~b_), - std::memory_order_seq_cst, - std::memory_order_seq_cst)) - { /* empty */ } - } - - bool get(flags flag) - { - return !!(b & flag); - } - - bits() : b(0u) - { - set(f_center, true); - set(f_enabled, true); - set(f_zero, false); - set(f_tcomp_disabled, false); - set(f_should_quit, false); - } + void set(flags flag_, bool val_); + void negate(flags flag_); + bool get(flags flag); + bits(); }; class OPENTRACK_LOGIC_EXPORT Tracker : private QThread, private bits @@ -100,7 +68,7 @@ private: // The owner of the reference is the main window. // This design might be usefull if we decide later on to swap out // the logger while the tracker is running. - TrackLogger &logger; + TrackLogger& logger; struct state { @@ -131,7 +99,7 @@ private: static constexpr double c_mult = 4; static constexpr double c_div = 1./c_mult; public: - Tracker(Mappings& m, SelectedLibraries& libs, TrackLogger &logger); + Tracker(Mappings& m, SelectedLibraries& libs, TrackLogger& logger); ~Tracker(); rmat get_camera_offset_matrix(double c); -- cgit v1.2.3