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 766 additions and 25 deletions

View file

@ -0,0 +1,106 @@
import sys
import configparser
def parse_ini(path):
config = configparser.ConfigParser()
config.read(path)
entries = {}
int_keys = {
"DisplayActiveStartOffset": "display_active_start_offset",
"DisplayActiveEndOffset": "display_active_end_offset",
"DMAMaxSliceTicks": "dma_max_slice_ticks",
"DMAHaltTicks": "dma_halt_ticks",
"GPUFIFOSize" : "gpu_fifo_size",
"GPUMaxRunAhead" : "gpu_max_run_ahead"
}
float_keys = {
"GPUPGXPTolerance" : "gpu_pgxp_tolerance"
}
traits = [
"ForceInterpreter",
"ForceSoftwareRenderer",
"ForceInterlacing",
"DisableTrueColor",
"DisableUpscaling",
"DisableScaledDithering",
"DisableForceNTSCTimings",
"DisableWidescreen",
"DisablePGXP",
"DisablePGXPCulling",
"DisablePGXPTextureCorrection",
"ForcePGXPVertexCache",
"ForcePGXPCPUMode",
"ForceDigitalController",
"ForceRecompilerMemoryExceptions",
"ForceRecompilerICache"
]
for gameid in config.sections():
entry = {}
for ini_key, cpp_key in int_keys.items():
try:
value = config.get(gameid, ini_key)
if value is not None:
entry[cpp_key] = str(value)
except configparser.NoOptionError:
pass
for ini_key, cpp_key in float_keys.items():
try:
value = config.getfloat(gameid, ini_key, fallback=None)
if value is not None:
entry[cpp_key] = str(value)
except configparser.NoOptionError:
pass
for trait in traits:
try:
value = config.getboolean(gameid, trait, fallback=None)
if value == True:
if "traits" not in entry:
entry["traits"] = []
entry["traits"].append(trait)
except configparser.NoOptionError:
pass
if len(entry) > 0:
entries[gameid] = entry
return entries
def write_cpp(entries, path):
print("Writing %u entries to '%s'" % (len(entries), path))
with open(path, "w") as f:
f.write('#include "libretro_game_settings.h"\n')
f.write('\n')
f.write('std::unique_ptr<GameSettings::Entry> GetSettingsForGame(const std::string& game_code)\n')
f.write('{\n')
f.write(' std::unique_ptr<GameSettings::Entry> gs = std::make_unique<GameSettings::Entry>();\n')
f.write('\n')
for gameid, entry in entries.items():
f.write(' if (game_code == "%s")\n' % gameid)
f.write(' {\n')
for key, value in entry.items():
if key == "traits":
for trait in value:
f.write(' gs->AddTrait(GameSettings::Trait::%s);\n' % trait)
else:
f.write(' gs->%s = %s;\n' % (key, value))
f.write(' return gs;\n')
f.write(' }\n')
f.write('\n')
f.write(' return {};\n')
f.write('}\n')
if __name__ == "__main__":
if len(sys.argv) < 3:
print("usage: %s <path to gamesettings.ini> <output cpp file>" % sys.argv[0])
sys.exit(1)
entries = parse_ini(sys.argv[1])
write_cpp(entries, sys.argv[2])

View file

