Merge pull request #845 from CookiePLMonster/fix-resume

Fix issues with a -resume parameter
This commit is contained in:
Connor McLaughlin 2020-09-14 00:11:42 +10:00 committed by GitHub
commit bb6af3c8fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 43 deletions

View file

@ -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;

View file

@ -19,8 +19,8 @@ class CheatList;
struct SystemBootParameters
{
SystemBootParameters();
SystemBootParameters(SystemBootParameters&& other);
SystemBootParameters(std::string filename_);
SystemBootParameters(const SystemBootParameters& copy);
~SystemBootParameters();
std::string filename;

View file

@ -28,7 +28,7 @@ int main(int argc, char* argv[])
std::unique_ptr<QtHostInterface> host_interface = std::make_unique<QtHostInterface>();
std::unique_ptr<SystemBootParameters> 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
{

View file

@ -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<const SystemBootParameters>(filename.toStdString()));
}
void MainWindow::onStartBIOSActionTriggered()
{
SystemBootParameters boot_params;
m_host_interface->bootSystem(boot_params);
m_host_interface->bootSystem(std::make_shared<const SystemBootParameters>());
}
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<const SystemBootParameters>(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<const SystemBootParameters>(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<SystemBootParameters>(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<SystemBootParameters>(entry->path);
boot_params->override_fast_boot = false;
m_host_interface->bootSystem(std::move(boot_params));
});
}
else

View file

@ -44,7 +44,7 @@ Log_SetChannel(QtHostInterface);
QtHostInterface::QtHostInterface(QObject* parent) : QObject(parent), CommonHostInterface()
{
qRegisterMetaType<SystemBootParameters>();
qRegisterMetaType<std::shared_ptr<const SystemBootParameters>>();
}
QtHostInterface::~QtHostInterface()
@ -171,12 +171,6 @@ bool QtHostInterface::ConfirmMessage(const char* message)
return result;
}
bool QtHostInterface::parseCommandLineParameters(int argc, char* argv[],
std::unique_ptr<SystemBootParameters>* 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<const SystemBootParameters> 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<const SystemBootParameters>, std::move(params)));
return;
}
emit emulationStarting();
BootSystem(params);
BootSystem(*params);
}
void QtHostInterface::resumeSystemFromState(const QString& filename, bool boot_on_failure)

View file

@ -30,7 +30,7 @@ class INISettingsInterface;
class MainWindow;
class QtDisplayWidget;
Q_DECLARE_METATYPE(SystemBootParameters);
Q_DECLARE_METATYPE(std::shared_ptr<const SystemBootParameters>);
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<SystemBootParameters>* 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<const SystemBootParameters> params);
void resumeSystemFromState(const QString& filename, bool boot_on_failure);
void resumeSystemFromMostRecentState();
void powerOffSystem();

View file

@ -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();
}
}
}
}