Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,25 @@ void MultiSwitchProgramSession::run_program_instance(MultiSwitchProgramEnvironme
}

// Startup Checks
std::deque<ControllerContext<AbstractController>> 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));
}
}

{
Expand Down Expand Up @@ -146,22 +152,24 @@ void MultiSwitchProgramSession::internal_stop_program(){
}
}
void MultiSwitchProgramSession::internal_run_program(){
CancellableHolder<CancellableScope> download_scope;
{
std::lock_guard<Mutex> lg(program_lock());
if (current_state() != ProgramState::RUNNING){
return;
CancellableHolder<CancellableScope> download_scope;
{
std::lock_guard<Mutex> 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<Mutex> lg(program_lock());
m_scope.store(nullptr, std::memory_order_release);
}
if (!success){
return;
bool success = download_prereqs(download_scope);
{
std::lock_guard<Mutex> lg(program_lock());
m_scope.store(nullptr, std::memory_order_release);
}
if (!success){
return;
}
}

auto ScopeCheck = m_sanitizer.check_scope();
Expand All @@ -180,7 +188,6 @@ void MultiSwitchProgramSession::internal_run_program(){
);

size_t consoles = m_system.count();
FixedLimitVector<NullController> null_controller_placeholders(consoles);
FixedLimitVector<ConsoleHandle> handles(consoles);
for (size_t c = 0; c < consoles; c++){
SwitchSystemSession& session = m_system[c];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#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"
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
#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"
Expand Down Expand Up @@ -89,13 +89,17 @@ void SingleSwitchProgramSession::run_program_instance(SingleSwitchProgramEnviron
m_option.descriptor().feedback()
);

ControllerContext<AbstractController> context(scope, env.console.controller());
size_t controllers = env.console.controllers();
FixedLimitVector<ControllerContext<AbstractController>> contexts(controllers);
for (size_t c = 0; c < controllers; c++){
contexts.emplace_back(scope, env.console.controller(c));
}
{
std::lock_guard<Mutex> 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]{
Expand All @@ -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(){
{
Expand All @@ -122,22 +126,24 @@ void SingleSwitchProgramSession::internal_stop_program(){
}
}
void SingleSwitchProgramSession::internal_run_program(){
CancellableHolder<CancellableScope> scope;
{
std::lock_guard<Mutex> lg(program_lock());
if (current_state() != ProgramState::RUNNING){
return;
CancellableHolder<CancellableScope> scope;
{
std::lock_guard<Mutex> 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<Mutex> 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<Mutex> lg(program_lock());
m_scope.store(nullptr, std::memory_order_release);
}

if (!success){
return;
if (!success){
return;
}
}

m_option.options().reset_state();
Expand All @@ -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<AbstractController> context(*controller);
CancellableHolder<CancellableScope> scope;
SingleSwitchProgramEnvironment env(
program_info,
context,
scope,
*this,
current_stats_tracker(), historical_stats_tracker(),
m_system
Expand All @@ -175,7 +176,7 @@ void SingleSwitchProgramSession::internal_run_program(){
logger().log("<b>Starting Program: " + identifier() + "</b>");
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&){
Expand Down