Settings: Load Memory Cards From State -> Load Devices From State

Makes it apply to controllers too.
This commit is contained in:
Connor McLaughlin 2020-07-02 00:43:18 +10:00
parent 6834f2ca42
commit b471d1043a
7 changed files with 47 additions and 23 deletions

View file

@ -333,6 +333,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetBoolValue("Main", "StartPaused", false);
si.SetBoolValue("Main", "SaveStateOnExit", true);
si.SetBoolValue("Main", "ConfirmPowerOff", true);
si.SetBoolValue("Main", "LoadDevicesFromSaveStates", false);
si.SetStringValue("CPU", "ExecutionMode", Settings::GetCPUExecutionModeName(Settings::DEFAULT_CPU_EXECUTION_MODE));
@ -374,7 +375,6 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetStringValue("Controller1", "Type", Settings::GetControllerTypeName(Settings::DEFAULT_CONTROLLER_1_TYPE));
si.SetStringValue("Controller2", "Type", Settings::GetControllerTypeName(Settings::DEFAULT_CONTROLLER_2_TYPE));
si.SetBoolValue("MemoryCards", "LoadFromSaveStates", false);
si.SetStringValue("MemoryCards", "Card1Type", Settings::GetMemoryCardTypeName(Settings::DEFAULT_MEMORY_CARD_1_TYPE));
si.SetStringValue("MemoryCards", "Card1Path", "memcards/shared_card_1.mcd");
si.SetStringValue("MemoryCards", "Card2Type", Settings::GetMemoryCardTypeName(Settings::DEFAULT_MEMORY_CARD_2_TYPE));

View file