@ -1,6 +1,8 @@
add_library(duckstation_libretro SHARED add_library(duckstation_libretro SHARED
libretro_audio_stream.cpp libretro_audio_stream.cpp
libretro_audio_stream.h libretro_audio_stream.h
libretro_game_settings.cpp
libretro_game_settings.h
libretro_host_display.cpp libretro_host_display.cpp
libretro_host_display.h libretro_host_display.h
libretro_host_interface.cpp libretro_host_interface.cpp

View file

@ -70,6 +70,7 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="libretro_d3d11_host_display.cpp" /> <ClCompile Include="libretro_d3d11_host_display.cpp" />
<ClCompile Include="libretro_audio_stream.cpp" /> <ClCompile Include="libretro_audio_stream.cpp" />
<ClCompile Include="libretro_game_settings.cpp" />
<ClCompile Include="libretro_host_display.cpp" /> <ClCompile Include="libretro_host_display.cpp" />
<ClCompile Include="libretro_host_interface.cpp" /> <ClCompile Include="libretro_host_interface.cpp" />
<ClCompile Include="libretro_settings_interface.cpp" /> <ClCompile Include="libretro_settings_interface.cpp" />
@ -80,6 +81,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="libretro_d3d11_host_display.h" /> <ClInclude Include="libretro_d3d11_host_display.h" />
<ClInclude Include="libretro_audio_stream.h" /> <ClInclude Include="libretro_audio_stream.h" />
<ClInclude Include="libretro_game_settings.h" />
<ClInclude Include="libretro_host_display.h" /> <ClInclude Include="libretro_host_display.h" />
<ClInclude Include="libretro_host_interface.h" /> <ClInclude Include="libretro_host_interface.h" />
<ClInclude Include="libretro_settings_interface.h" /> <ClInclude Include="libretro_settings_interface.h" />

View file

@ -9,6 +9,7 @@
<ClCompile Include="libretro_opengl_host_display.cpp" /> <ClCompile Include="libretro_opengl_host_display.cpp" />
<ClCompile Include="libretro_d3d11_host_display.cpp" /> <ClCompile Include="libretro_d3d11_host_display.cpp" />
<ClCompile Include="libretro_vulkan_host_display.cpp" /> <ClCompile Include="libretro_vulkan_host_display.cpp" />
<ClCompile Include="libretro_game_settings.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="libretro_host_interface.h" /> <ClInclude Include="libretro_host_interface.h" />
@ -18,5 +19,6 @@
<ClInclude Include="libretro_opengl_host_display.h" /> <ClInclude Include="libretro_opengl_host_display.h" />
<ClInclude Include="libretro_d3d11_host_display.h" /> <ClInclude Include="libretro_d3d11_host_display.h" />
<ClInclude Include="libretro_vulkan_host_display.h" /> <ClInclude Include="libretro_vulkan_host_display.h" />
<ClInclude Include="libretro_game_settings.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -0,0 +1,561 @@
#include "libretro_game_settings.h"
std::unique_ptr<GameSettings::Entry> GetSettingsForGame(const std::string& game_code)
{
std::unique_ptr<GameSettings::Entry> gs = std::make_unique<GameSettings::Entry>();
if (game_code == "SLUS-00530")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SLUS-00634")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SLUS-00077")
{
gs->AddTrait(GameSettings::Trait::DisableUpscaling);
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLPM-87089")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLPS-03336")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-01260")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLES-01211")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-01261")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLES-02466")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLES-00259")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLES-00606")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00639")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-90039")
{
gs->AddTrait(GameSettings::Trait::ForceSoftwareRenderer);
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00337")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00606")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLPS-03553")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLPS-01211")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00656")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00952")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-01222")
{
gs->display_active_start_offset = 64;
gs->display_active_end_offset = 68;
return gs;
}
if (game_code == "SLUS-00297")
{
gs->AddTrait(GameSettings::Trait::DisableUpscaling);
gs->AddTrait(GameSettings::Trait::DisablePGXP);
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SCUS-94350")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SCUS-94900")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "PCPX-96085")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00590")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00403")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SCUS-94300")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00214")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00204")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00006")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00213")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SCES-00344")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00355")
{
gs->AddTrait(GameSettings::Trait::DisableUpscaling);
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00331")
{
gs->AddTrait(GameSettings::Trait::DisableUpscaling);
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00106")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00005")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-01265")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00601")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLPS-00435")
{
gs->AddTrait(GameSettings::Trait::ForceRecompilerICache);
return gs;
}
if (game_code == "SLUS-00388")
{
gs->AddTrait(GameSettings::Trait::ForceRecompilerICache);
return gs;
}
if (game_code == "SCES-02834")
{
gs->AddTrait(GameSettings::Trait::ForceRecompilerICache);
return gs;
}
if (game_code == "SLUS-00870")
{
gs->AddTrait(GameSettings::Trait::ForceInterpreter);
return gs;
}
if (game_code == "SLUS-00183")
{
gs->AddTrait(GameSettings::Trait::ForceRecompilerICache);
return gs;
}
if (game_code == "SLES-00483")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLPS-02361")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPVertexCache);
return gs;
}
if (game_code == "SLPM-86023")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00067")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLES-00524")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLPS-00712")
{
gs->AddTrait(GameSettings::Trait::ForceRecompilerICache);
return gs;
}
if (game_code == "SLPS-01434")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00684")
{
gs->AddTrait(GameSettings::Trait::ForceInterpreter);
return gs;
}
if (game_code == "SLPS-02459")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLPM-86750")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLPS-02120")
{
gs->AddTrait(GameSettings::Trait::ForceInterlacing);
return gs;
}
if (game_code == "SLUS-00102")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00152")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00603")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00348")
{
gs->AddTrait(GameSettings::Trait::DisableUpscaling);
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00042")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00561")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00035")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00057")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00014")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SCUS-94403")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00549")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00240")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00027")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00119")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00224")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00453")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00753")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00811")
{
gs->AddTrait(GameSettings::Trait::ForceDigitalController);
return gs;
}
if (game_code == "SLUS-00208")
{
gs->display_active_start_offset = -62;
gs->display_active_end_offset = 72;
return gs;
}
if (game_code == "SLPS-01762")
{
gs->AddTrait(GameSettings::Trait::DisablePGXPCulling);
return gs;
}
if (game_code == "SLPS-01567")
{
gs->display_active_start_offset = -62;
gs->display_active_end_offset = 51;
return gs;
}
if (game_code == "SLPS-00360")
{
gs->display_active_start_offset = -62;
gs->display_active_end_offset = 72;
return gs;
}
if (game_code == "SCES-02835")
{
gs->AddTrait(GameSettings::Trait::ForceInterpreter);
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCES-02104")
{
gs->AddTrait(GameSettings::Trait::ForceInterpreter);
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCES-01438")
{
gs->AddTrait(GameSettings::Trait::DisablePGXPCulling);
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCUS-94467")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCUS-94425")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCPS-10085")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCUS-94228")
{
gs->AddTrait(GameSettings::Trait::DisablePGXPCulling);
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SCUS-94290")
{
gs->AddTrait(GameSettings::Trait::ForcePGXPCPUMode);
return gs;
}
if (game_code == "SLUS-01138")
{
gs->dma_max_slice_ticks = 200;
gs->gpu_max_run_ahead = 1;
return gs;
}
if (game_code == "SLPS-02376")
{
gs->dma_max_slice_ticks = 100;
gs->gpu_max_run_ahead = 1;
return gs;
}
if (game_code == "SLUS-00282")
{
gs->dma_max_slice_ticks = 200;
gs->gpu_max_run_ahead = 1;
return gs;
}
if (game_code == "SLUS-00022")
{
gs->AddTrait(GameSettings::Trait::DisableUpscaling);
return gs;
}
return {};
}

View file

@ -0,0 +1,4 @@
#include "frontend-common/game_settings.h"
#include <memory>
std::unique_ptr<GameSettings::Entry> GetSettingsForGame(const std::string& game_code);

View file

@ -12,6 +12,7 @@
#include "core/gpu.h" #include "core/gpu.h"
#include "core/system.h" #include "core/system.h"
#include "libretro_audio_stream.h" #include "libretro_audio_stream.h"
#include "libretro_game_settings.h"
#include "libretro_host_display.h" #include "libretro_host_display.h"
#include "libretro_opengl_host_display.h" #include "libretro_opengl_host_display.h"
#include "libretro_settings_interface.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? // 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); *title = System::GetTitleForPath(path);
code->clear(); *code = System::GetGameCodeForImage(image);
} }
static const char* GetSaveDirectory() static const char* GetSaveDirectory()
@ -279,6 +280,32 @@ void LibretroHostInterface::UpdateLogging()
Log::SetConsoleOutputParams(true, nullptr, g_settings.log_level); 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) bool LibretroHostInterface::retro_load_game(const struct retro_game_info* game)
{ {
SystemBootParameters bp; SystemBootParameters bp;
@ -462,7 +489,7 @@ void LibretroHostInterface::OnSystemDestroyed()
m_using_hardware_renderer = false; 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", {"duckstation_Console.Region",
"Console Region", "Console Region",
"Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.", "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.", "Shows on-screen messages generated by the core.",
{{"true", "Enabled"}, {"false", "Disabled"}}, {{"true", "Enabled"}, {"false", "Disabled"}},
"true"}, "true"},
{"duckstation_Main.ApplyGameSettings",
"Apply Compatibility Settings",
"Automatically disables enhancements on games which are incompatible.",
{{"true", "Enabled"}, {"false", "Disabled"}},
"true"},
{"duckstation_Logging.LogLevel", {"duckstation_Logging.LogLevel",
"Log Level", "Log Level",
"Sets the level of information logged by the core.", "Sets the level of information logged by the core.",
@ -858,32 +890,36 @@ void LibretroHostInterface::UpdateSettings()
{ {
Settings old_settings(std::move(g_settings)); Settings old_settings(std::move(g_settings));
LoadSettings(); LoadSettings();
ApplyGameSettings();
FixIncompatibleSettings(false); FixIncompatibleSettings(false);
if (g_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale && if (System::IsValid())
g_settings.gpu_renderer != GPURenderer::Software)
{ {
ReportMessage("Resolution changed, updating system AV info..."); if (g_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale &&
g_settings.gpu_renderer != GPURenderer::Software)
{
ReportMessage("Resolution changed, updating system AV info...");
UpdateSystemAVInfo(true); UpdateSystemAVInfo(true);
if (!g_settings.IsUsingSoftwareRenderer()) if (!g_settings.IsUsingSoftwareRenderer())
{ {
if (!m_hw_render_callback_valid) if (!m_hw_render_callback_valid)
RequestHardwareRendererContext(); RequestHardwareRendererContext();
else if (!m_using_hardware_renderer) else if (!m_using_hardware_renderer)
SwitchToHardwareRenderer(); SwitchToHardwareRenderer();
} }
// Don't let the base class mess with the GPU. // Don't let the base class mess with the GPU.
old_settings.gpu_resolution_scale = g_settings.gpu_resolution_scale; old_settings.gpu_resolution_scale = g_settings.gpu_resolution_scale;
} }
if (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.", ReportFormattedMessage("Switch to %s renderer pending, please restart the core to apply.",
Settings::GetRendererDisplayName(g_settings.gpu_renderer)); Settings::GetRendererDisplayName(g_settings.gpu_renderer));
g_settings.gpu_renderer = old_settings.gpu_renderer; g_settings.gpu_renderer = old_settings.gpu_renderer;
}
} }
CheckForSettingsChanges(old_settings); CheckForSettingsChanges(old_settings);
@ -900,6 +936,13 @@ void LibretroHostInterface::CheckForSettingsChanges(const Settings& old_settings
UpdateLogging(); 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() void LibretroHostInterface::InitRumbleInterface()
{ {
m_rumble_interface_valid = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &m_rumble_interface); m_rumble_interface_valid = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &m_rumble_interface);

View file

@ -4,6 +4,12 @@
#include "libretro.h" #include "libretro.h"
#include <limits> #include <limits>
#include <optional> #include <optional>
#include <memory>
namespace GameSettings
{
struct Entry;
}
class LibretroHostInterface : public HostInterface class LibretroHostInterface : public HostInterface
{ {
@ -50,6 +56,7 @@ protected:
std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override; std::unique_ptr<AudioStream> CreateAudioStream(AudioBackend backend) override;
void OnSystemDestroyed() override; void OnSystemDestroyed() override;
void CheckForSettingsChanges(const Settings& old_settings) override; void CheckForSettingsChanges(const Settings& old_settings) override;
void OnRunningGameChanged() override;
private: private:
bool SetCoreOptions(); bool SetCoreOptions();
@ -68,6 +75,9 @@ private:
void UpdateGeometry(); void UpdateGeometry();
void UpdateLogging(); void UpdateLogging();
bool UpdateGameSettings();
void ApplyGameSettings();
// Hardware renderer setup. // Hardware renderer setup.
bool RequestHardwareRendererContext(); bool RequestHardwareRendererContext();
void SwitchToHardwareRenderer(); void SwitchToHardwareRenderer();
@ -88,6 +98,9 @@ private:
static bool RETRO_CALLCONV DiskControlGetImagePath(unsigned index, char* path, size_t len); static bool RETRO_CALLCONV DiskControlGetImagePath(unsigned index, char* path, size_t len);
static bool RETRO_CALLCONV DiskControlGetImageLabel(unsigned index, char* label, size_t len); static bool RETRO_CALLCONV DiskControlGetImageLabel(unsigned index, char* label, size_t len);
std::unique_ptr<GameSettings::Entry> m_game_settings;
float m_last_aspect_ratio = 4.0f / 3.0f;
retro_hw_render_callback m_hw_render_callback = {}; retro_hw_render_callback m_hw_render_callback = {};
std::unique_ptr<HostDisplay> m_hw_render_display; std::unique_ptr<HostDisplay> m_hw_render_display;
bool m_hw_render_callback_valid = false; bool m_hw_render_callback_valid = false;
@ -97,8 +110,6 @@ private:
retro_rumble_interface m_rumble_interface = {}; retro_rumble_interface m_rumble_interface = {};
bool m_rumble_interface_valid = false; bool m_rumble_interface_valid = false;
bool m_supports_input_bitmasks = false; bool m_supports_input_bitmasks = false;
float m_last_aspect_ratio = 4.0f / 3.0f;
}; };
extern LibretroHostInterface g_libretro_host_interface; extern LibretroHostInterface g_libretro_host_interface;

View file

@ -1,4 +1,6 @@
add_library(frontend-common add_library(frontend-common
game_settings.cpp
game_settings.h
opengl_host_display.cpp opengl_host_display.cpp
opengl_host_display.h opengl_host_display.h
vulkan_host_display.cpp vulkan_host_display.cpp
@ -42,8 +44,6 @@ if(NOT BUILD_LIBRETRO_CORE)
cubeb_audio_stream.h cubeb_audio_stream.h
game_list.cpp game_list.cpp
game_list.h game_list.h
game_settings.cpp
game_settings.h
icon.cpp icon.cpp
icon.h icon.h
imgui_styles.cpp imgui_styles.cpp

View file

@ -11,10 +11,12 @@
#include <utility> #include <utility>
Log_SetChannel(GameSettings); Log_SetChannel(GameSettings);
#ifndef LIBRETRO
#ifdef WIN32 #ifdef WIN32
#include "common/windows_headers.h" #include "common/windows_headers.h"
#endif #endif
#include "SimpleIni.h" #include "SimpleIni.h"
#endif
namespace GameSettings { namespace GameSettings {
@ -173,6 +175,8 @@ bool Entry::SaveToStream(ByteStream* stream) const
WriteStringToStream(stream, memory_card_2_shared_path) && WriteStringToStream(stream, input_profile_name); WriteStringToStream(stream, memory_card_2_shared_path) && WriteStringToStream(stream, input_profile_name);
} }
#ifndef LIBRETRO
static void ParseIniSection(Entry* entry, const char* section, const CSimpleIniA& ini) static void ParseIniSection(Entry* entry, const char* section, const CSimpleIniA& ini)
{ {
for (u32 trait = 0; trait < static_cast<u32>(Trait::Count); trait++) for (u32 trait = 0; trait < static_cast<u32>(Trait::Count); trait++)
@ -467,6 +471,8 @@ void Database::SetEntry(const std::string& code, const std::string& name, const
m_entries.emplace(code, entry); m_entries.emplace(code, entry);
} }
#endif
void Entry::ApplySettings(bool display_osd_messages) const void Entry::ApplySettings(bool display_osd_messages) const
{ {
constexpr float osd_duration = 10.0f; constexpr float osd_duration = 10.0f;

View file

@ -82,6 +82,8 @@ struct Entry
void ApplySettings(bool display_osd_messages) const; void ApplySettings(bool display_osd_messages) const;
}; };
#ifndef LIBRETRO
class Database class Database
{ {
public: public:
@ -97,4 +99,6 @@ private:
std::unordered_map<std::string, Entry> m_entries; std::unordered_map<std::string, Entry> m_entries;
}; };
#endif
}; // namespace GameSettings }; // namespace GameSettings