diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp index 16a63b32e7..b276f30c0f 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp @@ -94,19 +94,25 @@ void MultiSwitchProgramSession::run_program_instance(MultiSwitchProgramEnvironme } // Startup Checks + std::deque> contexts; size_t consoles = m_system.count(); - for (size_t c = 0; c < consoles; c++){ + for (size_t console = 0; console < consoles; console++){ m_option.instance().start_program_controller_check( - m_system[c].controller(), c + m_system[console].controller(), console ); m_option.instance().start_program_feedback_check( - env.consoles[c], c, + env.consoles[console], console, m_option.descriptor().feedback() ); m_option.instance().start_program_border_check( - env.consoles[c], c, + env.consoles[console], console, m_option.descriptor().feedback() ); + + size_t controllers = env.consoles[console].controllers(); + for (size_t controller = 0; controller < controllers; controller++){ + contexts.emplace_back(scope, env.consoles[console].controller(controller)); + } } { @@ -146,22 +152,24 @@ void MultiSwitchProgramSession::internal_stop_program(){ } } void MultiSwitchProgramSession::internal_run_program(){ - CancellableHolder download_scope; { - std::lock_guard lg(program_lock()); - if (current_state() != ProgramState::RUNNING){ - return; + CancellableHolder download_scope; + { + std::lock_guard lg(program_lock()); + if (current_state() != ProgramState::RUNNING){ + return; + } + m_scope.store(&download_scope, std::memory_order_release); } - m_scope.store(&download_scope, std::memory_order_release); - } - bool success = download_prereqs(download_scope); - { - std::lock_guard lg(program_lock()); - m_scope.store(nullptr, std::memory_order_release); - } - if (!success){ - return; + bool success = download_prereqs(download_scope); + { + std::lock_guard lg(program_lock()); + m_scope.store(nullptr, std::memory_order_release); + } + if (!success){ + return; + } } auto ScopeCheck = m_sanitizer.check_scope(); @@ -180,7 +188,6 @@ void MultiSwitchProgramSession::internal_run_program(){ ); size_t consoles = m_system.count(); - FixedLimitVector null_controller_placeholders(consoles); FixedLimitVector handles(consoles); for (size_t c = 0; c < consoles; c++){ SwitchSystemSession& session = m_system[c]; diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp index f79508e29d..09f7f08fee 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp @@ -8,6 +8,7 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/EarlyShutdown.h" #include "Common/Cpp/Concurrency/SpinPause.h" +#include "Common/Cpp/Containers/FixedLimitVector.tpp" #include "CommonFramework/GlobalSettingsPanel.h" #include "CommonFramework/Exceptions/FatalProgramException.h" #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" @@ -15,7 +16,6 @@ #include "CommonFramework/Options/Environment/SleepSuppressOption.h" #include "CommonFramework/Notifications/ProgramInfo.h" #include "CommonFramework/Notifications/ProgramNotifications.h" -#include "Controllers/NullController.h" #include "NintendoSwitch/NintendoSwitch_Settings.h" #include "NintendoSwitch_SingleSwitchProgramOption.h" #include "NintendoSwitch_SingleSwitchProgramSession.h" @@ -89,13 +89,17 @@ void SingleSwitchProgramSession::run_program_instance(SingleSwitchProgramEnviron m_option.descriptor().feedback() ); - ControllerContext context(scope, env.console.controller()); + size_t controllers = env.console.controllers(); + FixedLimitVector> contexts(controllers); + for (size_t c = 0; c < controllers; c++){ + contexts.emplace_back(scope, env.console.controller(c)); + } { std::lock_guard lg(program_lock()); if (current_state() != ProgramState::RUNNING){ return; } - m_scope.store(&context, std::memory_order_release); + m_scope.store(&scope, std::memory_order_release); } ScopeExit on_exit([&, this]{ @@ -104,8 +108,8 @@ void SingleSwitchProgramSession::run_program_instance(SingleSwitchProgramEnviron m_scope.store(nullptr, std::memory_order_release); }); - m_option.instance().program(env, context); - context.wait_for_all_requests(); + m_option.instance().program(env, scope); + env.console.wait_for_all_controllers(); } void SingleSwitchProgramSession::internal_stop_program(){ { @@ -122,22 +126,24 @@ void SingleSwitchProgramSession::internal_stop_program(){ } } void SingleSwitchProgramSession::internal_run_program(){ - CancellableHolder scope; { - std::lock_guard lg(program_lock()); - if (current_state() != ProgramState::RUNNING){ - return; + CancellableHolder scope; + { + std::lock_guard lg(program_lock()); + if (current_state() != ProgramState::RUNNING){ + return; + } + m_scope.store(&scope, std::memory_order_release); + } + bool success = download_prereqs(scope); + { + std::lock_guard lg(program_lock()); + m_scope.store(nullptr, std::memory_order_release); } - m_scope.store(&scope, std::memory_order_release); - } - bool success = download_prereqs(scope); - { - std::lock_guard lg(program_lock()); - m_scope.store(nullptr, std::memory_order_release); - } - if (!success){ - return; + if (!success){ + return; + } } m_option.options().reset_state(); @@ -150,15 +156,10 @@ void SingleSwitchProgramSession::internal_run_program(){ m_option.descriptor().display_name(), timestamp() ); - NullController null_controller(m_system.logger()); - AbstractController* controller = m_system.controller().controller(); - if (controller == nullptr){ - controller = &null_controller; - } - ControllerContext context(*controller); + CancellableHolder scope; SingleSwitchProgramEnvironment env( program_info, - context, + scope, *this, current_stats_tracker(), historical_stats_tracker(), m_system @@ -175,7 +176,7 @@ void SingleSwitchProgramSession::internal_run_program(){ logger().log("Starting Program: " + identifier() + ""); env.console.overlay().clear_log(); env.console.overlay().add_log("- Starting Program -"); - run_program_instance(env, context); + run_program_instance(env, scope); env.console.overlay().add_log("- Program Finished -"); logger().log("Program finished normally!", COLOR_BLUE); }catch (OperationCancelledException&){