diff --git a/src/core/system.cpp b/src/core/system.cpp index 50faa1867..b861fada4 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -41,14 +41,9 @@ Log_SetChannel(System); SystemBootParameters::SystemBootParameters() = default; -SystemBootParameters::SystemBootParameters(std::string filename_) : filename(filename_) {} +SystemBootParameters::SystemBootParameters(SystemBootParameters&& other) = default; -SystemBootParameters::SystemBootParameters(const SystemBootParameters& copy) - : filename(copy.filename), override_fast_boot(copy.override_fast_boot), override_fullscreen(copy.override_fullscreen) -{ - // only exists for qt, we can't copy the state stream - Assert(!copy.state_stream); -} +SystemBootParameters::SystemBootParameters(std::string filename_) : filename(std::move(filename_)) {} SystemBootParameters::~SystemBootParameters() = default; diff --git a/src/core/system.h b/src/core/system.h index 938bee0d7..6b0085099 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -19,8 +19,8 @@ class CheatList; struct SystemBootParameters { SystemBootParameters(); + SystemBootParameters(SystemBootParameters&& other); SystemBootParameters(std::string filename_); - SystemBootParameters(const SystemBootParameters& copy); ~SystemBootParameters(); std::string filename; diff --git a/src/duckstation-qt/main.cpp b/src/duckstation-qt/main.cpp index c30fc6a52..66bf4bf51 100644 --- a/src/duckstation-qt/main.cpp +++ b/src/duckstation-qt/main.cpp @@ -28,7 +28,7 @@ int main(int argc, char* argv[]) std::unique_ptr host_interface = std::make_unique(); std::unique_ptr boot_params; - if (!host_interface->parseCommandLineParameters(argc, argv, &boot_params)) + if (!host_interface->ParseCommandLineParameters(argc, argv, &boot_params)) return EXIT_FAILURE; if (!host_interface->Initialize()) @@ -48,8 +48,7 @@ int main(int argc, char* argv[]) if (boot_params) { - host_interface->bootSystem(*boot_params); - boot_params.reset(); + host_interface->bootSystem(std::move(boot_params)); } else { diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index ccd342957..985de0256 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -269,15 +269,12 @@ void MainWindow::onStartDiscActionTriggered() if (filename.isEmpty()) return; - SystemBootParameters boot_params; - boot_params.filename = filename.toStdString(); - m_host_interface->bootSystem(boot_params); + m_host_interface->bootSystem(std::make_shared(filename.toStdString())); } void MainWindow::onStartBIOSActionTriggered() { - SystemBootParameters boot_params; - m_host_interface->bootSystem(boot_params); + m_host_interface->bootSystem(std::make_shared()); } void MainWindow::onChangeDiscFromFileActionTriggered() @@ -391,9 +388,7 @@ void MainWindow::onGameListEntryDoubleClicked(const GameListEntry* entry) } else { - SystemBootParameters boot_params; - boot_params.filename = path.toStdString(); - m_host_interface->bootSystem(boot_params); + m_host_interface->bootSystem(std::make_shared(path.toStdString())); } } else @@ -429,19 +424,20 @@ void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameL menu.addSeparator(); } - connect(menu.addAction(tr("Default Boot")), &QAction::triggered, - [this, entry]() { m_host_interface->bootSystem(SystemBootParameters(entry->path)); }); + connect(menu.addAction(tr("Default Boot")), &QAction::triggered, [this, entry]() { + m_host_interface->bootSystem(std::make_shared(entry->path)); + }); connect(menu.addAction(tr("Fast Boot")), &QAction::triggered, [this, entry]() { - SystemBootParameters boot_params(entry->path); - boot_params.override_fast_boot = true; - m_host_interface->bootSystem(boot_params); + auto boot_params = std::make_shared(entry->path); + boot_params->override_fast_boot = true; + m_host_interface->bootSystem(std::move(boot_params)); }); connect(menu.addAction(tr("Full Boot")), &QAction::triggered, [this, entry]() { - SystemBootParameters boot_params(entry->path); - boot_params.override_fast_boot = false; - m_host_interface->bootSystem(boot_params); + auto boot_params = std::make_shared(entry->path); + boot_params->override_fast_boot = false; + m_host_interface->bootSystem(std::move(boot_params)); }); } else diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index b781cdb6a..943043390 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -44,7 +44,7 @@ Log_SetChannel(QtHostInterface); QtHostInterface::QtHostInterface(QObject* parent) : QObject(parent), CommonHostInterface() { - qRegisterMetaType(); + qRegisterMetaType>(); } QtHostInterface::~QtHostInterface() @@ -171,12 +171,6 @@ bool QtHostInterface::ConfirmMessage(const char* message) return result; } -bool QtHostInterface::parseCommandLineParameters(int argc, char* argv[], - std::unique_ptr* out_boot_params) -{ - return CommonHostInterface::ParseCommandLineParameters(argc, argv, out_boot_params); -} - std::string QtHostInterface::GetStringSettingValue(const char* section, const char* key, const char* default_value /*= ""*/) { @@ -344,16 +338,17 @@ void QtHostInterface::setMainWindow(MainWindow* window) m_main_window = window; } -void QtHostInterface::bootSystem(const SystemBootParameters& params) +void QtHostInterface::bootSystem(std::shared_ptr params) { if (!isOnWorkerThread()) { - QMetaObject::invokeMethod(this, "bootSystem", Qt::QueuedConnection, Q_ARG(const SystemBootParameters&, params)); + QMetaObject::invokeMethod(this, "bootSystem", Qt::QueuedConnection, + Q_ARG(std::shared_ptr, std::move(params))); return; } emit emulationStarting(); - BootSystem(params); + BootSystem(*params); } void QtHostInterface::resumeSystemFromState(const QString& filename, bool boot_on_failure) diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 5cdf1abf6..e8d444229 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -30,7 +30,7 @@ class INISettingsInterface; class MainWindow; class QtDisplayWidget; -Q_DECLARE_METATYPE(SystemBootParameters); +Q_DECLARE_METATYPE(std::shared_ptr); class QtHostInterface final : public QObject, public CommonHostInterface { @@ -51,8 +51,6 @@ public: void ReportMessage(const char* message) override; bool ConfirmMessage(const char* message) override; - bool parseCommandLineParameters(int argc, char* argv[], std::unique_ptr* out_boot_params); - /// Thread-safe settings access. std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override; bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false) override; @@ -143,7 +141,7 @@ public Q_SLOTS: void onDisplayWindowKeyEvent(int key, bool pressed); void onDisplayWindowMouseMoveEvent(int x, int y); void onDisplayWindowMouseButtonEvent(int button, bool pressed); - void bootSystem(const SystemBootParameters& params); + void bootSystem(std::shared_ptr params); void resumeSystemFromState(const QString& filename, bool boot_on_failure); void resumeSystemFromMostRecentState(); void powerOffSystem(); diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 68a4d2d53..6b70f4fab 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -376,8 +376,15 @@ bool CommonHostInterface::ParseCommandLineParameters(int argc, char* argv[], state_filename = GetGameSaveStateFileName(game_code.c_str(), *state_index); if (state_filename.empty() || !FileSystem::FileExists(state_filename.c_str())) { - Log_ErrorPrintf("Could not find file for game '%s' save state %d", game_code.c_str(), *state_index); - return false; + if (state_index >= 0) // Do not exit if -resume is specified, but resume save state does not exist + { + Log_ErrorPrintf("Could not find file for game '%s' save state %d", game_code.c_str(), *state_index); + return false; + } + else + { + state_filename.clear(); + } } } }