Controller: Always preserve internal state when loading/resuming

Fixes analog mode getting disabled when loading state.
This commit is contained in:
Connor McLaughlin
2020-12-17 00:09:32 +10:00
parent b78a6045fc
commit 47f0720b93
15 changed files with 99 additions and 39 deletions

View File

@ -71,7 +71,7 @@ bool Pad::DoState(StateWrapper& sw)
if (state_controller_type != ControllerType::None)
{
m_controllers[i] = Controller::Create(state_controller_type, i);
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw, false))
return false;
}
}
@ -88,7 +88,7 @@ bool Pad::DoState(StateWrapper& sw)
std::unique_ptr<Controller> dummy_controller = Controller::Create(state_controller_type, i);
if (dummy_controller)
{
if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw))
if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw, true))
return false;
}
}
@ -98,21 +98,38 @@ bool Pad::DoState(StateWrapper& sw)
{
if (m_controllers[i])
{
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw, true))
return false;
}
}
}
else
{
// we still need to read the save state controller state
if (state_controller_type != ControllerType::None)
{
std::unique_ptr<Controller> dummy_controller = Controller::Create(state_controller_type, i);
if (dummy_controller)
if (controller_type != state_controller_type)
{
if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw))
return false;
g_host_interface->AddFormattedOSDMessage(
10.0f,
g_host_interface->TranslateString("OSDMessage", "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
std::unique_ptr<Controller> dummy_controller = Controller::Create(state_controller_type, i);
if (dummy_controller)
{
if (!sw.DoMarker("Controller") || !dummy_controller->DoState(sw, true))
return false;
}
}
else
{
// we still need to load some things from the state, e.g. configuration mode, analog mode
if (m_controllers[i])
{
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw, false))
return false;
}
}
}
}