From 52c82b6aa359b9fd6b81b2ef6cce87e160b824ef Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 16 Dec 2019 00:05:48 +1000 Subject: [PATCH] Pad: Change controller types when loading states if needed --- README.md | 1 + src/core/pad.cpp | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e61ab6b4f..ba47d7d17 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/core/pad.cpp b/src/core/pad.cpp index ba9bf9ea7..5655d0d84 100644 --- a/src/core/pad.cpp +++ b/src/core/pad.cpp @@ -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); @@ -36,16 +36,26 @@ bool Pad::DoState(StateWrapper& sw) { for (u32 i = 0; i < NUM_SLOTS; 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) + { + 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); + } + if (m_controllers[i]) { if (!sw.DoMarker("Controller") || !m_controllers[i]->DoState(sw)) return false; } - else - { - if (!sw.DoMarker("NoController")) - return false; - } bool card_present = static_cast(m_memory_cards[i]); sw.Do(&card_present); @@ -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);