System: Add option to disable loading memory cards from save states

This commit is contained in:
Connor McLaughlin 2020-05-27 02:06:56 +10:00
parent b17a5832e5
commit 81a7b147fc
7 changed files with 45 additions and 11 deletions

View File

@ -1022,6 +1022,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si)
si.SetStringValue("Controller1", "Type", Settings::GetControllerTypeName(ControllerType::DigitalController));
si.SetStringValue("Controller2", "Type", Settings::GetControllerTypeName(ControllerType::None));
si.SetBoolValue("MemoryCards", "LoadFromSaveStates", false);
si.SetStringValue("MemoryCards", "Card1Type", Settings::GetMemoryCardTypeName(MemoryCardType::PerGameTitle));
si.SetStringValue("MemoryCards", "Card1Path", "memcards/shared_card_1.mcd");
si.SetStringValue("MemoryCards", "Card2Type", "None");

View File

@ -62,16 +62,31 @@ bool Pad::DoState(StateWrapper& sw)
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)
{
Log_WarningPrintf("Skipping loading memory card %u from save state.", i + 1u);
MemoryCard dummy_card(m_system);
if (!sw.DoMarker("MemoryCard") || !dummy_card.DoState(sw))
return false;
// we do need to reset the existing card though, in case it was in the middle of a write
if (m_memory_cards[i])
m_memory_cards[i]->Reset();
continue;
}
if (card_present && !m_memory_cards[i])
{
m_system->GetHostInterface()->AddFormattedOSDMessage(
2.0f, "Memory card %c present in save state but not in system. Creating temporary card.", i + 1);
2.0f, "Memory card %u present in save state but not in system. Creating temporary card.", i + 1u);
m_memory_cards[i] = MemoryCard::Create(m_system);
}
else if (!card_present && m_memory_cards[i])
{
m_system->GetHostInterface()->AddFormattedOSDMessage(
2.0f, "Memory card %u present in system but not in save state. Removing card.", i + 1);
2.0f, "Memory card %u present in system but not in save state. Removing card.", i + 1u);
m_memory_cards[i].reset();
}

View File

@ -74,6 +74,7 @@ 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(MemoryCardType::Shared)).c_str())
@ -166,6 +167,7 @@ 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

@ -45,6 +45,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;
GPURenderer gpu_renderer = GPURenderer::Software;
u32 gpu_resolution_scale = 1;

View File

@ -12,6 +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.showOSDMessages, "Display/ShowOSDMessages");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, "Display/ShowFPS");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showVPS, "Display/ShowVPS");
@ -43,6 +45,10 @@ GeneralSettingsWidget::GeneralSettingsWidget(QtHostInterface* host_interface, QW
"the game list. If unchecked, the display will render in a seperate window.");
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.");
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

@ -33,6 +33,13 @@
</property>
<layout class="QGridLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QCheckBox" name="pauseOnStart">
<property name="text">
<string>Pause On Start</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="confirmPowerOff">
<property name="text">
<string>Confirm Power Off</string>
@ -46,27 +53,27 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="1">
<widget class="QCheckBox" name="loadMemoryCardsFromSaveStates">
<property name="text">
<string>Load Memory Cards From Save States</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="startFullscreen">
<property name="text">
<string>Start Fullscreen</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QCheckBox" name="renderToMain">
<property name="text">
<string>Render To Main Window</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="pauseOnStart">
<property name="text">
<string>Pause On Start</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -1026,6 +1026,8 @@ void SDLHostInterface::DrawSettingsWindow()
settings_changed |= ImGui::Checkbox("Pause On Start", &m_settings_copy.start_paused);
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::NewLine();