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

@ -8,6 +8,10 @@
#include "Common/Config/Config.h"
enum class AspectMode : int;
enum class ShaderCompilationMode : int;
enum class StereoMode : int;
namespace Config
{
// Configuration Information
@ -20,8 +24,8 @@ extern const ConfigInfo<int> GFX_ADAPTER;
// Graphics.Settings
extern const ConfigInfo<bool> GFX_WIDESCREEN_HACK;
extern const ConfigInfo<int> GFX_ASPECT_RATIO;
extern const ConfigInfo<int> GFX_SUGGESTED_ASPECT_RATIO;
extern const ConfigInfo<AspectMode> GFX_ASPECT_RATIO;
extern const ConfigInfo<AspectMode> GFX_SUGGESTED_ASPECT_RATIO;
extern const ConfigInfo<bool> GFX_CROP;
extern const ConfigInfo<int> GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES;
extern const ConfigInfo<bool> GFX_SHOW_FPS;
@ -60,7 +64,7 @@ extern const ConfigInfo<bool> GFX_BACKEND_MULTITHREADING;
extern const ConfigInfo<int> GFX_COMMAND_BUFFER_EXECUTE_INTERVAL;
extern const ConfigInfo<bool> GFX_SHADER_CACHE;
extern const ConfigInfo<bool> GFX_WAIT_FOR_SHADERS_BEFORE_STARTING;
extern const ConfigInfo<int> GFX_SHADER_COMPILATION_MODE;
extern const ConfigInfo<ShaderCompilationMode> GFX_SHADER_COMPILATION_MODE;
extern const ConfigInfo<int> GFX_SHADER_COMPILER_THREADS;
extern const ConfigInfo<int> GFX_SHADER_PRECOMPILER_THREADS;
@ -84,7 +88,7 @@ extern const ConfigInfo<bool> GFX_ENHANCE_DISABLE_COPY_FILTER;
// Graphics.Stereoscopy
extern const ConfigInfo<int> GFX_STEREO_MODE;
extern const ConfigInfo<StereoMode> GFX_STEREO_MODE;
extern const ConfigInfo<int> GFX_STEREO_DEPTH;
extern const ConfigInfo<int> GFX_STEREO_CONVERGENCE_PERCENTAGE;
extern const ConfigInfo<bool> GFX_STEREO_SWAP_EYES;