Fix Android build after controller changes

This commit is contained in:
Connor McLaughlin
2019-12-16 16:46:43 +10:00
parent 52c82b6aa3
commit ad21f48a67
7 changed files with 57 additions and 87 deletions

View File

@ -33,11 +33,11 @@ void Settings::SetDefaults()
bios_patch_tty_enable = false;
bios_patch_fast_boot = false;
controller_1_type = ControllerType::DigitalController;
controller_2_type = ControllerType::None;
controller_types[0] = ControllerType::DigitalController;
controller_types[1] = ControllerType::None;
memory_card_1_path = "memory_card_1.mcd";
memory_card_2_path.clear();
memory_card_paths[0] = "memory_card_1.mcd";
memory_card_paths[1].clear();
}
void Settings::Load(const char* filename)
@ -72,13 +72,13 @@ void Settings::Load(const char* filename)
bios_patch_tty_enable = ini.GetBoolValue("BIOS", "PatchTTYEnable", true);
bios_patch_fast_boot = ini.GetBoolValue("BIOS", "PatchFastBoot", false);
controller_1_type = ParseControllerTypeName(ini.GetValue("Ports", "Controller1Type", "DigitalController"))
controller_types[0] = ParseControllerTypeName(ini.GetValue("Ports", "Controller1Type", "DigitalController"))
.value_or(ControllerType::DigitalController);
controller_2_type =
controller_types[1] =
ParseControllerTypeName(ini.GetValue("Ports", "Controller2Type", "None")).value_or(ControllerType::None);
memory_card_1_path = ini.GetValue("Ports", "MemoryCard1Path", "memory_card_1.mcd");
memory_card_2_path = ini.GetValue("Ports", "MemoryCard2Path", "");
memory_card_paths[0] = ini.GetValue("Ports", "MemoryCard1Path", "memory_card_1.mcd");
memory_card_paths[1] = ini.GetValue("Ports", "MemoryCard2Path", "");
}
bool Settings::Save(const char* filename) const
@ -110,23 +110,23 @@ bool Settings::Save(const char* filename) const
ini.SetBoolValue("BIOS", "PatchTTYEnable", bios_patch_tty_enable);
ini.SetBoolValue("BIOS", "PatchFastBoot", bios_patch_fast_boot);
if (controller_1_type != ControllerType::None)
ini.SetValue("Ports", "Controller1Type", GetControllerTypeName(controller_1_type));
if (controller_types[0] != ControllerType::None)
ini.SetValue("Ports", "Controller1Type", GetControllerTypeName(controller_types[0]));
else
ini.DeleteValue("Ports", "Controller1Type", nullptr);
if (controller_2_type != ControllerType::None)
ini.SetValue("Ports", "Controller2Type", GetControllerTypeName(controller_2_type));
if (controller_types[1] != ControllerType::None)
ini.SetValue("Ports", "Controller2Type", GetControllerTypeName(controller_types[1]));
else
ini.DeleteValue("Ports", "Controller2Type", nullptr);
if (!memory_card_1_path.empty())
ini.SetValue("Ports", "MemoryCard1Path", memory_card_1_path.c_str());
if (!memory_card_paths[0].empty())
ini.SetValue("Ports", "MemoryCard1Path", memory_card_paths[0].c_str());
else
ini.DeleteValue("Ports", "MemoryCard1Path", nullptr);
if (!memory_card_2_path.empty())
ini.SetValue("Ports", "MemoryCard2Path", memory_card_2_path.c_str());
if (!memory_card_paths[1].empty())
ini.SetValue("Ports", "MemoryCard2Path", memory_card_paths[1].c_str());
else
ini.DeleteValue("Ports", "MemoryCard2Path", nullptr);

View File

@ -1,5 +1,6 @@
#pragma once
#include "types.h"
#include <array>
#include <optional>
#include <string>
@ -45,11 +46,8 @@ struct Settings
bool bios_patch_tty_enable = false;
bool bios_patch_fast_boot = false;
ControllerType controller_1_type = ControllerType::None;
ControllerType controller_2_type = ControllerType::None;
std::string memory_card_1_path;
std::string memory_card_2_path;
std::array<ControllerType, NUM_CONTROLLER_AND_CARD_PORTS> controller_types{};
std::array<std::string, NUM_CONTROLLER_AND_CARD_PORTS> memory_card_paths{};
void SetDefaults();
void Load(const char* filename);

View File

@ -459,43 +459,28 @@ Controller* System::GetController(u32 slot) const
void System::UpdateControllers()
{
m_pad->SetController(0, nullptr);
m_pad->SetController(1, nullptr);
const Settings& settings = m_host_interface->GetSettings();
if (settings.controller_1_type != ControllerType::None)
{
std::unique_ptr<Controller> controller = Controller::Create(settings.controller_1_type);
if (controller)
m_pad->SetController(0, std::move(controller));
}
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) {
m_pad->SetController(i, nullptr);
if (settings.controller_2_type != ControllerType::None)
{
std::unique_ptr<Controller> controller = Controller::Create(settings.controller_2_type);
if (controller)
m_pad->SetController(1, std::move(controller));
const ControllerType type = settings.controller_types[i];
if (type != ControllerType::None) {
std::unique_ptr<Controller> controller = Controller::Create(type);
if (controller)
m_pad->SetController(i, std::move(controller));
}
}
}
void System::UpdateMemoryCards()
{
m_pad->SetMemoryCard(0, nullptr);
m_pad->SetMemoryCard(1, nullptr);
const Settings& settings = m_host_interface->GetSettings();
if (!settings.memory_card_1_path.empty())
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
{
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_1_path);
m_pad->SetMemoryCard(i, nullptr);
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_paths[i]);
if (card)
m_pad->SetMemoryCard(0, std::move(card));
}
if (!settings.memory_card_2_path.empty())
{
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_2_path);
if (card)
m_pad->SetMemoryCard(1, std::move(card));
m_pad->SetMemoryCard(i, std::move(card));
}
}

View File

@ -55,6 +55,12 @@ enum class ControllerType
Count
};
enum : u32
{
NUM_CONTROLLER_AND_CARD_PORTS = 2
};
enum : u32
{
CPU_CODE_CACHE_PAGE_SIZE = 1024,

View File

@ -1166,8 +1166,7 @@ void SDLHostInterface::DrawSettingsWindow()
ImGui::Text("Controller:");
ImGui::SameLine(indent);
int controller_type =
static_cast<int>((i == 0) ? m_settings.controller_1_type : m_settings.controller_2_type);
int controller_type = static_cast<int>(m_settings.controller_types[i]);
if (ImGui::Combo(
"##controller_type", &controller_type,
[](void*, int index, const char** out_text) {
@ -1176,11 +1175,7 @@ void SDLHostInterface::DrawSettingsWindow()
},
nullptr, static_cast<int>(ControllerType::Count)))
{
if (i == 0)
m_settings.controller_1_type = static_cast<ControllerType>(controller_type);
else
m_settings.controller_2_type = static_cast<ControllerType>(controller_type);
m_settings.controller_types[i] = static_cast<ControllerType>(controller_type);
settings_changed = true;
if (m_system)
{
@ -1193,7 +1188,7 @@ void SDLHostInterface::DrawSettingsWindow()
ImGui::Text("Memory Card Path:");
ImGui::SameLine(indent);
std::string* path_ptr = (i == 0) ? &m_settings.memory_card_1_path : &m_settings.memory_card_2_path;
std::string* path_ptr = &m_settings.memory_card_paths[i];
if (DrawFileChooser(TinyString::FromFormat("##memcard_%c_path", 'a' + i), path_ptr))
{
settings_changed = true;