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("Controller1", "Type", Settings::GetControllerTypeName(ControllerType::DigitalController));
si.SetStringValue("Controller2", "Type", Settings::GetControllerTypeName(ControllerType::None)); si.SetStringValue("Controller2", "Type", Settings::GetControllerTypeName(ControllerType::None));
si.SetBoolValue("MemoryCards", "LoadFromSaveStates", false);
si.SetStringValue("MemoryCards", "Card1Type", Settings::GetMemoryCardTypeName(MemoryCardType::PerGameTitle)); si.SetStringValue("MemoryCards", "Card1Type", Settings::GetMemoryCardTypeName(MemoryCardType::PerGameTitle));
si.SetStringValue("MemoryCards", "Card1Path", "memcards/shared_card_1.mcd"); si.SetStringValue("MemoryCards", "Card1Path", "memcards/shared_card_1.mcd");
si.SetStringValue("MemoryCards", "Card2Type", "None"); 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]); bool card_present = static_cast<bool>(m_memory_cards[i]);
sw.Do(&card_present); 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]) if (card_present && !m_memory_cards[i])
{ {
m_system->GetHostInterface()->AddFormattedOSDMessage( 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); m_memory_cards[i] = MemoryCard::Create(m_system);
} }
else if (!card_present && m_memory_cards[i]) else if (!card_present && m_memory_cards[i])
{ {
m_system->GetHostInterface()->AddFormattedOSDMessage( 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(); 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. // 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. // 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] = memory_card_types[0] =
ParseMemoryCardTypeName( ParseMemoryCardTypeName(
si.GetStringValue("MemoryCards", "Card1Type", GetMemoryCardTypeName(MemoryCardType::Shared)).c_str()) si.GetStringValue("MemoryCards", "Card1Type", GetMemoryCardTypeName(MemoryCardType::Shared)).c_str())
@ -166,6 +167,7 @@ void Settings::Save(SettingsInterface& si) const
else else
si.DeleteValue("Controller2", "Type"); 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", "Card1Type", GetMemoryCardTypeName(memory_card_types[0]));
si.SetStringValue("MemoryCards", "Card1Path", memory_card_paths[0].c_str()); si.SetStringValue("MemoryCards", "Card1Path", memory_card_paths[0].c_str());
si.SetStringValue("MemoryCards", "Card2Type", GetMemoryCardTypeName(memory_card_types[1])); si.SetStringValue("MemoryCards", "Card2Type", GetMemoryCardTypeName(memory_card_types[1]));

View file

@ -45,6 +45,7 @@ struct Settings
bool start_fullscreen = false; bool start_fullscreen = false;
bool save_state_on_exit = true; bool save_state_on_exit = true;
bool confim_power_off = true; bool confim_power_off = true;
bool load_memory_cards_from_save_states = false;
GPURenderer gpu_renderer = GPURenderer::Software; GPURenderer gpu_renderer = GPURenderer::Software;
u32 gpu_resolution_scale = 1; 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.renderToMain, "Main/RenderToMainWindow");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.saveStateOnExit, "Main/SaveStateOnExit"); 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.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.showOSDMessages, "Display/ShowOSDMessages");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, "Display/ShowFPS"); SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showFPS, "Display/ShowFPS");
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.showVPS, "Display/ShowVPS"); 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."); "the game list. If unchecked, the display will render in a seperate window.");
dialog->registerWidgetHelp(m_ui.pauseOnStart, "Pause On Start", "Unchecked", dialog->registerWidgetHelp(m_ui.pauseOnStart, "Pause On Start", "Unchecked",
"Pauses the emulator when a game is started."); "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", dialog->registerWidgetHelp(m_ui.enableSpeedLimiter, "Enable Speed Limiter", "Checked",
"Throttles the emulation speed to the chosen speed above. If unchecked, the emulator will " "Throttles the emulation speed to the chosen speed above. If unchecked, the emulator will "
"run as fast as possible, which may not be playable."); "run as fast as possible, which may not be playable.");

View file

@ -33,6 +33,13 @@
</property> </property>
<layout class="QGridLayout" name="formLayout_4"> <layout class="QGridLayout" name="formLayout_4">
<item row="0" column="0"> <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"> <widget class="QCheckBox" name="confirmPowerOff">
<property name="text"> <property name="text">
<string>Confirm Power Off</string> <string>Confirm Power Off</string>
@ -46,27 +53,27 @@
</property> </property>
</widget> </widget>
</item> </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"> <widget class="QCheckBox" name="startFullscreen">
<property name="text"> <property name="text">
<string>Start Fullscreen</string> <string>Start Fullscreen</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="1">
<widget class="QCheckBox" name="renderToMain"> <widget class="QCheckBox" name="renderToMain">
<property name="text"> <property name="text">
<string>Render To Main Window</string> <string>Render To Main Window</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QCheckBox" name="pauseOnStart">
<property name="text">
<string>Pause On Start</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </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("Pause On Start", &m_settings_copy.start_paused);
settings_changed |= ImGui::Checkbox("Start Fullscreen", &m_settings_copy.start_fullscreen); 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("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(); ImGui::NewLine();