Config: Port SI device settings to new config system.

This commit is contained in:
Admiral H. Curtiss 2022-01-06 08:08:02 +01:00
parent a0a0bfc5ca
commit 5c325eef38
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
17 changed files with 114 additions and 66 deletions

View File

@ -66,7 +66,6 @@ public:
// alone on restore (false)
bool bSetVolume = false;
std::array<bool, MAX_BBMOTES> bSetWiimoteSource{};
std::array<bool, SerialInterface::MAX_SI_CHANNELS> bSetPads{};
private:
bool valid = false;
@ -77,7 +76,6 @@ private:
int iSyncGpuMinDistance = 0;
float fSyncGpuOverclock = 0;
std::array<WiimoteSource, MAX_BBMOTES> iWiimoteSource{};
std::array<SerialInterface::SIDevices, SerialInterface::MAX_SI_CHANNELS> Pads{};
};
void ConfigCache::SaveConfig(const SConfig& config)
@ -94,11 +92,8 @@ void ConfigCache::SaveConfig(const SConfig& config)
for (int i = 0; i != MAX_BBMOTES; ++i)
iWiimoteSource[i] = WiimoteCommon::GetSource(i);
std::copy(std::begin(config.m_SIDevice), std::end(config.m_SIDevice), std::begin(Pads));
bSetVolume = false;
bSetWiimoteSource.fill(false);
bSetPads.fill(false);
}
void ConfigCache::RestoreConfig(SConfig* config)
@ -125,12 +120,6 @@ void ConfigCache::RestoreConfig(SConfig* config)
WiimoteCommon::SetSource(i, iWiimoteSource[i]);
}
}
for (unsigned int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
if (bSetPads[i])
config->m_SIDevice[i] = Pads[i];
}
}
static ConfigCache config_cache;
@ -161,17 +150,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
core_section->Get("MMU", &StartUp.bMMU, StartUp.bMMU);
core_section->Get("SyncGPU", &StartUp.bSyncGPU, StartUp.bSyncGPU);
for (unsigned int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
int source;
controls_section->Get(fmt::format("PadType{}", i), &source, -1);
if (source >= SerialInterface::SIDEVICE_NONE && source < SerialInterface::SIDEVICE_COUNT)
{
StartUp.m_SIDevice[i] = static_cast<SerialInterface::SIDevices>(source);
config_cache.bSetPads[i] = true;
}
}
// Wii settings
if (StartUp.bWii)
{

View File

@ -76,11 +76,19 @@ const Info<std::string> MAIN_BBA_MAC{{System::Main, "Core", "BBA_MAC"}, ""};
const Info<std::string> MAIN_BBA_XLINK_IP{{System::Main, "Core", "BBA_XLINK_IP"}, "127.0.0.1"};
const Info<bool> MAIN_BBA_XLINK_CHAT_OSD{{System::Main, "Core", "BBA_XLINK_CHAT_OSD"}, true};
Info<u32> GetInfoForSIDevice(u32 channel)
const Info<SerialInterface::SIDevices>& GetInfoForSIDevice(int channel)
{
return {{System::Main, "Core", fmt::format("SIDevice{}", channel)},
static_cast<u32>(channel == 0 ? SerialInterface::SIDEVICE_GC_CONTROLLER :
SerialInterface::SIDEVICE_NONE)};
static const std::array<const Info<SerialInterface::SIDevices>, 4> infos{
Info<SerialInterface::SIDevices>{{System::Main, "Core", "SIDevice0"},
SerialInterface::SIDEVICE_GC_CONTROLLER},
Info<SerialInterface::SIDevices>{{System::Main, "Core", "SIDevice1"},
SerialInterface::SIDEVICE_NONE},
Info<SerialInterface::SIDevices>{{System::Main, "Core", "SIDevice2"},
SerialInterface::SIDEVICE_NONE},
Info<SerialInterface::SIDevices>{{System::Main, "Core", "SIDevice3"},
SerialInterface::SIDEVICE_NONE},
};
return infos[channel];
}
const Info<bool>& GetInfoForAdapterRumble(int channel)

View File

@ -36,6 +36,11 @@ namespace ExpansionInterface
enum TEXIDevices : int;
}
namespace SerialInterface
{
enum SIDevices : int;
}
namespace Config
{
// Main.Core
@ -71,7 +76,7 @@ const Info<ExpansionInterface::TEXIDevices>& GetInfoForEXIDevice(int channel);
extern const Info<std::string> MAIN_BBA_MAC;
extern const Info<std::string> MAIN_BBA_XLINK_IP;
extern const Info<bool> MAIN_BBA_XLINK_CHAT_OSD;
Info<u32> GetInfoForSIDevice(u32 channel);
const Info<SerialInterface::SIDevices>& GetInfoForSIDevice(int channel);
const Info<bool>& GetInfoForAdapterRumble(int channel);
const Info<bool>& GetInfoForSimulateKonga(int channel);
extern const Info<bool> MAIN_WII_SD_CARD;

View File

@ -75,6 +75,10 @@ static const INIToLocationMap& GetINIToLocationMap()
{{"Wii", "Language"}, {Config::SYSCONF_LANGUAGE.GetLocation()}},
{{"Core", "HLE_BS2"}, {Config::MAIN_SKIP_IPL.GetLocation()}},
{{"Core", "GameCubeLanguage"}, {Config::MAIN_GC_LANGUAGE.GetLocation()}},
{{"Core", "PadType0"}, {Config::GetInfoForSIDevice(0).GetLocation()}},
{{"Core", "PadType1"}, {Config::GetInfoForSIDevice(1).GetLocation()}},
{{"Core", "PadType2"}, {Config::GetInfoForSIDevice(2).GetLocation()}},
{{"Core", "PadType3"}, {Config::GetInfoForSIDevice(3).GetLocation()}},
};
return ini_to_location;
}

