Skip to content

Commit

Permalink
Pad: Change controller types when loading states if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 15, 2019
1 parent 0df741a commit 52c82b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Windows and Linux support - macOS may work, but not actively maintained
- Currently only .bin/.cue disc image formats are supported. Additional formats are planned
- Direct booting of homebrew executables
- Digital and analog controllers for input (rumble is forwarded to host)

## System Requirements
- A CPU faster than a potato.
Expand Down
27 changes: 16 additions & 11 deletions src/core/pad.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "pad.h"
#include "YBaseLib/Log.h"
#include "common/state_wrapper.h"
#include "controller.h"
#include "host_interface.h"
#include "interrupt_controller.h"
#include "memory_card.h"
#include "controller.h"
#include "system.h"
Log_SetChannel(Pad);

Expand Down Expand Up @@ -36,14 +36,24 @@ bool Pad::DoState(StateWrapper& sw)
{
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))
return false;
m_system->GetHostInterface()->AddOSDMessage(SmallString::FromFormat(
"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;
}

Expand Down Expand Up @@ -74,11 +84,6 @@ bool Pad::DoState(StateWrapper& sw)
if (!sw.DoMarker("MemoryCard") || !m_memory_cards[i]->DoState(sw))
return false;
}
else
{
if (!sw.DoMarker("NoController"))
return false;
}
}

sw.Do(&m_state);
Expand Down

0 comments on commit 52c82b6

Please sign in to comment.