@ -44,25 +44,48 @@ bool Pad::DoState(StateWrapper& sw)
if (controller_type != state_controller_type)
{
m_system->GetHostInterface()->AddFormattedOSDMessage(
2.0f, "Save state contains controller type %s in port %u, but %s is used. Switching.",
Settings::GetControllerTypeName(state_controller_type), i, Settings::GetControllerTypeName(controller_type));
if (m_system->GetSettings().load_devices_from_save_states)
{
m_system->GetHostInterface()->AddFormattedOSDMessage(
2.0f, "Save state contains controller type %s in port %u, but %s is used. Switching.",
Settings::GetControllerTypeName(state_controller_type), i + 1u,
Settings::GetControllerTypeName(controller_type));
m_controllers[i].reset();
if (state_controller_type != ControllerType::None)
m_controllers[i] = Controller::Create(m_system, state_controller_type, i);
m_controllers[i].reset();
if (state_controller_type != ControllerType::None)
m_controllers[i] = Controller::Create(m_system, state_controller_type, i);
}
else
{
m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Ignoring mismatched controller type %s in port %u.",
Settings::GetControllerTypeName(state_controller_type),
i + 1u);
// we still need to read the save state controller state
if (state_controller_type != ControllerType::None)
{
std::unique_ptr<Controller> dummy_controller = Controller::Create(m_system, state_controller_type, i);
if (dummy_controller)
{
if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw))
return false;
}
}
}
}
if (m_controllers[i])
else
{
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
return false;
if (m_controllers[i])
{
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
return false;
}
}
bool card_present = static_cast<bool>(m_memory_cards[i]);
sw.Do(&card_present);
if (sw.IsReading() && card_present && !m_system->GetSettings().load_memory_cards_from_save_states)
if (sw.IsReading() && card_present && !m_system->GetSettings().load_devices_from_save_states)
{
Log_WarningPrintf("Skipping loading memory card %u from save state.", i + 1u);

View file

@ -81,6 +81,7 @@ void Settings::Load(SettingsInterface& si)
start_fullscreen = si.GetBoolValue("Main", "StartFullscreen", false);
save_state_on_exit = si.GetBoolValue("Main", "SaveStateOnExit", true);
confim_power_off = si.GetBoolValue("Main", "ConfirmPowerOff", true);
load_devices_from_save_states = si.GetBoolValue("Main", "LoadDevicesFromSaveStates", false);
cpu_execution_mode =
ParseCPUExecutionMode(
@ -146,7 +147,6 @@ void Settings::Load(SettingsInterface& si)
// NOTE: The default value here if not present in the config is shared, but SetDefaultSettings() makes per-game.
// This is so we don't break older builds which had the shared card by default.
load_memory_cards_from_save_states = si.GetBoolValue("MemoryCards", "LoadFromSaveStates", false);
memory_card_types[0] =
ParseMemoryCardTypeName(
si.GetStringValue("MemoryCards", "Card1Type", GetMemoryCardTypeName(DEFAULT_MEMORY_CARD_1_TYPE)).c_str())
@ -187,6 +187,7 @@ void Settings::Save(SettingsInterface& si) const
si.SetBoolValue("Main", "StartFullscreen", start_fullscreen);
si.SetBoolValue("Main", "SaveStateOnExit", save_state_on_exit);
si.SetBoolValue("Main", "ConfirmPowerOff", confim_power_off);
si.SetBoolValue("Main", "LoadDevicesFromSaveStates", load_devices_from_save_states);
si.SetStringValue("CPU", "ExecutionMode", GetCPUExecutionModeName(cpu_execution_mode));
@ -239,7 +240,6 @@ void Settings::Save(SettingsInterface& si) const
else
si.DeleteValue("Controller2", "Type");
si.SetBoolValue("MemoryCards", "LoadFromSaveStates", load_memory_cards_from_save_states);
si.SetStringValue("MemoryCards", "Card1Type", GetMemoryCardTypeName(memory_card_types[0]));
si.SetStringValue("MemoryCards", "Card1Path", memory_card_paths[0].c_str());
si.SetStringValue("MemoryCards", "Card2Type", GetMemoryCardTypeName(memory_card_types[1]));

View file

@ -77,7 +77,7 @@ struct Settings
bool start_fullscreen = false;
bool save_state_on_exit = true;
bool confim_power_off = true;
bool load_memory_cards_from_save_states = false;
bool load_devices_from_save_states = false;
GPURenderer gpu_renderer = GPURenderer::Software;
std::string gpu_adapter;

View file

@ -12,8 +12,8 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.renderToMain, "Main/RenderToMainWindow");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.saveStateOnExit, "Main/SaveStateOnExit");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.confirmPowerOff, "Main/ConfirmPowerOff");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.loadMemoryCardsFromSaveStates,
"MemoryCards/LoadFromSaveStates");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.loadDevicesFromSaveStates,
"Main/LoadDevicesFromSaveStates");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showOSDMessages, "Display/ShowOSDMessages");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, "Display/ShowFPS");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showVPS, "Display/ShowVPS");
@ -46,9 +46,10 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
dialog->registerWidgetHelp(m_ui.pauseOnStart, "Pause On Start", "Unchecked",
"Pauses the emulator when a game is started.");
dialog->registerWidgetHelp(
m_ui.loadMemoryCardsFromSaveStates, "Load Memory Cards From Save States", "Unchecked",
"When enabled, memory cards will be overwritten when save states are loaded. This can "
"result in lost saves. For deterministic save states, enable this option, otherwise leave disabled.");
m_ui.loadDevicesFromSaveStates, "Load Devices From Save States", "Unchecked",
"When enabled, memory cards and controllers will be overwritten when save states are loaded. This can "
"result in lost saves, and controller type mismatches. For deterministic save states, enable this option, "
"otherwise leave disabled.");
dialog->registerWidgetHelp(m_ui.enableSpeedLimiter, "Enable Speed Limiter", "Checked",
"Throttles the emulation speed to the chosen speed above. If unchecked, the emulator will "
"run as fast as possible, which may not be playable.");

View file

@ -54,9 +54,9 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="loadMemoryCardsFromSaveStates">
<widget class="QCheckBox" name="loadDevicesFromSaveStates">
<property name="text">
<string>Load Memory Cards From Save States</string>
<string>Load Devices From Save States</string>
</property>
</widget>
</item>

View file

@ -1086,7 +1086,7 @@ void SDLHostInterface::DrawSettingsWindow()
settings_changed |= ImGui::Checkbox("Start Fullscreen", &m_settings_copy.start_fullscreen);
settings_changed |= ImGui::Checkbox("Save State On Exit", &m_settings_copy.save_state_on_exit);
settings_changed |=
ImGui::Checkbox("Load Memory Cards From Save States", &m_settings_copy.load_memory_cards_from_save_states);
ImGui::Checkbox("Load Devices From Save States", &m_settings_copy.load_devices_from_save_states);
}
ImGui::NewLine();