View File

@ -113,6 +113,10 @@ bool IsSettingSaveable(const Config::Location& config_location)
&Config::MAIN_SLOT_A.GetLocation(),
&Config::MAIN_SLOT_B.GetLocation(),
&Config::MAIN_SERIAL_PORT_1.GetLocation(),
&Config::GetInfoForSIDevice(0).GetLocation(),
&Config::GetInfoForSIDevice(1).GetLocation(),
&Config::GetInfoForSIDevice(2).GetLocation(),
&Config::GetInfoForSIDevice(3).GetLocation(),
// UI.General

View File

@ -104,10 +104,6 @@ void SConfig::SaveCoreSettings(IniFile& ini)
core->Set("SyncGpuMaxDistance", iSyncGpuMaxDistance);
core->Set("SyncGpuMinDistance", iSyncGpuMinDistance);
core->Set("SyncGpuOverclock", fSyncGpuOverclock);
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
core->Set(fmt::format("SIDevice{}", i), m_SIDevice[i]);
}
core->Set("MMU", bMMU);
}
@ -127,11 +123,6 @@ void SConfig::LoadCoreSettings(IniFile& ini)
IniFile::Section* core = ini.GetOrCreateSection("Core");
core->Get("CPUThread", &bCPUThread, true);
for (size_t i = 0; i < std::size(m_SIDevice); ++i)
{
core->Get(fmt::format("SIDevice{}", i), &m_SIDevice[i],
(i == 0) ? SerialInterface::SIDEVICE_GC_CONTROLLER : SerialInterface::SIDEVICE_NONE);
}
core->Get("MMU", &bMMU, bMMU);
core->Get("BBDumpPort", &iBBDumpPort, -1);
core->Get("SyncGPU", &bSyncGPU, false);

View File

@ -114,8 +114,6 @@ struct SConfig
static IniFile LoadLocalGameIni(const std::string& id, std::optional<u16> revision);
static IniFile LoadGameIni(const std::string& id, std::optional<u16> revision);
SerialInterface::SIDevices m_SIDevice[4];
SConfig(const SConfig&) = delete;
SConfig& operator=(const SConfig&) = delete;
SConfig(SConfig&&) = delete;

