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 58 additions and 88 deletions

View file

@ -57,7 +57,8 @@ AndroidHostInterface::AndroidHostInterface(jobject java_object) : m_java_object(
{
m_settings.SetDefaults();
m_settings.bios_path = "/sdcard/PSX/BIOS/scph1001.bin";
m_settings.memory_card_a_path = "/sdcard/PSX/memory_card_a.mcd";
m_settings.controller_types[0] = ControllerType::DigitalController;
m_settings.memory_card_paths[0] = "/sdcard/PSX/memory_card_1.mcd";
m_settings.cpu_execution_mode = CPUExecutionMode::Recompiler;
//m_settings.cpu_execution_mode = CPUExecutionMode::CachedInterpreter;
//m_settings.gpu_renderer = GPURenderer::Software;
@ -333,19 +334,18 @@ void AndroidHostInterface::SurfaceChanged(ANativeWindow* window, int format, int
void AndroidHostInterface::SetControllerType(u32 index, std::string_view type_name)
{
ControllerType type = Settings::ParseControllerTypeName(std::string(type_name).c_str()).value_or(ControllerType::None);
if (!IsEmulationThreadRunning())
{
m_controller_type_names[index] = type_name;
m_settings.controller_types[index] = type;
return;
}
std::string type_name_copy(type_name);
RunOnEmulationThread([this, index, type_name_copy]() {
Log_InfoPrintf("Changing controller slot %d to %s", index, type_name_copy.c_str());
m_controller_type_names[index] = std::move(type_name_copy);
m_controllers[index] = Controller::Create(m_controller_type_names[index]);
m_system->SetController(index, m_controllers[index]);
RunOnEmulationThread([this, index, type]() {
Log_InfoPrintf("Changing controller slot %d to %s", index, Settings::GetControllerTypeName(type));
m_settings.controller_types[index] = type;
m_system->UpdateControllers();
}, false);
}
@ -355,27 +355,14 @@ void AndroidHostInterface::SetControllerButtonState(u32 index, s32 button_code,
return;
RunOnEmulationThread([this, index, button_code, pressed]() {
if (!m_controllers[index])
Controller* controller = m_system->GetController(index);
if (!controller)
return;
m_controllers[index]->SetButtonState(button_code, pressed);
controller->SetButtonState(button_code, pressed);
}, false);
}
void AndroidHostInterface::ConnectControllers()
{
for (u32 i = 0; i < NUM_CONTROLLERS; i++)
{
if (m_controller_type_names[i].empty())
continue;
Log_InfoPrintf("Connecting controller '%s' to port %u", m_controller_type_names[i].c_str(), i);
m_controllers[i] = Controller::Create(m_controller_type_names[i]);
if (m_controllers[i])
m_system->SetController(i, m_controllers[i]);
}
}
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
Log::GetInstance().SetDebugOutputParams(true, nullptr, LOGLEVEL_DEV);
@ -491,7 +478,11 @@ DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_setControllerButtonState, jobj
DEFINE_JNI_ARGS_METHOD(jint, AndroidHostInterface_getControllerButtonCode, jobject unused, jstring controller_type, jstring button_name)
{
std::optional<s32> code = Controller::GetButtonCodeByName(JStringToString(env, controller_type), JStringToString(env, button_name));
std::optional<ControllerType> type = Settings::ParseControllerTypeName(JStringToString(env, controller_type).c_str());
if (!type)
return -1;
std::optional<s32> code = Controller::GetButtonCodeByName(type.value(), JStringToString(env, button_name));
return code.value_or(-1);
}

View file

@ -48,8 +48,6 @@ private:
void DrawFPSWindow();
void ConnectControllers() override;
jobject m_java_object = {};
std::mutex m_callback_mutex;
@ -59,7 +57,4 @@ private:
std::atomic_bool m_emulation_thread_stop_request{false};
std::atomic_bool m_emulation_thread_start_result{false};
Event m_emulation_thread_started;
std::array<std::string, NUM_CONTROLLERS> m_controller_type_names;
std::array<std::shared_ptr<Controller>, NUM_CONTROLLERS> m_controllers;
};

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));
}
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));
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) {
m_pad->SetController(i, nullptr);
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())
{
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_1_path);
if (card)
m_pad->SetMemoryCard(0, std::move(card));
}
if (!settings.memory_card_2_path.empty())
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
{
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_2_path);
m_pad->SetMemoryCard(i, nullptr);
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_paths[i]);
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;