From 132d9fd240bfb102476bd1d99b9d582ec2358ea6 Mon Sep 17 00:00:00 2001 From: DarthMew Date: Fri, 17 Mar 2023 01:11:54 +0100 Subject: [PATCH] Simplify code related to settings --- src/core/controller.cpp | 6 ---- src/core/digital_controller.cpp | 25 +------------ src/core/digital_controller.h | 7 ---- src/core/host_interface.cpp | 5 --- src/core/host_interface.h | 3 -- src/core/playstation_mouse.cpp | 23 ------------ src/core/playstation_mouse.h | 6 ---- src/core/settings.cpp | 46 ++---------------------- src/libretro/libretro_host_interface.cpp | 3 +- 9 files changed, 5 insertions(+), 119 deletions(-) diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 4eaee743..ebdc1d86 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -239,9 +239,6 @@ Controller::SettingList Controller::GetSettings(ControllerType type) { switch (type) { - case ControllerType::DigitalController: - return DigitalController::StaticGetSettings(); - case ControllerType::AnalogController: return AnalogController::StaticGetSettings(); @@ -254,9 +251,6 @@ Controller::SettingList Controller::GetSettings(ControllerType type) case ControllerType::NeGcon: return NeGcon::StaticGetSettings(); - case ControllerType::PlayStationMouse: - return PlayStationMouse::StaticGetSettings(); - default: return {}; } diff --git a/src/core/digital_controller.cpp b/src/core/digital_controller.cpp index 7cf81dee..4bdf277c 100644 --- a/src/core/digital_controller.cpp +++ b/src/core/digital_controller.cpp @@ -118,7 +118,7 @@ bool DigitalController::Transfer(const u8 data_in, u8* data_out) case TransferState::ButtonsLSB: { - *data_out = Truncate8(m_button_state) & GetButtonsLSBMask(); + *data_out = Truncate8(m_button_state); m_transfer_state = TransferState::ButtonsMSB; return true; } @@ -201,26 +201,3 @@ u32 DigitalController::StaticGetVibrationMotorCount() { return 0; } - -Controller::SettingList DigitalController::StaticGetSettings() -{ - static constexpr std::array settings = { - {{SettingInfo::Type::Boolean, "ForcePopnControllerMode", - TRANSLATABLE("DigitalController", "Force Pop'n Controller Mode"), - TRANSLATABLE("DigitalController", "Forces the Digital Controller to act as a Pop'n Controller."), "false"}}}; - return SettingList(settings.begin(), settings.end()); -} - -void DigitalController::LoadSettings(const char* section) -{ - Controller::LoadSettings(section); - m_popn_controller_mode = g_host_interface->GetBoolSettingValue(section, "ForcePopnControllerMode", false); -} - -u8 DigitalController::GetButtonsLSBMask() const -{ - constexpr u8 popn_controller_mask = - static_cast(~(u8(1) << static_cast(Button::Right) | u8(1) << static_cast(Button::Down) | - u8(1) << static_cast(Button::Left))); - return m_popn_controller_mode ? popn_controller_mask : 0xFF; -} diff --git a/src/core/digital_controller.h b/src/core/digital_controller.h index ad1eff31..bf36e07b 100644 --- a/src/core/digital_controller.h +++ b/src/core/digital_controller.h @@ -37,7 +37,6 @@ public: static AxisList StaticGetAxisNames(); static ButtonList StaticGetButtonNames(); static u32 StaticGetVibrationMotorCount(); - static SettingList StaticGetSettings(); ControllerType GetType() const override; std::optional GetAxisCodeByName(std::string_view axis_name) const override; @@ -54,8 +53,6 @@ public: void SetButtonState(Button button, bool pressed); - void LoadSettings(const char* section) override; - private: enum class TransferState : u8 { @@ -70,8 +67,4 @@ private: u16 m_button_state = UINT16_C(0xFFFF); TransferState m_transfer_state = TransferState::Idle; - - bool m_popn_controller_mode = false; - - u8 GetButtonsLSBMask() const; }; diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 436719c1..f6de9125 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -251,11 +251,6 @@ std::string HostInterface::GetShaderCacheBasePath() const return GetUserDirectoryRelativePath("cache/"); } -void HostInterface::LoadSettings(SettingsInterface& si) -{ - g_settings.Load(si); -} - void HostInterface::FixIncompatibleSettings(bool display_osd_messages) { if (g_settings.disable_all_enhancements) diff --git a/src/core/host_interface.h b/src/core/host_interface.h index c3c37932..420b2a75 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -126,9 +126,6 @@ protected: virtual void OnControllerTypeChanged(u32 slot) = 0; - /// Loads settings to m_settings and any frontend-specific parameters. - virtual void LoadSettings(SettingsInterface& si); - /// Checks and fixes up any incompatible settings. virtual void FixIncompatibleSettings(bool display_osd_messages); diff --git a/src/core/playstation_mouse.cpp b/src/core/playstation_mouse.cpp index ec3dcdff..1cc25770 100644 --- a/src/core/playstation_mouse.cpp +++ b/src/core/playstation_mouse.cpp @@ -208,26 +208,3 @@ u32 PlayStationMouse::StaticGetVibrationMotorCount() { return 0; } - -Controller::SettingList PlayStationMouse::StaticGetSettings() -{ - static constexpr std::array settings = {{ - {SettingInfo::Type::Boolean, "RelativeMouseMode", TRANSLATABLE("PlayStationMouse", "Relative Mouse Mode"), - TRANSLATABLE("PlayStationMouse", "Locks the mouse cursor to the window, use for FPS games."), "false"}, - }}; - - return SettingList(settings.begin(), settings.end()); -} - -void PlayStationMouse::LoadSettings(const char* section) -{ - Controller::LoadSettings(section); - - m_use_relative_mode = g_host_interface->GetBoolSettingValue(section, "RelativeMouseMode"); -} - -bool PlayStationMouse::GetSoftwareCursor(const Common::RGBA8Image** image, float* image_scale, bool* relative_mode) -{ - *relative_mode = m_use_relative_mode; - return m_use_relative_mode; -} diff --git a/src/core/playstation_mouse.h b/src/core/playstation_mouse.h index 472324b6..190e46ef 100644 --- a/src/core/playstation_mouse.h +++ b/src/core/playstation_mouse.h @@ -23,7 +23,6 @@ public: static AxisList StaticGetAxisNames(); static ButtonList StaticGetButtonNames(); static u32 StaticGetVibrationMotorCount(); - static SettingList StaticGetSettings(); ControllerType GetType() const override; std::optional GetAxisCodeByName(std::string_view axis_name) const override; @@ -39,9 +38,6 @@ public: void SetButtonState(Button button, bool pressed); - void LoadSettings(const char* section) override; - bool GetSoftwareCursor(const Common::RGBA8Image** image, float* image_scale, bool* relative_mode) override; - private: void UpdatePosition(); @@ -65,6 +61,4 @@ private: s8 m_delta_y = 0; TransferState m_transfer_state = TransferState::Idle; - - bool m_use_relative_mode = false; }; diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 72fdbc24..7f4fd240 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -141,21 +141,15 @@ void Settings::Load(SettingsInterface& si) enable_8mb_ram = si.GetBoolValue("Console", "Enable8MBRAM", false); apply_game_settings = si.GetBoolValue("Main", "ApplyGameSettings", true); - disable_all_enhancements = si.GetBoolValue("Main", "DisableAllEnhancements", false); - rewind_enable = si.GetBoolValue("Main", "RewindEnable", false); - rewind_save_frequency = si.GetFloatValue("Main", "RewindFrequency", 10.0f); - rewind_save_slots = static_cast(si.GetIntValue("Main", "RewindSaveSlots", 10)); runahead_frames = static_cast(si.GetIntValue("Main", "RunaheadFrameCount", 0)); cpu_execution_mode = ParseCPUExecutionMode( si.GetStringValue("CPU", "ExecutionMode", GetCPUExecutionModeName(DEFAULT_CPU_EXECUTION_MODE)).c_str()) .value_or(DEFAULT_CPU_EXECUTION_MODE); - cpu_overclock_numerator = std::max(si.GetIntValue("CPU", "OverclockNumerator", 1), 1); - cpu_overclock_denominator = std::max(si.GetIntValue("CPU", "OverclockDenominator", 1), 1); - cpu_overclock_enable = si.GetBoolValue("CPU", "OverclockEnable", false); + UpdateOverclockActive(); - cpu_recompiler_memory_exceptions = si.GetBoolValue("CPU", "RecompilerMemoryExceptions", false); + cpu_recompiler_block_linking = si.GetBoolValue("CPU", "RecompilerBlockLinking", true); cpu_recompiler_icache = si.GetBoolValue("CPU", "RecompilerICache", false); cpu_fastmem_mode = ParseCPUFastmemMode( @@ -166,8 +160,6 @@ void Settings::Load(SettingsInterface& si) gpu_renderer = ParseRendererName(si.GetStringValue("GPU", "Renderer", GetRendererName(DEFAULT_GPU_RENDERER)).c_str()) .value_or(DEFAULT_GPU_RENDERER); gpu_resolution_scale = static_cast(si.GetIntValue("GPU", "ResolutionScale", 1)); - gpu_multisamples = static_cast(si.GetIntValue("GPU", "Multisamples", 1)); - gpu_per_sample_shading = si.GetBoolValue("GPU", "PerSampleShading", false); gpu_use_thread = si.GetBoolValue("GPU", "UseThread", true); gpu_use_software_renderer_for_readbacks = si.GetBoolValue("GPU", "UseSoftwareRendererForReadbacks", false); gpu_true_color = si.GetBoolValue("GPU", "TrueColor", false); @@ -213,7 +205,6 @@ void Settings::Load(SettingsInterface& si) display_line_start_offset = static_cast(si.GetIntValue("Display", "LineStartOffset", 0)); display_line_end_offset = static_cast(si.GetIntValue("Display", "LineEndOffset", 0)); display_show_osd_messages = si.GetBoolValue("Display", "ShowOSDMessages", true); - display_show_enhancements = si.GetBoolValue("Display", "ShowEnhancements", false); cdrom_readahead_sectors = static_cast(si.GetIntValue("CDROM", "ReadaheadSectors", DEFAULT_CDROM_READAHEAD_SECTORS)); cdrom_region_check = si.GetBoolValue("CDROM", "RegionCheck", false); @@ -223,32 +214,10 @@ void Settings::Load(SettingsInterface& si) cdrom_read_speedup = si.GetIntValue("CDROM", "ReadSpeedup", 1); cdrom_seek_speedup = si.GetIntValue("CDROM", "SeekSpeedup", 1); - audio_buffer_size = si.GetIntValue("Audio", "BufferSize", HostInterface::DEFAULT_AUDIO_BUFFER_SIZE); - use_old_mdec_routines = si.GetBoolValue("Hacks", "UseOldMDECRoutines", false); - dma_max_slice_ticks = si.GetIntValue("Hacks", "DMAMaxSliceTicks", DEFAULT_DMA_MAX_SLICE_TICKS); - dma_halt_ticks = si.GetIntValue("Hacks", "DMAHaltTicks", DEFAULT_DMA_HALT_TICKS); - gpu_fifo_size = static_cast(si.GetIntValue("Hacks", "GPUFIFOSize", DEFAULT_GPU_FIFO_SIZE)); - gpu_max_run_ahead = si.GetIntValue("Hacks", "GPUMaxRunAhead", DEFAULT_GPU_MAX_RUN_AHEAD); - - bios_patch_tty_enable = si.GetBoolValue("BIOS", "PatchTTYEnable", false); bios_patch_fast_boot = si.GetBoolValue("BIOS", "PatchFastBoot", DEFAULT_FAST_BOOT_VALUE); - controller_types[0] = - ParseControllerTypeName( - si.GetStringValue("Controller1", "Type", GetControllerTypeName(DEFAULT_CONTROLLER_1_TYPE)).c_str()) - .value_or(DEFAULT_CONTROLLER_1_TYPE); - - for (u32 i = 1; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) - { - controller_types[i] = - ParseControllerTypeName(si.GetStringValue(TinyString::FromFormat("Controller%u", i + 1u), "Type", - GetControllerTypeName(DEFAULT_CONTROLLER_2_TYPE)) - .c_str()) - .value_or(DEFAULT_CONTROLLER_2_TYPE); - } - controller_analog_combo = si.GetIntValue("Controller", "AnalogCombo", 1); controller_enable_rumble = si.GetBoolValue("Controller", "EnableRumble", true); @@ -260,9 +229,7 @@ void Settings::Load(SettingsInterface& si) ParseMemoryCardTypeName( si.GetStringValue("MemoryCards", "Card2Type", GetMemoryCardTypeName(DEFAULT_MEMORY_CARD_2_TYPE)).c_str()) .value_or(DEFAULT_MEMORY_CARD_2_TYPE); - memory_card_paths[0] = si.GetStringValue("MemoryCards", "Card1Path", ""); - memory_card_paths[1] = si.GetStringValue("MemoryCards", "Card2Path", ""); - memory_card_directory = si.GetStringValue("MemoryCards", "Directory", ""); + memory_card_use_playlist_title = si.GetBoolValue("MemoryCards", "UsePlaylistTitle", true); multitap_mode = @@ -276,13 +243,6 @@ void Settings::Load(SettingsInterface& si) texture_replacements.enable_vram_write_replacements = si.GetBoolValue("TextureReplacements", "EnableVRAMWriteReplacements", false); texture_replacements.preload_textures = si.GetBoolValue("TextureReplacements", "PreloadTextures", false); - texture_replacements.dump_vram_writes = si.GetBoolValue("TextureReplacements", "DumpVRAMWrites", false); - texture_replacements.dump_vram_write_force_alpha_channel = - si.GetBoolValue("TextureReplacements", "DumpVRAMWriteForceAlphaChannel", true); - texture_replacements.dump_vram_write_width_threshold = - si.GetIntValue("TextureReplacements", "DumpVRAMWriteWidthThreshold", 128); - texture_replacements.dump_vram_write_height_threshold = - si.GetIntValue("TextureReplacements", "DumpVRAMWriteHeightThreshold", 128); } static std::array s_log_level_names = { diff --git a/src/libretro/libretro_host_interface.cpp b/src/libretro/libretro_host_interface.cpp index c81930b6..1beab835 100644 --- a/src/libretro/libretro_host_interface.cpp +++ b/src/libretro/libretro_host_interface.cpp @@ -325,7 +325,6 @@ bool LibretroHostInterface::Initialize() P_THIS->m_disk_control_info.image_labels.clear(); InitInterfaces(); - LibretroSettingsInterface si; LoadSettings(); FixIncompatibleSettings(true); UpdateLogging(); @@ -1045,7 +1044,7 @@ std::string LibretroHostInterface::GetBIOSDirectory() void LibretroHostInterface::LoadSettings() { LibretroSettingsInterface si; - HostInterface::LoadSettings(si); + g_settings.Load(si); // turn percentage into fraction for overclock const u32 overclock_percent = static_cast(std::max(si.GetIntValue("CPU", "Overclock", 100), 1));