View File

@ -16,6 +16,7 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Swap.h"
#include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h"
#include "Core/CoreTiming.h"
#include "Core/HW/MMIO.h"
@ -411,7 +412,7 @@ void Init()
}
else if (Movie::IsUsingPad(i))
{
SIDevices current = SConfig::GetInstance().m_SIDevice[i];
SIDevices current = Config::Get(Config::GetInfoForSIDevice(i));
// GC pad-compatible devices can be used for both playing and recording
if (Movie::IsUsingBongo(i))
s_desired_device_types[i] = SIDEVICE_GC_TARUKONGA;
@ -423,7 +424,7 @@ void Init()
}
else if (!NetPlay::IsNetPlayRunning())
{
s_desired_device_types[i] = SConfig::GetInstance().m_SIDevice[i];
s_desired_device_types[i] = Config::Get(Config::GetInfoForSIDevice(i));
}
AddDevice(s_desired_device_types[i], i);

View File

@ -81,9 +81,8 @@ bool CSIDevice_GCAdapter::GetData(u32& hi, u32& low)
return true;
}
void CSIDevice_GCController::Rumble(int pad_num, ControlState strength)
void CSIDevice_GCController::Rumble(int pad_num, ControlState strength, SIDevices device)
{
SIDevices device = SConfig::GetInstance().m_SIDevice[pad_num];
if (device == SIDEVICE_WIIU_ADAPTER)
GCAdapter::Output(pad_num, static_cast<u8>(strength));
else if (SIDevice_IsGCController(device))

View File

@ -10,6 +10,7 @@
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/Swap.h"
#include "Core/Config/MainSettings.h"
#include "Core/CoreTiming.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/ProcessorInterface.h"
@ -33,6 +34,14 @@ CSIDevice_GCController::CSIDevice_GCController(SIDevices device, int device_numb
m_origin.origin_stick_y = GCPadStatus::MAIN_STICK_CENTER_Y;
m_origin.substick_x = GCPadStatus::C_STICK_CENTER_X;
m_origin.substick_y = GCPadStatus::C_STICK_CENTER_Y;
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
}
CSIDevice_GCController::~CSIDevice_GCController()
{
Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
}
int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
@ -299,10 +308,11 @@ void CSIDevice_GCController::SendCommand(u32 command, u8 poll)
if (pad_num < 4)
{
const SIDevices device = m_config_si_devices[pad_num];
if (type == 1)
CSIDevice_GCController::Rumble(pad_num, 1.0);
CSIDevice_GCController::Rumble(pad_num, 1.0, device);
else
CSIDevice_GCController::Rumble(pad_num, 0.0);
CSIDevice_GCController::Rumble(pad_num, 0.0, device);
}
if (poll == 0)
@ -328,6 +338,15 @@ void CSIDevice_GCController::DoState(PointerWrap& p)
p.Do(m_last_button_combo);
}
void CSIDevice_GCController::RefreshConfig()
{
for (int i = 0; i < 4; ++i)
{
const SerialInterface::SIDevices device = Config::Get(Config::GetInfoForSIDevice(i));
m_config_si_devices[i] = device;
}
}
CSIDevice_TaruKonga::CSIDevice_TaruKonga(SIDevices device, int device_number)
: CSIDevice_GCController(device, device_number)
{

View File

@ -3,6 +3,8 @@
#pragma once
#include <array>
#include "Core/HW/GCPad.h"
#include "Core/HW/SI/SI_Device.h"
#include "InputCommon/GCPadStatus.h"
@ -52,6 +54,7 @@ protected:
public:
// Constructor
CSIDevice_GCController(SIDevices device, int device_number);
~CSIDevice_GCController() override;
// Run the SI Buffer
int RunBuffer(u8* buffer, int request_length) override;
@ -74,12 +77,18 @@ public:
static int NetPlay_InGamePadToLocalPad(int pad_num);
// Direct rumble to the right GC Controller
static void Rumble(int pad_num, ControlState strength);
static void Rumble(int pad_num, ControlState strength, SIDevices device);
static void HandleMoviePadStatus(int device_number, GCPadStatus* pad_status);
protected:
void SetOrigin(const GCPadStatus& pad_status);
private:
void RefreshConfig();
std::array<SIDevices, 4> m_config_si_devices{};
size_t m_config_changed_callback_id;
};
// "TaruKonga", the DK Bongo controller

