GameProfile: Refactor encapsulation and controller profile accessors

This commit is contained in:
SSimco 2026-04-23 21:43:54 +03:00
parent 1d9bdd99c9
commit b9febc42bb
3 changed files with 56 additions and 42 deletions

View File

@ -9,8 +9,6 @@ struct gameProfileIntegerOption_t
class GameProfile
{
friend class GameProfileWindow;
public:
static const uint32 kThreadQuantumDefault = 45000;
@ -25,23 +23,36 @@ public:
[[nodiscard]] const std::optional<std::string>& GetGameName() const { return m_gameName; }
[[nodiscard]] const std::optional<bool>& ShouldLoadSharedLibraries() const { return m_loadSharedLibraries; }
void SetShouldLoadSharedLibraries(bool shouldLoadSharedLibraries) { m_loadSharedLibraries = shouldLoadSharedLibraries; }
[[nodiscard]] bool StartWithGamepadView() const { return m_startWithPadView; }
void SetStartWithGamepadView(bool startWithPadView) { m_startWithPadView = startWithPadView; }
[[nodiscard]] const std::optional<GraphicAPI>& GetGraphicsAPI() const { return m_graphics_api; }
void SetGraphicsAPI(GraphicAPI graphicApi) { m_graphics_api = graphicApi; }
void ClearGraphicsAPI() { m_graphics_api.reset(); }
[[nodiscard]] const AccurateShaderMulOption& GetAccurateShaderMul() const { return m_accurateShaderMul; }
void SetAccurateShaderMul(AccurateShaderMulOption accurateShaderMulOption) { m_accurateShaderMul = accurateShaderMulOption; }
#ifdef ENABLE_METAL
[[nodiscard]] bool GetShaderFastMath() const { return m_shaderFastMath; }
void SetShaderFastMath(bool shaderFastMath) { m_shaderFastMath = shaderFastMath; }
[[nodiscard]] MetalBufferCacheMode GetBufferCacheMode() const { return m_metalBufferCacheMode; }
void SetBufferCacheMode(MetalBufferCacheMode metalBufferCacheMode) { m_metalBufferCacheMode = metalBufferCacheMode; }
[[nodiscard]] PositionInvariance GetPositionInvariance() const { return m_positionInvariance; }
void SetPositionInvariance(PositionInvariance positionInvariance) { m_positionInvariance = positionInvariance; }
#endif
[[nodiscard]] const std::optional<PrecompiledShaderOption>& GetPrecompiledShadersState() const { return m_precompiledShaders; }
[[nodiscard]] uint32 GetThreadQuantum() const { return m_threadQuantum; }
void SetThreadQuantum(uint32 threadQuantum){ m_threadQuantum = threadQuantum; }
[[nodiscard]] const std::optional<CPUMode>& GetCPUMode() const { return m_cpuMode; }
void SetCPUMode(CPUMode cpuMode) { m_cpuMode = cpuMode; }
[[nodiscard]] bool IsAudioDisabled() const { return m_disableAudio; }
[[nodiscard]] const std::array< std::optional<std::string>, 8>& GetControllerProfile() const { return m_controllerProfile; }
[[nodiscard]] const std::array< std::optional<std::string>, 8>& GetControllerProfiles() const { return m_controllerProfile; }
[[nodiscard]] const std::optional<std::string>& GetControllerProfile(size_t controllerIndex) const { return m_controllerProfile[controllerIndex]; }
void SetControllerProfile(size_t controllerIndex, const std::string& profileName) { m_controllerProfile[controllerIndex] = profileName; }
void ResetControllerProfile(size_t controllerIndex) { m_controllerProfile[controllerIndex].reset(); }
#if BOOST_PLAT_ANDROID
struct DriverSetting

View File

@ -270,16 +270,16 @@ void GameProfileWindow::SetProfileInt(gameProfileIntegerOption_t& option, wxChec
void GameProfileWindow::ApplyProfile()
{
if(m_game_profile.m_gameName)
this->SetTitle(_("Edit game profile") + " - " + m_game_profile.m_gameName.value());
if (auto gameName = m_game_profile.GetGameName())
this->SetTitle(_("Edit game profile") + " - " + gameName.value());
// general
m_load_libs->SetValue(m_game_profile.m_loadSharedLibraries.value());
m_start_with_padview->SetValue(m_game_profile.m_startWithPadView);
m_load_libs->SetValue(m_game_profile.ShouldLoadSharedLibraries().value_or(false));
m_start_with_padview->SetValue(m_game_profile.StartWithGamepadView());
// cpu
// wxString cpu_modes[] = { _("Singlecore-Interpreter"), _("Singlecore-Recompiler"), _("Triplecore-Recompiler"), _("Auto (recommended)") };
switch(m_game_profile.m_cpuMode.value())
switch(m_game_profile.GetCPUMode().value_or(CPUMode::MulticoreRecompiler))
{
case CPUMode::SinglecoreInterpreter: m_cpu_mode->SetSelection(0); break;
case CPUMode::SinglecoreRecompiler: m_cpu_mode->SetSelection(1); break;
@ -288,18 +288,18 @@ void GameProfileWindow::ApplyProfile()
default: m_cpu_mode->SetSelection(3);
}
m_thread_quantum->SetStringSelection(fmt::format("{}", m_game_profile.m_threadQuantum));
m_thread_quantum->SetStringSelection(fmt::format("{}", m_game_profile.GetThreadQuantum()));
// gpu
if (!m_game_profile.m_graphics_api.has_value())
m_graphic_api->SetSelection(0); // selecting ""
if (auto graphicsApi = m_game_profile.GetGraphicsAPI())
m_graphic_api->SetSelection(1 + graphicsApi.value()); // "", OpenGL, Vulkan, Metal
else
m_graphic_api->SetSelection(1 + m_game_profile.m_graphics_api.value()); // "", OpenGL, Vulkan, Metal
m_shader_mul_accuracy->SetSelection((int)m_game_profile.m_accurateShaderMul);
m_graphic_api->SetSelection(0); // selecting ""
m_shader_mul_accuracy->SetSelection((int)m_game_profile.GetAccurateShaderMul());
#ifdef ENABLE_METAL
m_shader_fast_math->SetSelection((int)m_game_profile.m_shaderFastMath);
m_metal_buffer_cache_mode->SetSelection((int)m_game_profile.m_metalBufferCacheMode);
m_position_invariance->SetSelection((int)m_game_profile.m_positionInvariance);
m_shader_fast_math->SetSelection((int)m_game_profile.GetShaderFastMath());
m_metal_buffer_cache_mode->SetSelection((int)m_game_profile.GetBufferCacheMode());
m_position_invariance->SetSelection((int)m_game_profile.GetPositionInvariance());
#endif
//// audio
@ -319,15 +319,15 @@ void GameProfileWindow::ApplyProfile()
for (int i = 0; i < InputManager::kMaxController; ++i)
{
const bool has_value = m_game_profile.m_controllerProfile[i].has_value();
if (has_value)
if (auto controllerProfile = m_game_profile.GetControllerProfile(i))
{
const auto& v = m_game_profile.m_controllerProfile[i].value();
const auto& v = controllerProfile.value();
m_controller_profile[i]->SetStringSelection(wxString::FromUTF8(v));
}
else
{
m_controller_profile[i]->SetSelection(wxNOT_FOUND);
}
}
}
@ -336,57 +336,60 @@ void GameProfileWindow::SaveProfile()
// update game profile struct
m_game_profile.Reset();
// general
m_game_profile.m_loadSharedLibraries = m_load_libs->GetValue();
m_game_profile.m_startWithPadView = m_start_with_padview->GetValue();
m_game_profile.SetShouldLoadSharedLibraries(m_load_libs->GetValue());
m_game_profile.SetStartWithGamepadView(m_start_with_padview->GetValue());
// cpu
switch(m_cpu_mode->GetSelection())
CPUMode cpuMode;
switch (m_cpu_mode->GetSelection())
{
case 0: m_game_profile.m_cpuMode = CPUMode::SinglecoreInterpreter; break;
case 1: m_game_profile.m_cpuMode = CPUMode::SinglecoreRecompiler; break;
case 2: m_game_profile.m_cpuMode = CPUMode::MulticoreRecompiler; break;
case 0: cpuMode = CPUMode::SinglecoreInterpreter; break;
case 1: cpuMode = CPUMode::SinglecoreRecompiler; break;
case 2: cpuMode = CPUMode::MulticoreRecompiler; break;
default:
m_game_profile.m_cpuMode = CPUMode::Auto;
cpuMode = CPUMode::Auto;
}
m_game_profile.SetCPUMode(cpuMode);
const wxString thread_quantum = m_thread_quantum->GetStringSelection();
if (!thread_quantum.empty())
{
m_game_profile.m_threadQuantum = ConvertString<uint32>(thread_quantum.ToStdString());
m_game_profile.m_threadQuantum = std::min<uint32>(m_game_profile.m_threadQuantum, 536870912);
m_game_profile.m_threadQuantum = std::max<uint32>(m_game_profile.m_threadQuantum, 5000);
auto threadQuantum = ConvertString<uint32>(thread_quantum.ToStdString());
threadQuantum = std::clamp(5000u, 536870912u, threadQuantum);
m_game_profile.SetThreadQuantum(threadQuantum);
}
// gpu
m_game_profile.m_accurateShaderMul = (AccurateShaderMulOption)m_shader_mul_accuracy->GetSelection();
if (m_game_profile.m_accurateShaderMul != AccurateShaderMulOption::False && m_game_profile.m_accurateShaderMul != AccurateShaderMulOption::True)
m_game_profile.m_accurateShaderMul = AccurateShaderMulOption::True; // force a legal value
auto accurateShaderMul = (AccurateShaderMulOption)m_shader_mul_accuracy->GetSelection();
if (accurateShaderMul != AccurateShaderMulOption::False && accurateShaderMul != AccurateShaderMulOption::True)
accurateShaderMul = AccurateShaderMulOption::True; // force a legal value
m_game_profile.SetAccurateShaderMul(accurateShaderMul);
#ifdef ENABLE_METAL
m_game_profile.m_shaderFastMath = (bool)m_shader_fast_math->GetSelection();
m_game_profile.m_metalBufferCacheMode = (MetalBufferCacheMode)m_metal_buffer_cache_mode->GetSelection();
m_game_profile.m_positionInvariance = (PositionInvariance)m_position_invariance->GetSelection();
m_game_profile.SetShaderFastMath((bool)m_shader_fast_math->GetSelection());
m_game_profile.SetBufferCacheMode((MetalBufferCacheMode)m_metal_buffer_cache_mode->GetSelection());
m_game_profile.SetPositionInvariance((PositionInvariance)m_position_invariance->GetSelection());
#endif
if (m_graphic_api->GetSelection() == 0)
m_game_profile.m_graphics_api = {};
m_game_profile.ClearGraphicsAPI();
else
m_game_profile.m_graphics_api = (GraphicAPI)(m_graphic_api->GetSelection() - 1); // "", OpenGL, Vulkan, Metal
m_game_profile.SetGraphicsAPI((GraphicAPI)(m_graphic_api->GetSelection() - 1)); // "", OpenGL, Vulkan, Metal
// controller
for (int i = 0; i < 8; ++i)
{
if(m_controller_profile[i]->GetSelection() == wxNOT_FOUND)
{
m_game_profile.m_controllerProfile[i].reset();
m_game_profile.ResetControllerProfile(i);
continue;
}
const wxString profile_name = m_controller_profile[i]->GetStringSelection();
if (profile_name.empty())
m_game_profile.m_controllerProfile[i].reset();
m_game_profile.ResetControllerProfile(i);
else
m_game_profile.m_controllerProfile[i] = profile_name.ToUTF8();
m_game_profile.SetControllerProfile(i, profile_name.utf8_string());
}
// update game profile file

View File

@ -761,7 +761,7 @@ ControllerProviderPtr InputManager::get_api_provider(InputAPI::Type api, const C
void InputManager::apply_game_profile()
{
const auto& profiles = g_current_game_profile->GetControllerProfile();
const auto& profiles = g_current_game_profile->GetControllerProfiles();
for (int i = 0; i < kMaxController; ++i)
{
if (profiles[i] && !profiles[i]->empty())