2018-01-29 03:22:21 +00:00
|
|
|
//
|
|
|
|
// MultiMachine.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 28/01/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "MultiMachine.hpp"
|
|
|
|
|
|
|
|
using namespace Analyser::Dynamic;
|
|
|
|
|
|
|
|
MultiMachine::MultiMachine(std::vector<std::unique_ptr<DynamicMachine>> &&machines) :
|
2018-01-30 02:49:49 +00:00
|
|
|
machines_(std::move(machines)),
|
2018-02-09 21:31:05 +00:00
|
|
|
configurable_(machines_),
|
2018-01-31 03:23:06 +00:00
|
|
|
configuration_target_(machines_),
|
2018-02-11 00:38:26 +00:00
|
|
|
crt_machine_(machines_, machines_mutex_),
|
2018-02-09 21:31:05 +00:00
|
|
|
joystick_machine_(machines),
|
|
|
|
keyboard_machine_(machines_) {
|
2018-02-01 12:53:52 +00:00
|
|
|
crt_machine_.set_delegate(this);
|
|
|
|
}
|
2018-01-29 03:22:21 +00:00
|
|
|
|
|
|
|
ConfigurationTarget::Machine *MultiMachine::configuration_target() {
|
2018-01-30 02:49:49 +00:00
|
|
|
return &configuration_target_;
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRTMachine::Machine *MultiMachine::crt_machine() {
|
2018-01-31 03:23:06 +00:00
|
|
|
return &crt_machine_;
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JoystickMachine::Machine *MultiMachine::joystick_machine() {
|
2018-02-09 21:31:05 +00:00
|
|
|
return &joystick_machine_;
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardMachine::Machine *MultiMachine::keyboard_machine() {
|
2018-02-09 21:31:05 +00:00
|
|
|
return &keyboard_machine_;
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Configurable::Device *MultiMachine::configurable_device() {
|
2018-02-09 21:31:05 +00:00
|
|
|
return &configurable_;
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
2018-02-01 12:53:52 +00:00
|
|
|
|
|
|
|
void MultiMachine::multi_crt_did_run_machines() {
|
2018-02-11 00:38:26 +00:00
|
|
|
std::lock_guard<std::mutex> machines_lock(machines_mutex_);
|
2018-02-01 12:53:52 +00:00
|
|
|
DynamicMachine *front = machines_.front().get();
|
|
|
|
// for(const auto &machine: machines_) {
|
|
|
|
// CRTMachine::Machine *crt = machine->crt_machine();
|
|
|
|
// printf("%0.2f ", crt->get_confidence());
|
|
|
|
// crt->print_type();
|
|
|
|
// printf("; ");
|
|
|
|
// }
|
|
|
|
// printf("\n");
|
2018-02-11 00:38:26 +00:00
|
|
|
|
2018-02-01 12:53:52 +00:00
|
|
|
std::stable_sort(machines_.begin(), machines_.end(), [] (const auto &lhs, const auto &rhs){
|
|
|
|
CRTMachine::Machine *lhs_crt = lhs->crt_machine();
|
|
|
|
CRTMachine::Machine *rhs_crt = rhs->crt_machine();
|
|
|
|
return lhs_crt->get_confidence() > rhs_crt->get_confidence();
|
|
|
|
});
|
|
|
|
|
|
|
|
if(machines_.front().get() != front) {
|
|
|
|
crt_machine_.did_change_machine_order();
|
|
|
|
}
|
|
|
|
}
|