View File

@ -453,9 +453,10 @@ void ChangePads()
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
if (SConfig::GetInstance().m_SIDevice[i] == SerialInterface::SIDEVICE_GC_GBA_EMULATED)
const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i));
if (si_device == SerialInterface::SIDEVICE_GC_GBA_EMULATED)
controllers[i] = ControllerType::GBA;
else if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i]))
else if (SerialInterface::SIDevice_IsGCController(si_device))
controllers[i] = ControllerType::GC;
else
controllers[i] = ControllerType::None;
@ -473,9 +474,10 @@ void ChangePads()
}
else if (IsUsingPad(i))
{
if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i]))
const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i));
if (SerialInterface::SIDevice_IsGCController(si_device))
{
device = SConfig::GetInstance().m_SIDevice[i];
device = si_device;
}
else
{
@ -548,7 +550,8 @@ bool BeginRecordingInput(const ControllerTypeArray& controllers,
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
if (SConfig::GetInstance().m_SIDevice[i] == SerialInterface::SIDEVICE_GC_TARUKONGA)
const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i));
if (si_device == SerialInterface::SIDEVICE_GC_TARUKONGA)
s_bongos |= (1 << i);
}

View File

@ -1838,11 +1838,13 @@ void NetPlayClient::UpdateDevices()
else if (player_id == m_local_player->pid)
{
// Use local controller types for local controllers if they are compatible
if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[local_pad]))
const SerialInterface::SIDevices si_device =
Config::Get(Config::GetInfoForSIDevice(local_pad));
if (SerialInterface::SIDevice_IsGCController(si_device))
{
SerialInterface::ChangeDevice(SConfig::GetInstance().m_SIDevice[local_pad], pad);
SerialInterface::ChangeDevice(si_device, pad);
if (SConfig::GetInstance().m_SIDevice[local_pad] == SerialInterface::SIDEVICE_WIIU_ADAPTER)
if (si_device == SerialInterface::SIDEVICE_WIIU_ADAPTER)
{
GCAdapter::ResetDeviceType(local_pad);
}
@ -2161,7 +2163,8 @@ bool NetPlayClient::PollLocalPad(const int local_pad, sf::Packet& packet)
{
pad_status = Pad::GetGBAStatus(local_pad);
}
else if (SConfig::GetInstance().m_SIDevice[local_pad] == SerialInterface::SIDEVICE_WIIU_ADAPTER)
else if (Config::Get(Config::GetInfoForSIDevice(local_pad)) ==
SerialInterface::SIDEVICE_WIIU_ADAPTER)
{
pad_status = GCAdapter::Input(local_pad);
}

View File

@ -178,7 +178,8 @@ void GamecubeControllersWidget::LoadSettings()
{
for (size_t i = 0; i < m_gc_groups.size(); i++)
{
const SerialInterface::SIDevices si_device = SConfig::GetInstance().m_SIDevice[i];
const SerialInterface::SIDevices si_device =
Config::Get(Config::GetInfoForSIDevice(static_cast<int>(i)));
const std::optional<int> gc_index = ToGCMenuIndex(si_device);
if (gc_index)
{
@ -194,7 +195,7 @@ void GamecubeControllersWidget::SaveSettings()
{
const int index = m_gc_controller_boxes[i]->currentIndex();
const SerialInterface::SIDevices si_device = FromGCMenuIndex(index);
SConfig::GetInstance().m_SIDevice[i] = si_device;
Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast<int>(i)), si_device);
if (Core::IsRunning())
SerialInterface::ChangeDevice(si_device, static_cast<s32>(i));

View File

@ -1728,9 +1728,10 @@ void MainWindow::OnStartRecording()
for (int i = 0; i < 4; i++)
{
if (SConfig::GetInstance().m_SIDevice[i] == SerialInterface::SIDEVICE_GC_GBA_EMULATED)
const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i));
if (si_device == SerialInterface::SIDEVICE_GC_GBA_EMULATED)
controllers[i] = Movie::ControllerType::GBA;
else if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i]))
else if (SerialInterface::SIDevice_IsGCController(si_device))
controllers[i] = Movie::ControllerType::GC;
else
controllers[i] = Movie::ControllerType::None;
@ -1782,8 +1783,9 @@ void MainWindow::ShowTASInput()
{
for (int i = 0; i < num_gc_controllers; i++)
{
if (SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_NONE &&
SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_GC_GBA)
const auto si_device = Config::Get(Config::GetInfoForSIDevice(i));
if (si_device != SerialInterface::SIDEVICE_NONE &&
si_device != SerialInterface::SIDEVICE_GC_GBA)
{
m_gc_tas_input_windows[i]->show();
m_gc_tas_input_windows[i]->raise();

View File

@ -83,6 +83,8 @@ static u8 s_endpoint_out = 0;
static u64 s_last_init = 0;
static std::optional<size_t> s_config_callback_id = std::nullopt;
static std::array<SerialInterface::SIDevices, SerialInterface::MAX_SI_CHANNELS>
s_config_si_device_type{};
static std::array<bool, SerialInterface::MAX_SI_CHANNELS> s_config_rumble_enabled{};
static void Read()
@ -205,7 +207,10 @@ void SetAdapterCallback(std::function<void()> func)
static void RefreshConfig()
{
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
{
s_config_si_device_type[i] = Config::Get(Config::GetInfoForSIDevice(i));
s_config_rumble_enabled[i] = Config::Get(Config::GetInfoForAdapterRumble(i));
}
}
void Init()
@ -542,9 +547,8 @@ void ResetDeviceType(int chan)
bool UseAdapter()
{
const auto& si_devices = SConfig::GetInstance().m_SIDevice;
return std::any_of(std::begin(si_devices), std::end(si_devices), [](const auto device_type) {
const auto& si_devices = s_config_si_device_type;
return std::any_of(si_devices.begin(), si_devices.end(), [](const auto device_type) {
return device_type == SerialInterface::SIDEVICE_WIIU_ADAPTER;
});
}

View File

@ -12,7 +12,7 @@
#include "Common/Flag.h"
#include "Common/Logging/Log.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/HW/SI/SI.h"
@ -61,6 +61,16 @@ static Common::Flag s_adapter_detect_thread_running;
static u64 s_last_init = 0;
static std::optional<size_t> s_config_callback_id = std::nullopt;
static std::array<SerialInterface::SIDevices, SerialInterface::MAX_SI_CHANNELS>
s_config_si_device_type{};
static void RefreshConfig()
{
for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
s_config_si_device_type[i] = Config::Get(Config::GetInfoForSIDevice(i));
}
static void ScanThreadFunc()
{
Common::SetCurrentThreadName("GC Adapter Scanning Thread");
@ -200,6 +210,10 @@ void Init()
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_GCAdapter");
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));
if (!s_config_callback_id)
s_config_callback_id = Config::AddConfigChangedCallback(RefreshConfig);
RefreshConfig();
if (UseAdapter())
StartScanThread();
}
@ -236,6 +250,12 @@ void Shutdown()
{
StopScanThread();
Reset();
if (s_config_callback_id)
{
Config::RemoveConfigChangedCallback(*s_config_callback_id);
s_config_callback_id = std::nullopt;
}
}
void StartScanThread()
@ -376,8 +396,7 @@ void ResetDeviceType(int chan)
bool UseAdapter()
{
const auto& si_devices = SConfig::GetInstance().m_SIDevice;
const auto& si_devices = s_config_si_device_type;
return std::any_of(std::begin(si_devices), std::end(si_devices), [](const auto device_type) {
return device_type == SerialInterface::SIDEVICE_WIIU_ADAPTER;
});