Config: Add support for enums

This makes it possible to use enums as the config type.
Default values are now clearer and there's no need for casts
when calling Config::Get/Set anymore.

In order to add support for enums, the common code was updated to
handle enums by using the underlying type when loading/saving settings.

A copy constructor is also provided for conversions from
`ConfigInfo<Enum>` to `ConfigInfo<underlying_type<Enum>>`
so that enum settings can still easily work with code that doesn't care
about the actual enum values (like Graphics{Choice,Radio} in DolphinQt2
which only treat the setting as an integer).
This commit is contained in:
Léo Lam
2018-05-11 22:38:44 +02:00
parent 7dca7c237e
commit 6763a3fce1
10 changed files with 87 additions and 54 deletions

View File

@ -21,10 +21,10 @@ const ConfigInfo<int> GFX_ADAPTER{{System::GFX, "Hardware", "Adapter"}, 0};
// Graphics.Settings
const ConfigInfo<bool> GFX_WIDESCREEN_HACK{{System::GFX, "Settings", "wideScreenHack"}, false};
const ConfigInfo<int> GFX_ASPECT_RATIO{{System::GFX, "Settings", "AspectRatio"},
static_cast<int>(AspectMode::Auto)};
const ConfigInfo<int> GFX_SUGGESTED_ASPECT_RATIO{{System::GFX, "Settings", "SuggestedAspectRatio"},
static_cast<int>(AspectMode::Auto)};
const ConfigInfo<AspectMode> GFX_ASPECT_RATIO{{System::GFX, "Settings", "AspectRatio"},
AspectMode::Auto};
const ConfigInfo<AspectMode> GFX_SUGGESTED_ASPECT_RATIO{
{System::GFX, "Settings", "SuggestedAspectRatio"}, AspectMode::Auto};
const ConfigInfo<bool> GFX_CROP{{System::GFX, "Settings", "Crop"}, false};
const ConfigInfo<int> GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES{
{System::GFX, "Settings", "SafeTextureCacheColorSamples"}, 128};
@ -78,9 +78,8 @@ const ConfigInfo<int> GFX_COMMAND_BUFFER_EXECUTE_INTERVAL{
const ConfigInfo<bool> GFX_SHADER_CACHE{{System::GFX, "Settings", "ShaderCache"}, true};
const ConfigInfo<bool> GFX_WAIT_FOR_SHADERS_BEFORE_STARTING{
{System::GFX, "Settings", "WaitForShadersBeforeStarting"}, false};
const ConfigInfo<int> GFX_SHADER_COMPILATION_MODE{
{System::GFX, "Settings", "ShaderCompilationMode"},
static_cast<int>(ShaderCompilationMode::Synchronous)};
const ConfigInfo<ShaderCompilationMode> GFX_SHADER_COMPILATION_MODE{
{System::GFX, "Settings", "ShaderCompilationMode"}, ShaderCompilationMode::Synchronous};
const ConfigInfo<int> GFX_SHADER_COMPILER_THREADS{
{System::GFX, "Settings", "ShaderCompilerThreads"}, 1};
const ConfigInfo<int> GFX_SHADER_PRECOMPILER_THREADS{
@ -111,7 +110,8 @@ const ConfigInfo<bool> GFX_ENHANCE_DISABLE_COPY_FILTER{
// Graphics.Stereoscopy
const ConfigInfo<int> GFX_STEREO_MODE{{System::GFX, "Stereoscopy", "StereoMode"}, 0};
const ConfigInfo<StereoMode> GFX_STEREO_MODE{{System::GFX, "Stereoscopy", "StereoMode"},
StereoMode::Off};
const ConfigInfo<int> GFX_STEREO_DEPTH{{System::GFX, "Stereoscopy", "StereoDepth"}, 20};
const ConfigInfo<int> GFX_STEREO_CONVERGENCE_PERCENTAGE{
{System::GFX, "Stereoscopy", "StereoConvergencePercentage"}, 100};