From 9527bfffed5ecc8c8c53e388e8d5905c9db6760f Mon Sep 17 00:00:00 2001 From: GPUCode Date: Fri, 30 Jun 2023 13:39:38 +0300 Subject: [PATCH] common: Remove dependency from core --- src/android/app/src/main/jni/native.cpp | 4 +- src/citra/citra.cpp | 2 +- .../configuration/configure_dialog.cpp | 9 ++- src/citra_qt/configuration/configure_dialog.h | 7 +- .../configuration/configure_per_game.cpp | 2 +- src/citra_qt/dumping/dumping_dialog.cpp | 7 +- src/citra_qt/dumping/dumping_dialog.h | 7 +- src/citra_qt/main.cpp | 16 ++--- src/common/CMakeLists.txt | 2 +- src/common/settings.cpp | 70 +------------------ src/common/settings.h | 1 - src/core/core.cpp | 69 ++++++++++++++++-- src/core/core.h | 3 + src/dedicated_room/CMakeLists.txt | 2 +- 14 files changed, 105 insertions(+), 96 deletions(-) diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index d1071ad3b..ef2b62f2e 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -141,7 +141,7 @@ static Core::System::ResultStatus RunCitra(const std::string& filepath) { app_loader->ReadProgramId(program_id); GameSettings::LoadOverrides(program_id); } - Settings::Apply(); + system.ApplySettings(); Settings::LogSettings(); Camera::RegisterFactory("image", std::make_unique()); @@ -472,7 +472,7 @@ void Java_org_citra_citra_1emu_NativeLibrary_ReloadSettings(JNIEnv* env, GameSettings::LoadOverrides(program_id); } - Settings::Apply(); + system.ApplySettings(); } jstring Java_org_citra_citra_1emu_NativeLibrary_GetUserSetting(JNIEnv* env, diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 3a9640c6e..8397992a2 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -343,7 +343,7 @@ int main(int argc, char** argv) { // Apply the command line arguments Settings::values.gdbstub_port = gdb_port; Settings::values.use_gdbstub = use_gdbstub; - Settings::Apply(); + system.ApplySettings(); // Register frontend applets Frontend::RegisterDefaultApplets(); diff --git a/src/citra_qt/configuration/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 1b00ddbe3..254a63641 100644 --- a/src/citra_qt/configuration/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -8,10 +8,13 @@ #include "citra_qt/configuration/configure_dialog.h" #include "citra_qt/hotkeys.h" #include "common/settings.h" +#include "core/core.h" #include "ui_configure.h" -ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, bool enable_web_config) - : QDialog(parent), ui(std::make_unique()), registry(registry) { +ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, Core::System& system_, + bool enable_web_config) + : QDialog(parent), ui{std::make_unique()}, registry{registry_}, + system{system_} { Settings::SetConfiguringGlobal(true); ui->setupUi(this); @@ -68,7 +71,7 @@ void ConfigureDialog::ApplyConfiguration() { ui->webTab->ApplyConfiguration(); ui->uiTab->ApplyConfiguration(); ui->storageTab->ApplyConfiguration(); - Settings::Apply(); + system.ApplySettings(); Settings::LogSettings(); } diff --git a/src/citra_qt/configuration/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index 3631ab20a..23b32a197 100644 --- a/src/citra_qt/configuration/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h @@ -13,11 +13,15 @@ namespace Ui { class ConfigureDialog; } +namespace Core { +class System; +} + class ConfigureDialog : public QDialog { Q_OBJECT public: - explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, + explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, Core::System& system, bool enable_web_config = true); ~ConfigureDialog() override; @@ -37,4 +41,5 @@ private: std::unique_ptr ui; HotkeyRegistry& registry; + Core::System& system; }; diff --git a/src/citra_qt/configuration/configure_per_game.cpp b/src/citra_qt/configuration/configure_per_game.cpp index fa11e3240..a0163dfa7 100644 --- a/src/citra_qt/configuration/configure_per_game.cpp +++ b/src/citra_qt/configuration/configure_per_game.cpp @@ -102,7 +102,7 @@ void ConfigurePerGame::ApplyConfiguration() { audio_tab->ApplyConfiguration(); debug_tab->ApplyConfiguration(); - Settings::Apply(); + system.ApplySettings(); Settings::LogSettings(); game_config->Save(); diff --git a/src/citra_qt/dumping/dumping_dialog.cpp b/src/citra_qt/dumping/dumping_dialog.cpp index bbe69f245..cd05d87d9 100644 --- a/src/citra_qt/dumping/dumping_dialog.cpp +++ b/src/citra_qt/dumping/dumping_dialog.cpp @@ -8,10 +8,11 @@ #include "citra_qt/dumping/options_dialog.h" #include "citra_qt/uisettings.h" #include "common/settings.h" +#include "core/core.h" #include "ui_dumping_dialog.h" -DumpingDialog::DumpingDialog(QWidget* parent) - : QDialog(parent), ui(std::make_unique()) { +DumpingDialog::DumpingDialog(QWidget* parent, Core::System& system_) + : QDialog(parent), ui{std::make_unique()}, system{system_} { ui->setupUi(this); @@ -216,5 +217,5 @@ void DumpingDialog::ApplyConfiguration() { Settings::values.audio_encoder_options = ui->audioEncoderOptionsLineEdit->text().toStdString(); Settings::values.audio_bitrate = ui->audioBitrateSpinBox->value(); UISettings::values.video_dumping_path = last_path; - Settings::Apply(); + system.ApplySettings(); } diff --git a/src/citra_qt/dumping/dumping_dialog.h b/src/citra_qt/dumping/dumping_dialog.h index 284f215c3..f0153f179 100644 --- a/src/citra_qt/dumping/dumping_dialog.h +++ b/src/citra_qt/dumping/dumping_dialog.h @@ -10,13 +10,17 @@ namespace Ui { class DumpingDialog; } +namespace Core { +class System; +} + class QLineEdit; class DumpingDialog : public QDialog { Q_OBJECT public: - explicit DumpingDialog(QWidget* parent); + explicit DumpingDialog(QWidget* parent, Core::System& system); ~DumpingDialog() override; QString GetFilePath() const; @@ -32,6 +36,7 @@ private: QLineEdit* line_edit); std::unique_ptr ui; + Core::System& system; QString last_path; diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 7a16bbfd3..46b8fdfb2 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -140,7 +140,7 @@ void GMainWindow::ShowTelemetryCallout() { "

Would you like to share your usage data with us?"); if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) == QMessageBox::Yes) { NetSettings::values.enable_telemetry = true; - Settings::Apply(); + system.ApplySettings(); } } @@ -1140,7 +1140,7 @@ void GMainWindow::BootGame(const QString& filename) { const std::string config_file_name = title_id == 0 ? name : fmt::format("{:016X}", title_id); Config per_game_config(config_file_name, Config::ConfigType::PerGameConfig); - Settings::Apply(); + system.ApplySettings(); LOG_INFO(Frontend, "Using per game config file for title id {}", config_file_name); Settings::LogSettings(); @@ -1883,7 +1883,7 @@ void GMainWindow::ChangeScreenLayout() { } Settings::values.layout_option = new_layout; - Settings::Apply(); + system.ApplySettings(); UpdateSecondaryWindowVisibility(); } @@ -1911,18 +1911,18 @@ void GMainWindow::ToggleScreenLayout() { Settings::values.layout_option = new_layout; SyncMenuUISettings(); - Settings::Apply(); + system.ApplySettings(); UpdateSecondaryWindowVisibility(); } void GMainWindow::OnSwapScreens() { Settings::values.swap_screen = ui->action_Screen_Layout_Swap_Screens->isChecked(); - Settings::Apply(); + system.ApplySettings(); } void GMainWindow::OnRotateScreens() { Settings::values.upright_screen = ui->action_Screen_Layout_Upright_Screens->isChecked(); - Settings::Apply(); + system.ApplySettings(); } void GMainWindow::TriggerSwapScreens() { @@ -1961,7 +1961,7 @@ void GMainWindow::OnLoadState() { void GMainWindow::OnConfigure() { game_list->SetDirectoryWatcherEnabled(false); Settings::SetConfiguringGlobal(true); - ConfigureDialog configureDialog(this, hotkey_registry, + ConfigureDialog configureDialog(this, hotkey_registry, system, !multiplayer_state->IsHostingPublicRoom()); connect(&configureDialog, &ConfigureDialog::LanguageChanged, this, &GMainWindow::OnLanguageChanged); @@ -2278,7 +2278,7 @@ void GMainWindow::OnOpenFFmpeg() { #endif void GMainWindow::OnStartVideoDumping() { - DumpingDialog dialog(this); + DumpingDialog dialog(this, system); if (dialog.exec() != QDialog::DialogCode::Accepted) { ui->action_Dump_Video->setChecked(false); return; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 4e3500a38..fc104ab45 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -176,5 +176,5 @@ if (CITRA_USE_PRECOMPILED_HEADERS) target_precompile_headers(citra_common PRIVATE precompiled_headers.h) endif() if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID STREQUAL GNU) - target_link_libraries(citra_common PRIVATE backtrace) + target_link_libraries(citra_common PRIVATE backtrace dl) endif() diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 19a52263c..9d76751f4 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -5,18 +5,8 @@ #include #include #include "audio_core/dsp_interface.h" +#include "common/file_util.h" #include "common/settings.h" -#include "core/core.h" -#include "core/gdbstub/gdbstub.h" -#include "core/hle/kernel/shared_page.h" -#include "core/hle/service/cam/cam.h" -#include "core/hle/service/hid/hid.h" -#include "core/hle/service/ir/ir_rst.h" -#include "core/hle/service/ir/ir_user.h" -#include "core/hle/service/mic_u.h" -#include "core/hle/service/plgldr/plgldr.h" -#include "video_core/renderer_base.h" -#include "video_core/video_core.h" namespace Settings { @@ -75,64 +65,6 @@ std::string_view GetTextureFilterName(TextureFilter filter) { Values values = {}; static bool configuring_global = true; -void Apply() { - GDBStub::SetServerPort(values.gdbstub_port.GetValue()); - GDBStub::ToggleServer(values.use_gdbstub.GetValue()); - - VideoCore::g_shader_jit_enabled = values.use_shader_jit.GetValue(); - VideoCore::g_hw_shader_enabled = values.use_hw_shader.GetValue(); - VideoCore::g_hw_shader_accurate_mul = values.shaders_accurate_mul.GetValue(); - -#ifndef ANDROID - if (VideoCore::g_renderer) { - VideoCore::g_renderer->UpdateCurrentFramebufferLayout(); - } -#endif - - if (VideoCore::g_renderer) { - auto& settings = VideoCore::g_renderer->Settings(); - settings.bg_color_update_requested = true; - settings.sampler_update_requested = true; - settings.shader_update_requested = true; - settings.texture_filter_update_requested = true; - } - - auto& system = Core::System::GetInstance(); - if (system.IsPoweredOn()) { - system.CoreTiming().UpdateClockSpeed(values.cpu_clock_percentage.GetValue()); - Core::DSP().SetSink(values.output_type.GetValue(), values.output_device.GetValue()); - Core::DSP().EnableStretching(values.enable_audio_stretching.GetValue()); - - auto hid = Service::HID::GetModule(system); - if (hid) { - hid->ReloadInputDevices(); - } - - auto apt = Service::APT::GetModule(system); - if (apt) { - apt->GetAppletManager()->ReloadInputDevices(); - } - - auto sm = system.ServiceManager(); - auto ir_user = sm.GetService("ir:USER"); - if (ir_user) - ir_user->ReloadInputDevices(); - auto ir_rst = sm.GetService("ir:rst"); - if (ir_rst) - ir_rst->ReloadInputDevices(); - - auto cam = Service::CAM::GetModule(system); - if (cam) { - cam->ReloadCameraDevices(); - } - - Service::MIC::ReloadMic(system); - } - - Service::PLGLDR::PLG_LDR::SetEnabled(values.plugin_loader_enabled.GetValue()); - Service::PLGLDR::PLG_LDR::SetAllowGameChangeState(values.allow_plugin_loader.GetValue()); -} - void LogSettings() { const auto log_setting = [](std::string_view name, const auto& value) { LOG_INFO(Config, "{}: {}", name, value); diff --git a/src/common/settings.h b/src/common/settings.h index 67c7b182c..c7bf565fe 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -525,7 +525,6 @@ void SetConfiguringGlobal(bool is_global); float Volume(); -void Apply(); void LogSettings(); // Restore the global state of all applicable settings in the Values struct diff --git a/src/core/core.cpp b/src/core/core.cpp index f3bbc12d7..4ac4d0fd0 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -13,9 +13,9 @@ #include "common/arch.h" #include "common/logging/log.h" #include "common/settings.h" -#include "common/texture.h" #include "core/arm/arm_interface.h" #include "core/arm/exclusive_monitor.h" +#include "core/hle/service/cam/cam.h" #if CITRA_ARCH(x86_64) || CITRA_ARCH(arm64) #include "core/arm/dynarmic/arm_dynarmic.h" #endif @@ -24,19 +24,22 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/dumping/backend.h" -#include "core/dumping/ffmpeg_backend.h" #include "core/frontend/image_interface.h" #include "core/gdbstub/gdbstub.h" #include "core/global.h" -#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/thread.h" #include "core/hle/service/apt/applet_manager.h" #include "core/hle/service/apt/apt.h" +#include "core/hle/service/cam/cam.h" #include "core/hle/service/fs/archive.h" #include "core/hle/service/gsp/gsp.h" -#include "core/hle/service/pm/pm_app.h" +#include "core/hle/service/hid/hid.h" +#include "core/hle/service/ir/ir_rst.h" +#include "core/hle/service/ir/ir_user.h" +#include "core/hle/service/mic_u.h" +#include "core/hle/service/plgldr/plgldr.h" #include "core/hle/service/service.h" #include "core/hle/service/sm/sm.h" #include "core/hw/gpu.h" @@ -597,6 +600,64 @@ void System::Reset() { } } +void System::ApplySettings() { + GDBStub::SetServerPort(Settings::values.gdbstub_port.GetValue()); + GDBStub::ToggleServer(Settings::values.use_gdbstub.GetValue()); + + VideoCore::g_shader_jit_enabled = Settings::values.use_shader_jit.GetValue(); + VideoCore::g_hw_shader_enabled = Settings::values.use_hw_shader.GetValue(); + VideoCore::g_hw_shader_accurate_mul = Settings::values.shaders_accurate_mul.GetValue(); + +#ifndef ANDROID + if (VideoCore::g_renderer) { + VideoCore::g_renderer->UpdateCurrentFramebufferLayout(); + } +#endif + + if (VideoCore::g_renderer) { + auto& settings = VideoCore::g_renderer->Settings(); + settings.bg_color_update_requested = true; + settings.sampler_update_requested = true; + settings.shader_update_requested = true; + settings.texture_filter_update_requested = true; + } + + if (IsPoweredOn()) { + CoreTiming().UpdateClockSpeed(Settings::values.cpu_clock_percentage.GetValue()); + Core::DSP().SetSink(Settings::values.output_type.GetValue(), + Settings::values.output_device.GetValue()); + Core::DSP().EnableStretching(Settings::values.enable_audio_stretching.GetValue()); + + auto hid = Service::HID::GetModule(*this); + if (hid) { + hid->ReloadInputDevices(); + } + + auto apt = Service::APT::GetModule(*this); + if (apt) { + apt->GetAppletManager()->ReloadInputDevices(); + } + + auto ir_user = service_manager->GetService("ir:USER"); + if (ir_user) + ir_user->ReloadInputDevices(); + auto ir_rst = service_manager->GetService("ir:rst"); + if (ir_rst) + ir_rst->ReloadInputDevices(); + + auto cam = Service::CAM::GetModule(*this); + if (cam) { + cam->ReloadCameraDevices(); + } + + Service::MIC::ReloadMic(*this); + } + + Service::PLGLDR::PLG_LDR::SetEnabled(Settings::values.plugin_loader_enabled.GetValue()); + Service::PLGLDR::PLG_LDR::SetAllowGameChangeState( + Settings::values.allow_plugin_loader.GetValue()); +} + template void System::serialize(Archive& ar, const unsigned int file_version) { diff --git a/src/core/core.h b/src/core/core.h index b29fc20e2..3b48912d1 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -330,6 +330,9 @@ public: return false; } + /// Applies any changes to settings to this core instance. + void ApplySettings(); + private: /** * Initialize the emulated system. diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt index 4df160a8d..7f130a9a8 100644 --- a/src/dedicated_room/CMakeLists.txt +++ b/src/dedicated_room/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(citra-room create_target_directory_groups(citra-room) -target_link_libraries(citra-room PRIVATE citra_common citra_core network) +target_link_libraries(citra-room PRIVATE citra_common network) if (ENABLE_WEB_SERVICE) target_compile_definitions(citra-room PRIVATE -DENABLE_WEB_SERVICE) target_link_libraries(citra-room PRIVATE web_service)