From 2c25135d8a0a4e295f430689fc5ac09d4de0dc0b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 9 Nov 2019 18:19:05 -0500 Subject: [PATCH] Fixes const correctness for joystick machines; the ST is now one such. --- .../MultiMachine/Implementation/MultiJoystickMachine.cpp | 2 +- .../MultiMachine/Implementation/MultiJoystickMachine.hpp | 2 +- Machines/AmstradCPC/AmstradCPC.cpp | 4 ++-- Machines/Apple/AppleII/AppleII.cpp | 2 +- Machines/Atari/2600/Atari2600.cpp | 2 +- Machines/Atari/ST/AtariST.cpp | 7 +++++++ Machines/Atari/ST/IntelligentKeyboard.hpp | 8 ++++++++ Machines/ColecoVision/ColecoVision.cpp | 2 +- Machines/Commodore/Vic-20/Vic20.cpp | 2 +- Machines/JoystickMachine.hpp | 2 +- Machines/MSX/MSX.cpp | 4 ++-- Machines/MasterSystem/MasterSystem.cpp | 2 +- OSBindings/Mac/Clock Signal/Machine/CSMachine.mm | 6 +++--- OSBindings/SDL/main.cpp | 4 ++-- 14 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp index 526b43749..70255b13e 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.cpp @@ -81,6 +81,6 @@ MultiJoystickMachine::MultiJoystickMachine(const std::vector> &MultiJoystickMachine::get_joysticks() { +const std::vector> &MultiJoystickMachine::get_joysticks() { return joysticks_; } diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp index f755d3061..6425a9a0a 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiJoystickMachine.hpp @@ -28,7 +28,7 @@ class MultiJoystickMachine: public JoystickMachine::Machine { MultiJoystickMachine(const std::vector> &machines); // Below is the standard JoystickMachine::Machine interface; see there for documentation. - std::vector> &get_joysticks() override; + const std::vector> &get_joysticks() override; private: std::vector> joysticks_; diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 6ebd9d5b6..bf869cf12 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -604,7 +604,7 @@ class KeyboardState: public GI::AY38910::PortHandler { memset(rows_, 0xff, sizeof(rows_)); } - std::vector> &get_joysticks() { + const std::vector> &get_joysticks() { return joysticks_; } @@ -1093,7 +1093,7 @@ template class ConcreteMachine: } // MARK: - Joysticks - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return key_state_.get_joysticks(); } diff --git a/Machines/Apple/AppleII/AppleII.cpp b/Machines/Apple/AppleII/AppleII.cpp index 3757092e1..f561059ca 100644 --- a/Machines/Apple/AppleII/AppleII.cpp +++ b/Machines/Apple/AppleII/AppleII.cpp @@ -893,7 +893,7 @@ template class ConcreteMachine: } // MARK: JoystickMachine - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return joysticks_; } }; diff --git a/Machines/Atari/2600/Atari2600.cpp b/Machines/Atari/2600/Atari2600.cpp index 3b2afe210..f1bce4903 100644 --- a/Machines/Atari/2600/Atari2600.cpp +++ b/Machines/Atari/2600/Atari2600.cpp @@ -124,7 +124,7 @@ class ConcreteMachine: joysticks_.emplace_back(new Joystick(bus_.get(), 4, 1)); } - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return joysticks_; } diff --git a/Machines/Atari/ST/AtariST.cpp b/Machines/Atari/ST/AtariST.cpp index e100043f8..413b94acb 100644 --- a/Machines/Atari/ST/AtariST.cpp +++ b/Machines/Atari/ST/AtariST.cpp @@ -9,6 +9,7 @@ #include "AtariST.hpp" #include "../../CRTMachine.hpp" +#include "../../JoystickMachine.hpp" #include "../../KeyboardMachine.hpp" #include "../../MouseMachine.hpp" #include "../../MediaTarget.hpp" @@ -49,6 +50,7 @@ class ConcreteMachine: public Motorola::MFP68901::MFP68901::InterruptDelegate, public DMAController::Delegate, public MouseMachine::Machine, + public JoystickMachine::Machine, public KeyboardMachine::MappedMachine, public Activity::Source, public MediaTarget::Machine, @@ -527,6 +529,11 @@ class ConcreteMachine: return &keyboard_mapper_; } + // MARK: - JoystickMachine + const std::vector> &get_joysticks() final { + return ikbd_.get_joysticks(); + } + // MARK: - AYPortHandler void set_port_output(bool port_b, uint8_t value) final { if(port_b) { diff --git a/Machines/Atari/ST/IntelligentKeyboard.hpp b/Machines/Atari/ST/IntelligentKeyboard.hpp index f81cfcc08..77d5b0642 100644 --- a/Machines/Atari/ST/IntelligentKeyboard.hpp +++ b/Machines/Atari/ST/IntelligentKeyboard.hpp @@ -13,10 +13,13 @@ #include "../../../Components/Serial/Line.hpp" #include "../../KeyboardMachine.hpp" +#include "../../../Inputs/Joystick.hpp" #include "../../../Inputs/Mouse.hpp" #include #include +#include +#include namespace Atari { namespace ST { @@ -61,6 +64,10 @@ class IntelligentKeyboard: uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) final; }; + const std::vector> &get_joysticks() { + return joysticks_; + } + private: // MARK: - Key queue. std::mutex key_queue_mutex_; @@ -128,6 +135,7 @@ class IntelligentKeyboard: enum class JoystickMode { Disabled, Event, Interrogation } joystick_mode_ = JoystickMode::Event; + std::vector> joysticks_; }; } diff --git a/Machines/ColecoVision/ColecoVision.cpp b/Machines/ColecoVision/ColecoVision.cpp index 371cca534..c3386d633 100644 --- a/Machines/ColecoVision/ColecoVision.cpp +++ b/Machines/ColecoVision/ColecoVision.cpp @@ -177,7 +177,7 @@ class ConcreteMachine: audio_queue_.flush(); } - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return joysticks_; } diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 4c65dc304..cb7682c80 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -494,7 +494,7 @@ class ConcreteMachine: keyboard_via_port_handler_->clear_all_keys(); } - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return joysticks_; } diff --git a/Machines/JoystickMachine.hpp b/Machines/JoystickMachine.hpp index 15c74e2eb..ae884cc25 100644 --- a/Machines/JoystickMachine.hpp +++ b/Machines/JoystickMachine.hpp @@ -16,7 +16,7 @@ namespace JoystickMachine { class Machine { public: - virtual std::vector> &get_joysticks() = 0; + virtual const std::vector> &get_joysticks() = 0; }; } diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index 0c00ab83d..bed05c068 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -89,7 +89,7 @@ class AYPortHandler: public GI::AY38910::PortHandler { return 0xff; } - std::vector> &get_joysticks() { + const std::vector> &get_joysticks() { return joysticks_; } @@ -686,7 +686,7 @@ class ConcreteMachine: } // MARK: - Joysticks - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return ay_port_handler_.get_joysticks(); } diff --git a/Machines/MasterSystem/MasterSystem.cpp b/Machines/MasterSystem/MasterSystem.cpp index a005b4e3d..b32453eda 100644 --- a/Machines/MasterSystem/MasterSystem.cpp +++ b/Machines/MasterSystem/MasterSystem.cpp @@ -340,7 +340,7 @@ class ConcreteMachine: audio_queue_.perform(); } - std::vector> &get_joysticks() override { + const std::vector> &get_joysticks() override { return joysticks_; } diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index a8160f139..5723930f6 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -268,7 +268,7 @@ struct ActivityObserver: public Activity::Observer { // Until then, apply a default mapping. size_t c = 0; - std::vector> &machine_joysticks = _joystickMachine->get_joysticks(); + auto &machine_joysticks = _joystickMachine->get_joysticks(); for(CSJoystick *joystick in _joystickManager.joysticks) { size_t target = c % machine_joysticks.size(); ++c; @@ -373,7 +373,7 @@ struct ActivityObserver: public Activity::Observer { @synchronized(self) { _joystickManager = joystickManager; if(_joystickMachine) { - std::vector> &machine_joysticks = _joystickMachine->get_joysticks(); + auto &machine_joysticks = _joystickMachine->get_joysticks(); for(const auto &joystick: machine_joysticks) { joystick->reset_all_inputs(); } @@ -467,7 +467,7 @@ struct ActivityObserver: public Activity::Observer { auto joystick_machine = _machine->joystick_machine(); if(self.inputMode == CSMachineKeyboardInputModeJoystick && joystick_machine) { @synchronized(self) { - std::vector> &joysticks = joystick_machine->get_joysticks(); + auto &joysticks = joystick_machine->get_joysticks(); if(!joysticks.empty()) { // Convert to a C++ bool so that the following calls are resolved correctly even if overloaded. bool is_pressed = !!isPressed; diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index cde2106fa..337c5c26b 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -741,7 +741,7 @@ int main(int argc, char *argv[]) { JoystickMachine::Machine *const joystick_machine = machine->joystick_machine(); if(joystick_machine) { - std::vector> &joysticks = joystick_machine->get_joysticks(); + auto &joysticks = joystick_machine->get_joysticks(); if(!joysticks.empty()) { switch(event.key.keysym.scancode) { case SDL_SCANCODE_LEFT: joysticks[0]->set_input(Inputs::Joystick::Input::Left, is_pressed); break; @@ -791,7 +791,7 @@ int main(int argc, char *argv[]) { // Push new joystick state, if any. JoystickMachine::Machine *const joystick_machine = machine->joystick_machine(); if(joystick_machine) { - std::vector> &machine_joysticks = joystick_machine->get_joysticks(); + auto &machine_joysticks = joystick_machine->get_joysticks(); for(size_t c = 0; c < joysticks.size(); ++c) { size_t target = c % machine_joysticks.size();