Files
eden/src/common/settings.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

384 lines
11 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2014-09-12 17:06:13 -07:00
2023-06-27 19:13:54 -04:00
#include <version>
2023-08-22 21:58:09 -04:00
#include "common/settings_enums.h"
2023-05-21 15:43:01 -04:00
#if __cpp_lib_chrono >= 201907L
#include <chrono>
2023-06-27 19:13:54 -04:00
#include <exception>
#include <stdexcept>
2023-05-21 15:43:01 -04:00
#endif
2023-06-10 23:40:39 -04:00
#include <compare>
#include <cstddef>
#include <filesystem>
2023-05-04 03:44:53 -04:00
#include <functional>
#include <string_view>
2023-06-10 23:40:39 -04:00
#include <type_traits>
#include <fmt/core.h>
#include "common/assert.h"
2023-06-10 23:40:39 -04:00
#include "common/fs/fs_util.h"
#include "common/fs/path_util.h"
#include "common/logging/log.h"
2021-04-14 16:07:40 -07:00
#include "common/settings.h"
#include "common/time_zone.h"
2016-04-11 14:38:42 +02:00
2014-09-12 17:06:13 -07:00
namespace Settings {
2023-07-18 15:36:20 -04:00
// Clang 14 and earlier have errors when explicitly instantiating these classes
#ifndef CANNOT_EXPLICITLY_INSTANTIATE
2023-06-10 23:40:39 -04:00
#define SETTING(TYPE, RANGED) template class Setting<TYPE, RANGED>
#define SWITCHABLE(TYPE, RANGED) template class SwitchableSetting<TYPE, RANGED>
SETTING(AppletMode, false);
2023-06-10 23:40:39 -04:00
SETTING(AudioEngine, false);
SETTING(bool, false);
SETTING(int, false);
SETTING(std::string, false);
SETTING(u16, false);
SWITCHABLE(AnisotropyMode, true);
SWITCHABLE(AntiAliasing, false);
SWITCHABLE(AspectRatio, true);
SWITCHABLE(AstcDecodeMode, true);
SWITCHABLE(AstcRecompression, true);
SWITCHABLE(AudioMode, true);
2023-11-17 22:03:42 +02:00
SWITCHABLE(CpuBackend, true);
2023-06-10 23:40:39 -04:00
SWITCHABLE(CpuAccuracy, true);
SWITCHABLE(FullscreenMode, true);
SWITCHABLE(GpuAccuracy, true);
SWITCHABLE(Language, true);
SWITCHABLE(MemoryLayout, true);
2023-06-10 23:40:39 -04:00
SWITCHABLE(NvdecEmulation, false);
SWITCHABLE(Region, true);
SWITCHABLE(RendererBackend, true);
SWITCHABLE(ScalingFilter, false);
2025-04-12 00:26:47 +03:00
SWITCHABLE(SpirvOptimizeMode, true);
2023-06-10 23:40:39 -04:00
SWITCHABLE(ShaderBackend, true);
SWITCHABLE(TimeZone, true);
SETTING(VSyncMode, true);
SWITCHABLE(bool, false);
SWITCHABLE(int, false);
SWITCHABLE(int, true);
SWITCHABLE(s64, false);
SWITCHABLE(u16, true);
SWITCHABLE(u32, false);
SWITCHABLE(u8, false);
SWITCHABLE(u8, true);
// Used in UISettings
// TODO see if we can move this to uisettings.cpp
SWITCHABLE(ConfirmStop, true);
2023-06-10 23:40:39 -04:00
#undef SETTING
#undef SWITCHABLE
#endif
2023-06-10 23:40:39 -04:00
2022-04-28 13:22:34 -04:00
Values values;
2014-09-12 17:06:13 -07:00
std::string GetTimeZoneString(TimeZone time_zone) {
const auto time_zone_index = static_cast<std::size_t>(time_zone);
ASSERT(time_zone_index < Common::TimeZone::GetTimeZoneStrings().size());
2023-05-21 15:43:01 -04:00
std::string location_name;
if (time_zone_index == 0) { // Auto
2023-07-10 17:52:35 -04:00
#if __cpp_lib_chrono >= 201907L && !defined(MINGW)
// Disabled for MinGW -- tzdb always returns Etc/UTC
try {
2023-07-09 02:26:58 -04:00
const struct std::chrono::tzdb& time_zone_data = std::chrono::get_tzdb();
const std::chrono::time_zone* current_zone = time_zone_data.current_zone();
std::string_view current_zone_name = current_zone->name();
location_name = current_zone_name;
} catch (std::runtime_error& runtime_error) {
// VCRUNTIME will throw a runtime_error if the operating system's selected time zone
// cannot be found
location_name = Common::TimeZone::FindSystemTimeZone();
LOG_WARNING(Common,
"Error occurred when trying to determine system time zone:\n{}\nFalling "
"back to hour offset \"{}\"",
runtime_error.what(), location_name);
}
2023-05-21 15:43:01 -04:00
#else
location_name = Common::TimeZone::FindSystemTimeZone();
2023-05-21 15:43:01 -04:00
#endif
} else {
location_name = Common::TimeZone::GetTimeZoneStrings()[time_zone_index];
2023-05-21 15:43:01 -04:00
}
return location_name;
}
2018-07-10 18:02:14 +08:00
void LogSettings() {
const auto log_setting = [](std::string_view name, const auto& value) {
LOG_INFO(Config, "{}: {}", name, value);
};
const auto log_path = [](std::string_view name, const std::filesystem::path& path) {
LOG_INFO(Config, "{}: {}", name, Common::FS::PathToUTF8String(path));
};
2025-07-19 00:12:21 -04:00
LOG_INFO(Config, "Eden Configuration:");
for (auto& [category, settings] : values.linkage.by_category) {
for (const auto& setting : settings) {
if (setting->Id() == values.eden_token.Id()) {
2023-07-18 15:36:20 -04:00
// Hide the token secret, for security reasons.
continue;
}
2023-07-18 15:36:20 -04:00
const auto name = fmt::format(
"{:c}{:c} {}.{}", setting->ToString() == setting->DefaultToString() ? '-' : 'M',
setting->UsingGlobal() ? '-' : 'C', TranslateCategory(category),
setting->GetLabel());
log_setting(name, setting->Canonicalize());
}
}
log_path("DataStorage_CacheDir", Common::FS::GetEdenPath(Common::FS::EdenPath::CacheDir));
log_path("DataStorage_ConfigDir", Common::FS::GetEdenPath(Common::FS::EdenPath::ConfigDir));
log_path("DataStorage_LoadDir", Common::FS::GetEdenPath(Common::FS::EdenPath::LoadDir));
log_path("DataStorage_NANDDir", Common::FS::GetEdenPath(Common::FS::EdenPath::NANDDir));
log_path("DataStorage_SaveDir", Common::FS::GetEdenPath(Common::FS::EdenPath::SaveDir));
log_path("DataStorage_SDMCDir", Common::FS::GetEdenPath(Common::FS::EdenPath::SDMCDir));
2020-06-25 21:05:03 +02:00
}
bool getDebugKnobAt(u8 i) {
return (values.debug_knobs.GetValue() & (1 << (i & 0xF))) != 0;
}
void UpdateGPUAccuracy() {
values.current_gpu_accuracy = values.gpu_accuracy.GetValue();
}
bool IsGPULevelLow() {
return values.current_gpu_accuracy == GpuAccuracy::Low;
}
bool IsGPULevelMedium() {
return values.current_gpu_accuracy == GpuAccuracy::Medium;
2020-04-15 21:42:05 -04:00
}
bool IsGPULevelHigh() {
return values.current_gpu_accuracy == GpuAccuracy::High;
}
2025-09-16 18:42:48 +02:00
bool IsDMALevelDefault() {
return values.dma_accuracy.GetValue() == DmaAccuracy::Default;
}
bool IsDMALevelSafe() {
return values.dma_accuracy.GetValue() == DmaAccuracy::Safe;
}
bool IsFastmemEnabled() {
if (values.cpu_accuracy.GetValue() == Settings::CpuAccuracy::Debugging) {
return bool(values.cpuopt_fastmem);
}
2025-09-16 18:42:48 +02:00
if (values.cpu_accuracy.GetValue() == CpuAccuracy::Unsafe) {
return bool(values.cpuopt_unsafe_host_mmu);
}
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__ANDROID__) && !defined(_WIN32)
return false;
#else
return true;
#endif
}
static bool is_nce_enabled = false;
void SetNceEnabled(bool is_39bit) {
2023-11-18 16:10:39 +02:00
const bool is_nce_selected = values.cpu_backend.GetValue() == CpuBackend::Nce;
2023-12-09 23:37:14 +02:00
if (is_nce_selected && !IsFastmemEnabled()) {
LOG_WARNING(Common, "Fastmem is required to natively execute code in a performant manner, "
"falling back to Dynarmic");
}
if (is_nce_selected && !is_39bit) {
2023-11-18 16:10:39 +02:00
LOG_WARNING(
Common,
"Program does not utilize 39-bit address space, unable to natively execute code");
}
2023-12-09 23:37:14 +02:00
is_nce_enabled = IsFastmemEnabled() && is_nce_selected && is_39bit;
}
bool IsNceEnabled() {
return is_nce_enabled;
2023-11-17 22:03:42 +02:00
}
2023-08-22 21:58:09 -04:00
bool IsDockedMode() {
return values.use_docked_mode.GetValue() == Settings::ConsoleMode::Docked;
}
float Volume() {
if (values.audio_muted) {
return 0.0f;
}
2022-08-12 16:57:29 +01:00
return values.volume.GetValue() / static_cast<f32>(values.volume.GetDefault());
}
2023-06-05 21:05:22 -04:00
const char* TranslateCategory(Category category) {
switch (category) {
case Category::Android:
return "Android";
2023-06-05 21:05:22 -04:00
case Category::Audio:
return "Audio";
case Category::Core:
return "Core";
case Category::Cpu:
2023-05-07 10:35:28 -04:00
case Category::CpuDebug:
case Category::CpuUnsafe:
2023-06-05 21:05:22 -04:00
return "Cpu";
case Category::Overlay:
return "Overlay";
2023-06-05 21:05:22 -04:00
case Category::Renderer:
2023-05-07 10:35:28 -04:00
case Category::RendererAdvanced:
case Category::RendererDebug:
2025-04-23 20:57:53 -04:00
case Category::RendererExtensions:
2023-06-05 21:05:22 -04:00
return "Renderer";
case Category::System:
2023-05-10 17:57:25 -04:00
case Category::SystemAudio:
2023-06-05 21:05:22 -04:00
return "System";
case Category::DataStorage:
return "Data Storage";
case Category::Debugging:
2023-05-07 10:35:28 -04:00
case Category::DebuggingGraphics:
2023-06-05 21:05:22 -04:00
return "Debugging";
2023-12-10 20:45:02 -05:00
case Category::GpuDriver:
return "GpuDriver";
case Category::LibraryApplet:
return "LibraryApplet";
2023-06-05 21:05:22 -04:00
case Category::Miscellaneous:
return "Miscellaneous";
case Category::Network:
return "Network";
case Category::WebService:
return "WebService";
case Category::AddOns:
return "DisabledAddOns";
case Category::Controls:
return "Controls";
case Category::Ui:
2023-05-09 01:35:25 -04:00
case Category::UiGeneral:
2023-06-05 21:05:22 -04:00
return "UI";
2023-11-09 20:11:13 -06:00
case Category::UiAudio:
return "UiAudio";
2023-06-05 21:05:22 -04:00
case Category::UiLayout:
return "UILayout";
2023-06-05 21:05:22 -04:00
case Category::UiGameList:
return "UIGameList";
2023-06-05 21:05:22 -04:00
case Category::Screenshots:
return "Screenshots";
case Category::Shortcuts:
return "Shortcuts";
case Category::Multiplayer:
return "Multiplayer";
case Category::Services:
return "Services";
case Category::Paths:
return "Paths";
case Category::MaxEnum:
break;
}
return "Miscellaneous";
}
void TranslateResolutionInfo(ResolutionSetup setup, ResolutionScalingInfo& info) {
2021-10-15 22:59:16 +02:00
info.downscale = false;
switch (setup) {
2025-05-31 02:16:36 +00:00
case ResolutionSetup::Res1_4X:
info.up_scale = 1;
info.down_shift = 2;
info.downscale = true;
break;
case ResolutionSetup::Res1_2X:
info.up_scale = 1;
info.down_shift = 1;
2021-10-15 22:59:16 +02:00
info.downscale = true;
break;
2021-10-20 18:56:34 +02:00
case ResolutionSetup::Res3_4X:
info.up_scale = 3;
info.down_shift = 2;
info.downscale = true;
break;
case ResolutionSetup::Res1X:
info.up_scale = 1;
info.down_shift = 0;
break;
2023-01-13 02:34:24 -03:00
case ResolutionSetup::Res3_2X:
info.up_scale = 3;
info.down_shift = 1;
break;
case ResolutionSetup::Res5_4X:
info.up_scale = 5;
info.down_shift = 2;
break;
case ResolutionSetup::Res2X:
info.up_scale = 2;
info.down_shift = 0;
break;
case ResolutionSetup::Res3X:
info.up_scale = 3;
info.down_shift = 0;
break;
case ResolutionSetup::Res4X:
info.up_scale = 4;
info.down_shift = 0;
break;
2021-10-20 18:56:34 +02:00
case ResolutionSetup::Res5X:
info.up_scale = 5;
info.down_shift = 0;
break;
case ResolutionSetup::Res6X:
info.up_scale = 6;
info.down_shift = 0;
break;
2023-01-13 04:55:26 -03:00
case ResolutionSetup::Res7X:
info.up_scale = 7;
info.down_shift = 0;
break;
case ResolutionSetup::Res8X:
info.up_scale = 8;
info.down_shift = 0;
break;
default:
ASSERT(false);
info.up_scale = 1;
info.down_shift = 0;
2022-11-09 15:34:26 +01:00
break;
}
info.up_factor = static_cast<f32>(info.up_scale) / (1U << info.down_shift);
info.down_factor = static_cast<f32>(1U << info.down_shift) / info.up_scale;
2021-07-20 18:29:52 +02:00
info.active = info.up_scale != 1 || info.down_shift != 0;
}
void UpdateRescalingInfo() {
const auto setup = values.resolution_setup.GetValue();
auto& info = values.resolution_info;
TranslateResolutionInfo(setup, info);
}
void RestoreGlobalState(bool is_powered_on) {
// If a game is running, DO NOT restore the global settings state
if (is_powered_on) {
return;
}
2023-06-05 21:05:22 -04:00
for (const auto& reset : values.linkage.restore_functions) {
2023-05-04 03:44:53 -04:00
reset();
}
// Reset per-game flags
values.use_squashed_iterated_blend = false;
2020-04-15 21:42:05 -04:00
}
static bool configuring_global = true;
bool IsConfiguringGlobal() {
return configuring_global;
}
void SetConfiguringGlobal(bool is_global) {
configuring_global = is_global;
2020-04-15 21:42:05 -04:00
}
2017-08-25 23:53:07 +02:00
} // namespace Settings