Pad: Change controller types when loading states if needed

pull/22/head
Connor McLaughlin 6 years ago
parent 0df741a799
commit 52c82b6aa3

@ -10,6 +10,7 @@
- Windows and Linux support - macOS may work, but not actively maintained - Windows and Linux support - macOS may work, but not actively maintained
- Currently only .bin/.cue disc image formats are supported. Additional formats are planned - Currently only .bin/.cue disc image formats are supported. Additional formats are planned
- Direct booting of homebrew executables - Direct booting of homebrew executables
- Digital and analog controllers for input (rumble is forwarded to host)
## System Requirements ## System Requirements
- A CPU faster than a potato. - A CPU faster than a potato.

@ -1,10 +1,10 @@
#include "pad.h" #include "pad.h"
#include "YBaseLib/Log.h" #include "YBaseLib/Log.h"
#include "common/state_wrapper.h" #include "common/state_wrapper.h"
#include "controller.h"
#include "host_interface.h" #include "host_interface.h"
#include "interrupt_controller.h" #include "interrupt_controller.h"
#include "memory_card.h" #include "memory_card.h"
#include "controller.h"
#include "system.h" #include "system.h"
Log_SetChannel(Pad); Log_SetChannel(Pad);
@ -36,14 +36,24 @@ bool Pad::DoState(StateWrapper& sw)
{ {
for (u32 i = 0; i < NUM_SLOTS; i++) for (u32 i = 0; i < NUM_SLOTS; i++)
{ {
if (m_controllers[i]) ControllerType controller_type = m_controllers[i] ? m_controllers[i]->GetType() : ControllerType::None;
ControllerType state_controller_type = controller_type;
sw.Do(&state_controller_type);
if (controller_type != state_controller_type)
{ {
if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw)) m_system->GetHostInterface()->AddOSDMessage(SmallString::FromFormat(
return false; "Save state contains controller type %s in port %u, but %s is used. Switching.",
Settings::GetControllerTypeName(state_controller_type), i, Settings::GetControllerTypeName(controller_type)));
m_controllers[i].reset();
if (state_controller_type != ControllerType::None)
m_controllers[i] = Controller::Create(state_controller_type);
} }
else
if (m_controllers[i])
{ {
if (!sw.DoMarker("NoController")) if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw))
return false; return false;
} }
@ -74,11 +84,6 @@ bool Pad::DoState(StateWrapper& sw)
if (!sw.DoMarker("MemoryCard") || !m_memory_cards[i]->DoState(sw)) if (!sw.DoMarker("MemoryCard") || !m_memory_cards[i]->DoState(sw))
return false; return false;
} }
else
{
if (!sw.DoMarker("NoController"))
return false;
}
} }
sw.Do(&m_state); sw.Do(&m_state);

Loading…
Cancel
Save