Compare commits

...

6 Commits

Author SHA1 Message Date
Jordan Woyak
4c48be43fe
Merge be95035cc4 into 0fdf1cc386 2025-11-15 14:52:22 -06:00
JosJuice
0fdf1cc386
Merge pull request #14112 from Simonx22/android/remove-unused-bimap-class
Android: Remove unused BiMap class
2025-11-15 16:22:17 +01:00
JosJuice
999e13b3b3
Merge pull request #14109 from OatmealDome/analytics-deadlock
DolphinAnalytics: Only call ReloadConfig in config changed callback when analytics enabled value changes
2025-11-15 14:44:54 +01:00
Jordan Woyak
be95035cc4 Core: Eliminate FreeLookConfig by putting the "active config" within FreeLookCamera. 2025-11-12 18:01:53 -06:00
Simonx22
d1526157df Android: Remove unused BiMap class 2025-11-12 17:26:05 -05:00
OatmealDome
df5f351add
DolphinAnalytics: Only call ReloadConfig in config changed callback when analytics enabled value changes
Co-authored-by: Simonx22 <simon@oatmealdome.me>
2025-11-12 00:09:41 -05:00
13 changed files with 42 additions and 177 deletions

View File

@ -1,29 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.utils;
import java.util.HashMap;
import java.util.Map;
public class BiMap<K, V>
{
private Map<K, V> forward = new HashMap<>();
private Map<V, K> backward = new HashMap<>();
public synchronized void add(K key, V value)
{
forward.put(key, value);
backward.put(value, key);
}
public synchronized V getForward(K key)
{
return forward.get(key);
}
public synchronized K getBackward(V key)
{
return backward.get(key);
}
}

View File

@ -123,8 +123,6 @@ add_library(core
FifoPlayer/FifoPlayer.h
FifoPlayer/FifoRecorder.cpp
FifoPlayer/FifoRecorder.h
FreeLookConfig.cpp
FreeLookConfig.h
FreeLookManager.cpp
FreeLookManager.h
GeckoCode.cpp

View File

@ -3,11 +3,6 @@
#include "Core/Config/FreeLookSettings.h"
#include <string>
#include "Common/Config/Config.h"
#include "Core/FreeLookConfig.h"
namespace Config
{
// Configuration Information

View File

@ -3,11 +3,16 @@
#pragma once
#include "Common/Config/Config.h"
#include "Common/Config/ConfigInfo.h"
namespace FreeLook
{
enum class ControlType : int;
enum class ControlType : int
{
SixAxis,
FPS,
Orbital
};
}
namespace Config

View File

@ -57,10 +57,19 @@ void DolphinAnalytics::AndroidSetGetValFunc(std::function<std::string(std::strin
DolphinAnalytics::DolphinAnalytics()
{
m_last_analytics_enabled = Config::Get(Config::MAIN_ANALYTICS_ENABLED);
ReloadConfig();
MakeBaseBuilder();
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { ReloadConfig(); });
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] {
bool current_analytics_enabled = Config::Get(Config::MAIN_ANALYTICS_ENABLED);
if (m_last_analytics_enabled != current_analytics_enabled)
{
m_last_analytics_enabled = current_analytics_enabled;
ReloadConfig();
}
});
}
DolphinAnalytics::~DolphinAnalytics()
@ -80,7 +89,7 @@ void DolphinAnalytics::ReloadConfig()
// Install the HTTP backend if analytics support is enabled.
std::unique_ptr<Common::AnalyticsReportingBackend> new_backend;
if (Config::Get(Config::MAIN_ANALYTICS_ENABLED))
if (m_last_analytics_enabled)
{
new_backend = std::make_unique<Common::HttpAnalyticsBackend>(ANALYTICS_ENDPOINT);
}

View File

@ -203,4 +203,5 @@ private:
std::mutex m_reporter_mutex;
Common::AnalyticsReporter m_reporter;
Config::ConfigChangedCallbackID m_config_changed_callback_id{};
bool m_last_analytics_enabled = false;
};

View File

@ -1,64 +0,0 @@
// Copyright 2020 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Core/FreeLookConfig.h"
#include <optional>
#include "Core/AchievementManager.h"
#include "Core/CPUThreadConfigCallback.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/FreeLookSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
namespace FreeLook
{
static Config s_config;
static Config s_active_config;
static std::optional<CPUThreadConfigCallback::ConfigChangedCallbackID>
s_config_changed_callback_id = std::nullopt;
Config& GetConfig()
{
return s_config;
}
const Config& GetActiveConfig()
{
return s_active_config;
}
void UpdateActiveConfig()
{
s_active_config = s_config;
}
Config::Config()
{
camera_config.control_type = ControlType::SixAxis;
enabled = false;
}
void Config::Refresh()
{
if (!s_config_changed_callback_id.has_value())
{
s_config_changed_callback_id =
CPUThreadConfigCallback::AddConfigChangedCallback([] { s_config.Refresh(); });
}
camera_config.control_type = ::Config::Get(::Config::FL1_CONTROL_TYPE);
enabled = ::Config::Get(::Config::FREE_LOOK_ENABLED) &&
!AchievementManager::GetInstance().IsHardcoreModeActive();
}
void Config::Shutdown()
{
if (!s_config_changed_callback_id.has_value())
return;
CPUThreadConfigCallback::RemoveConfigChangedCallback(*s_config_changed_callback_id);
s_config_changed_callback_id.reset();
}
} // namespace FreeLook

View File

