2018-02-09 21:31:05 +00:00
|
|
|
//
|
|
|
|
// MultiJoystickMachine.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 09/02/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-02-09 21:31:05 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "MultiJoystickMachine.hpp"
|
|
|
|
|
2018-03-23 22:05:51 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2018-02-09 21:31:05 +00:00
|
|
|
using namespace Analyser::Dynamic;
|
|
|
|
|
2018-03-22 15:07:52 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MultiJoystick: public Inputs::Joystick {
|
|
|
|
public:
|
2020-04-02 03:19:34 +00:00
|
|
|
MultiJoystick(std::vector<MachineTypes::JoystickMachine *> &machines, std::size_t index) {
|
2018-03-22 15:07:52 +00:00
|
|
|
for(const auto &machine: machines) {
|
|
|
|
const auto &joysticks = machine->get_joysticks();
|
|
|
|
if(joysticks.size() >= index) {
|
|
|
|
joysticks_.push_back(joysticks[index].get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 04:31:16 +00:00
|
|
|
const std::vector<Input> &get_inputs() final {
|
2018-06-12 01:35:03 +00:00
|
|
|
if(inputs.empty()) {
|
|
|
|
for(const auto &joystick: joysticks_) {
|
|
|
|
std::vector<Input> joystick_inputs = joystick->get_inputs();
|
|
|
|
for(const auto &input: joystick_inputs) {
|
|
|
|
if(std::find(inputs.begin(), inputs.end(), input) != inputs.end()) {
|
|
|
|
inputs.push_back(input);
|
|
|
|
}
|
2018-03-22 15:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
}
|
|
|
|
|
2020-01-24 03:57:51 +00:00
|
|
|
void set_input(const Input &digital_input, bool is_active) final {
|
2018-03-22 15:07:52 +00:00
|
|
|
for(const auto &joystick: joysticks_) {
|
2018-06-11 00:45:52 +00:00
|
|
|
joystick->set_input(digital_input, is_active);
|
2018-03-22 15:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-12 01:35:03 +00:00
|
|
|
|
2020-01-24 03:57:51 +00:00
|
|
|
void set_input(const Input &digital_input, float value) final {
|
2018-06-12 01:35:03 +00:00
|
|
|
for(const auto &joystick: joysticks_) {
|
|
|
|
joystick->set_input(digital_input, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 03:57:51 +00:00
|
|
|
void reset_all_inputs() final {
|
2018-03-22 15:07:52 +00:00
|
|
|
for(const auto &joystick: joysticks_) {
|
|
|
|
joystick->reset_all_inputs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 01:35:03 +00:00
|
|
|
std::vector<Input> inputs;
|
2018-03-22 15:07:52 +00:00
|
|
|
std::vector<Inputs::Joystick *> joysticks_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-09 21:31:05 +00:00
|
|
|
MultiJoystickMachine::MultiJoystickMachine(const std::vector<std::unique_ptr<::Machine::DynamicMachine>> &machines) {
|
2018-03-22 15:07:52 +00:00
|
|
|
std::size_t total_joysticks = 0;
|
2020-04-02 03:19:34 +00:00
|
|
|
std::vector<MachineTypes::JoystickMachine *> joystick_machines;
|
2018-02-09 21:31:05 +00:00
|
|
|
for(const auto &machine: machines) {
|
2020-04-02 03:19:34 +00:00
|
|
|
auto joystick_machine = machine->joystick_machine();
|
2018-03-22 15:07:52 +00:00
|
|
|
if(joystick_machine) {
|
|
|
|
joystick_machines.push_back(joystick_machine);
|
|
|
|
total_joysticks = std::max(total_joysticks, joystick_machine->get_joysticks().size());
|
|
|
|
}
|
2018-05-05 23:32:20 +00:00
|
|
|
}
|
2018-03-22 15:07:52 +00:00
|
|
|
|
|
|
|
for(std::size_t index = 0; index < total_joysticks; ++index) {
|
|
|
|
joysticks_.emplace_back(new MultiJoystick(joystick_machines, index));
|
|
|
|
}
|
2018-02-09 21:31:05 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 23:19:05 +00:00
|
|
|
const std::vector<std::unique_ptr<Inputs::Joystick>> &MultiJoystickMachine::get_joysticks() {
|
2018-02-09 21:31:05 +00:00
|
|
|
return joysticks_;
|
|
|
|
}
|