libretro: Add compatibility settings loading

This commit is contained in:
Connor McLaughlin
2020-11-27 15:42:22 +10:00
parent b16e639f0c
commit 859f23f4d5
11 changed files with 767 additions and 26 deletions

View File

@ -12,6 +12,7 @@
#include "core/gpu.h"
#include "core/system.h"
#include "libretro_audio_stream.h"
#include "libretro_game_settings.h"
#include "libretro_host_display.h"
#include "libretro_opengl_host_display.h"
#include "libretro_settings_interface.h"
@ -135,7 +136,7 @@ void LibretroHostInterface::GetGameInfo(const char* path, CDImage* image, std::s
{
// Just use the filename for now... we don't have the game list. Unless we can pull this from the frontend somehow?
*title = System::GetTitleForPath(path);
code->clear();
*code = System::GetGameCodeForImage(image);
}
static const char* GetSaveDirectory()
@ -279,6 +280,32 @@ void LibretroHostInterface::UpdateLogging()
Log::SetConsoleOutputParams(true, nullptr, g_settings.log_level);
}
bool LibretroHostInterface::UpdateGameSettings()
{
std::unique_ptr<GameSettings::Entry> new_game_settings;
if (!System::IsShutdown() && !System::GetRunningCode().empty())
{
new_game_settings = GetSettingsForGame(System::GetRunningCode());
if (new_game_settings)
Log_InfoPrintf("Game settings found for %s", System::GetRunningCode().c_str());
}
if (new_game_settings == m_game_settings)
return false;
m_game_settings = std::move(new_game_settings);
return true;
}
void LibretroHostInterface::ApplyGameSettings()
{
if (!g_settings.apply_game_settings || !m_game_settings)
return;
m_game_settings->ApplySettings(System::GetState() == System::State::Starting);
}
bool LibretroHostInterface::retro_load_game(const struct retro_game_info* game)
{
SystemBootParameters bp;
@ -462,7 +489,7 @@ void LibretroHostInterface::OnSystemDestroyed()
m_using_hardware_renderer = false;
}
static std::array<retro_core_option_definition, 45> s_option_definitions = {{
static std::array<retro_core_option_definition, 46> s_option_definitions = {{
{"duckstation_Console.Region",
"Console Region",
"Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.",
@ -769,6 +796,11 @@ static std::array<retro_core_option_definition, 45> s_option_definitions = {{
"Shows on-screen messages generated by the core.",
{{"true", "Enabled"}, {"false", "Disabled"}},
"true"},
{"duckstation_Main.ApplyGameSettings",
"Apply Compatibility Settings",
"Automatically disables enhancements on games which are incompatible.",
{{"true", "Enabled"}, {"false", "Disabled"}},
"true"},
{"duckstation_Logging.LogLevel",
"Log Level",
"Sets the level of information logged by the core.",
@ -858,32 +890,36 @@ void LibretroHostInterface::UpdateSettings()
{
Settings old_settings(std::move(g_settings));
LoadSettings();
ApplyGameSettings();
FixIncompatibleSettings(false);
if (g_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale &&
g_settings.gpu_renderer != GPURenderer::Software)
if (System::IsValid())
{
ReportMessage("Resolution changed, updating system AV info...");
UpdateSystemAVInfo(true);
if (!g_settings.IsUsingSoftwareRenderer())
if (g_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale &&
g_settings.gpu_renderer != GPURenderer::Software)
{
if (!m_hw_render_callback_valid)
RequestHardwareRendererContext();
else if (!m_using_hardware_renderer)
SwitchToHardwareRenderer();
ReportMessage("Resolution changed, updating system AV info...");
UpdateSystemAVInfo(true);
if (!g_settings.IsUsingSoftwareRenderer())
{
if (!m_hw_render_callback_valid)
RequestHardwareRendererContext();
else if (!m_using_hardware_renderer)
SwitchToHardwareRenderer();
}
// Don't let the base class mess with the GPU.
old_settings.gpu_resolution_scale = g_settings.gpu_resolution_scale;
}
// Don't let the base class mess with the GPU.
old_settings.gpu_resolution_scale = g_settings.gpu_resolution_scale;
}
if (g_settings.gpu_renderer != old_settings.gpu_renderer)
{
ReportFormattedMessage("Switch to %s renderer pending, please restart the core to apply.",
Settings::GetRendererDisplayName(g_settings.gpu_renderer));
g_settings.gpu_renderer = old_settings.gpu_renderer;
if (g_settings.gpu_renderer != old_settings.gpu_renderer)
{
ReportFormattedMessage("Switch to %s renderer pending, please restart the core to apply.",
Settings::GetRendererDisplayName(g_settings.gpu_renderer));
g_settings.gpu_renderer = old_settings.gpu_renderer;
}
}
CheckForSettingsChanges(old_settings);
@ -900,6 +936,13 @@ void LibretroHostInterface::CheckForSettingsChanges(const Settings& old_settings
UpdateLogging();
}
void LibretroHostInterface::OnRunningGameChanged()
{
Log_InfoPrintf("Running game changed: %s (%s)", System::GetRunningCode().c_str(), System::GetRunningTitle().c_str());
if (UpdateGameSettings())
UpdateSettings();
}
void LibretroHostInterface::InitRumbleInterface()
{
m_rumble_interface_valid = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &m_rumble_interface);