@ -1,41 +0,0 @@
// Copyright 2020 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// IMPORTANT: UI etc should modify the value returned by FreeLook::GetConfig().
// Free Look code should read from the value returned by FreeLook::GetActiveConfig().
// The reason for this is to get rid of race conditions etc when the
// configuration changes in the middle of a frame.
#pragma once
namespace FreeLook
{
enum class ControlType : int
{
SixAxis,
FPS,
Orbital
};
struct CameraConfig
{
ControlType control_type;
};
// NEVER inherit from this class.
struct Config final
{
Config();
void Refresh();
void Shutdown();
CameraConfig camera_config;
bool enabled;
};
Config& GetConfig();
const Config& GetActiveConfig();
// Called every frame.
void UpdateActiveConfig();
} // namespace FreeLook

View File

@ -7,14 +7,11 @@
#include <fmt/ranges.h>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/ScopeGuard.h"
#include "Core/Config/FreeLookSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/FreeLookConfig.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
@ -22,7 +19,6 @@
#include "InputCommon/InputConfig.h"
#include "VideoCommon/FreeLookCamera.h"
#include "VideoCommon/OnScreenDisplay.h"
namespace
{
@ -326,8 +322,6 @@ void Shutdown()
{
s_config.UnregisterHotplugCallback();
s_config.ClearControllers();
GetConfig().Shutdown();
}
void Initialize()
@ -339,7 +333,7 @@ void Initialize()
s_config.RegisterHotplugCallback();
FreeLook::GetConfig().Refresh();
g_freelook_camera.RefreshConfig();
s_config.LoadConfig();
}

View File

@ -250,7 +250,6 @@
<ClInclude Include="Core\FifoPlayer\FifoDataFile.h" />
<ClInclude Include="Core\FifoPlayer\FifoPlayer.h" />
<ClInclude Include="Core\FifoPlayer\FifoRecorder.h" />
<ClInclude Include="Core\FreeLookConfig.h" />
<ClInclude Include="Core\FreeLookManager.h" />
<ClInclude Include="Core\GeckoCode.h" />
<ClInclude Include="Core\GeckoCodeConfig.h" />
@ -933,7 +932,6 @@
<ClCompile Include="Core\FifoPlayer\FifoDataFile.cpp" />
<ClCompile Include="Core\FifoPlayer\FifoPlayer.cpp" />
<ClCompile Include="Core\FifoPlayer\FifoRecorder.cpp" />
<ClCompile Include="Core\FreeLookConfig.cpp" />
<ClCompile Include="Core\FreeLookManager.cpp" />
<ClCompile Include="Core\GeckoCode.cpp" />
<ClCompile Include="Core\GeckoCodeConfig.cpp" />

View File

@ -4,18 +4,13 @@
#include "VideoCommon/FreeLookCamera.h"
#include <algorithm>
#include <math.h>
#include <fmt/format.h>
#include "Common/MathUtil.h"
#include "Common/ChunkFile.h"
#include "Core/ConfigManager.h"
#include "Common/Config/Config.h"
#include "Core/Core.h"
#include "VideoCommon/VideoCommon.h"
FreeLookCamera g_freelook_camera;
namespace
@ -260,21 +255,18 @@ float CameraControllerInput::GetSpeed() const
FreeLookCamera::FreeLookCamera()
{
SetControlType(FreeLook::ControlType::SixAxis);
RefreshConfig();
}
void FreeLookCamera::SetControlType(FreeLook::ControlType type)
void FreeLookCamera::RefreshConfig()
{
if (m_current_type && *m_current_type == type)
{
return;
}
m_is_enabled = Config::Get(Config::FREE_LOOK_ENABLED);
const auto type = Config::Get(Config::FL1_CONTROL_TYPE);
if (type == FreeLook::ControlType::SixAxis)
{
m_camera_controller = std::make_unique<SixAxisController>();
}
else if (type == FreeLook::ControlType::Orbital)
if (m_current_type == type)
return;
if (type == FreeLook::ControlType::Orbital)
{
m_camera_controller = std::make_unique<OrbitalController>();
}
@ -282,6 +274,10 @@ void FreeLookCamera::SetControlType(FreeLook::ControlType type)
{
m_camera_controller = std::make_unique<FPSController>();
}
else
{
m_camera_controller = std::make_unique<SixAxisController>();
}
m_current_type = type;
}
@ -330,7 +326,7 @@ void FreeLookCamera::DoState(PointerWrap& p)
bool FreeLookCamera::IsActive() const
{
return FreeLook::GetActiveConfig().enabled;
return m_is_enabled;
}
CameraController* FreeLookCamera::GetController() const

View File

@ -7,7 +7,7 @@
#include <optional>
#include "Common/Matrix.h"
#include "Core/FreeLookConfig.h"
#include "Core/Config/FreeLookSettings.h"
class PointerWrap;
@ -79,7 +79,9 @@ class FreeLookCamera
{
public:
FreeLookCamera();
void SetControlType(FreeLook::ControlType type);
void RefreshConfig();
Common::Matrix44 GetView() const;
Common::Vec2 GetFieldOfViewMultiplier() const;
@ -90,8 +92,10 @@ public:
CameraController* GetController() const;
private:
std::optional<FreeLook::ControlType> m_current_type;
std::unique_ptr<CameraController> m_camera_controller;
bool m_is_enabled{};
std::optional<FreeLook::ControlType> m_current_type;
};
extern FreeLookCamera g_freelook_camera;

View File

@ -305,10 +305,9 @@ void CheckForConfigChanges()
const auto old_hdr = g_ActiveConfig.bHDR;
UpdateActiveConfig();
FreeLook::UpdateActiveConfig();
g_vertex_manager->OnConfigChange();
g_freelook_camera.SetControlType(FreeLook::GetActiveConfig().camera_config.control_type);
g_freelook_camera.RefreshConfig();
if (g_ActiveConfig.bGraphicMods && !old_graphics_mods_enabled)
{