neteja tidy a source/game (fixes d'arrel: BulletKind enum class, signatures, branches)
This commit is contained in:
+60
-102
@@ -30,30 +30,38 @@ namespace Options {
|
||||
std::string crtpi_file_path;
|
||||
int current_crtpi_preset = 0;
|
||||
|
||||
// Lectura tolerant d'un camp YAML: assigna a `target` el valor del camp
|
||||
// si existeix i el tipus encaixa. Si la clau no hi és o el tipus YAML
|
||||
// no és compatible amb T, conserva el valor previ de `target` (default).
|
||||
// Retorna true si s'ha llegit, false si s'ha conservat el default.
|
||||
template <typename T>
|
||||
auto tryGet(const fkyaml::node &node, const std::string &key, T &target) -> bool {
|
||||
if (!node.contains(key)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
target = node[key].get_value<T>();
|
||||
return true;
|
||||
} catch (...) {
|
||||
// @INTENTIONAL: valor YAML amb tipus incompatible per a T. La
|
||||
// política del loader és conservar el default existent en
|
||||
// `target` enlloc d'avortar la càrrega de la resta del fitxer.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Helpers locals ---
|
||||
namespace {
|
||||
void parseBoolField(const fkyaml::node &node, const std::string &key, bool &target) {
|
||||
if (node.contains(key)) {
|
||||
try {
|
||||
target = node[key].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<bool>(node, key, target);
|
||||
}
|
||||
|
||||
void parseIntField(const fkyaml::node &node, const std::string &key, int &target) {
|
||||
if (node.contains(key)) {
|
||||
try {
|
||||
target = node[key].get_value<int>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<int>(node, key, target);
|
||||
}
|
||||
|
||||
void parseStringField(const fkyaml::node &node, const std::string &key, std::string &target) {
|
||||
if (node.contains(key)) {
|
||||
try {
|
||||
target = node[key].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<std::string>(node, key, target);
|
||||
}
|
||||
|
||||
void loadWindowFromYaml(const fkyaml::node &yaml) {
|
||||
@@ -72,10 +80,9 @@ namespace Options {
|
||||
parseBoolField(vid, "fullscreen", video.fullscreen);
|
||||
parseBoolField(vid, "vsync", video.vsync);
|
||||
parseBoolField(vid, "integer_scale", video.integer_scale);
|
||||
if (vid.contains("scale_mode")) {
|
||||
try {
|
||||
video.scale_mode = static_cast<SDL_ScaleMode>(vid["scale_mode"].get_value<int>());
|
||||
} catch (...) {}
|
||||
int scale_mode_int = static_cast<int>(video.scale_mode);
|
||||
if (tryGet<int>(vid, "scale_mode", scale_mode_int)) {
|
||||
video.scale_mode = static_cast<SDL_ScaleMode>(scale_mode_int);
|
||||
}
|
||||
|
||||
if (vid.contains("gpu")) {
|
||||
@@ -94,13 +101,11 @@ namespace Options {
|
||||
if (vid.contains("shader")) {
|
||||
const auto &sh = vid["shader"];
|
||||
parseBoolField(sh, "enabled", video.shader.enabled);
|
||||
if (sh.contains("current_shader")) {
|
||||
try {
|
||||
auto s = sh["current_shader"].get_value<std::string>();
|
||||
video.shader.current_shader = (s == "crtpi" || s == "CRTPI")
|
||||
? Rendering::ShaderType::CRTPI
|
||||
: Rendering::ShaderType::POSTFX;
|
||||
} catch (...) {}
|
||||
std::string shader_kind;
|
||||
if (tryGet<std::string>(sh, "current_shader", shader_kind)) {
|
||||
video.shader.current_shader = (shader_kind == "crtpi" || shader_kind == "CRTPI")
|
||||
? Rendering::ShaderType::CRTPI
|
||||
: Rendering::ShaderType::POSTFX;
|
||||
}
|
||||
parseStringField(sh, "current_postfx_preset", video.shader.current_postfx_preset_name);
|
||||
parseStringField(sh, "current_crtpi_preset", video.shader.current_crtpi_preset_name);
|
||||
@@ -112,27 +117,21 @@ namespace Options {
|
||||
const auto &aud = yaml["audio"];
|
||||
|
||||
parseBoolField(aud, "enabled", audio.enabled);
|
||||
if (aud.contains("volume")) {
|
||||
try {
|
||||
audio.volume = std::clamp(aud["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||
} catch (...) {}
|
||||
if (tryGet<float>(aud, "volume", audio.volume)) {
|
||||
audio.volume = std::clamp(audio.volume, 0.0F, 1.0F);
|
||||
}
|
||||
if (aud.contains("music")) {
|
||||
const auto &mus = aud["music"];
|
||||
parseBoolField(mus, "enabled", audio.music.enabled);
|
||||
if (mus.contains("volume")) {
|
||||
try {
|
||||
audio.music.volume = std::clamp(mus["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||
} catch (...) {}
|
||||
if (tryGet<float>(mus, "volume", audio.music.volume)) {
|
||||
audio.music.volume = std::clamp(audio.music.volume, 0.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
if (aud.contains("sound")) {
|
||||
const auto &snd = aud["sound"];
|
||||
parseBoolField(snd, "enabled", audio.sound.enabled);
|
||||
if (snd.contains("volume")) {
|
||||
try {
|
||||
audio.sound.volume = std::clamp(snd["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||
} catch (...) {}
|
||||
if (tryGet<float>(snd, "volume", audio.sound.volume)) {
|
||||
audio.sound.volume = std::clamp(audio.sound.volume, 0.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,10 +161,9 @@ namespace Options {
|
||||
size_t i = 0;
|
||||
for (const auto &entry : ins) {
|
||||
if (i >= inputs.size()) { break; }
|
||||
if (entry.contains("device_type")) {
|
||||
try {
|
||||
inputs[i].deviceType = static_cast<Uint8>(entry["device_type"].get_value<int>());
|
||||
} catch (...) {}
|
||||
int device_type_int = inputs[i].deviceType;
|
||||
if (tryGet<int>(entry, "device_type", device_type_int)) {
|
||||
inputs[i].deviceType = static_cast<Uint8>(device_type_int);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -229,11 +227,7 @@ namespace Options {
|
||||
auto yaml = fkyaml::node::deserialize(CONTENT);
|
||||
|
||||
int file_version = 0;
|
||||
if (yaml.contains("config_version")) {
|
||||
try {
|
||||
file_version = yaml["config_version"].get_value<int>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<int>(yaml, "config_version", file_version);
|
||||
if (file_version != Settings::CURRENT_CONFIG_VERSION) {
|
||||
std::cout << "Config version " << file_version
|
||||
<< " != expected " << Settings::CURRENT_CONFIG_VERSION
|
||||
@@ -352,31 +346,27 @@ namespace Options {
|
||||
|
||||
namespace {
|
||||
void parseFloatField(const fkyaml::node &node, const std::string &key, float &target) {
|
||||
if (node.contains(key)) {
|
||||
try {
|
||||
target = node[key].get_value<float>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<float>(node, key, target);
|
||||
}
|
||||
|
||||
auto defaultPostFXPresets() -> const std::vector<PostFXPreset> & {
|
||||
static const std::vector<PostFXPreset> DEFAULTS = {
|
||||
{"CRT", 0.6F, 0.7F, 0.15F, 0.6F, 0.8F},
|
||||
{"NTSC", 0.4F, 0.5F, 0.2F, 0.4F, 0.5F, 0.0F, 0.6F},
|
||||
{"CURVED", 0.5F, 0.6F, 0.1F, 0.5F, 0.7F, 0.8F},
|
||||
{"SCANLINES", 0.0F, 0.8F},
|
||||
{"SUBTLE", 0.3F, 0.4F, 0.05F, 0.0F, 0.3F},
|
||||
{"CRT LIVE", 0.5F, 0.6F, 0.3F, 0.3F, 0.4F, 0.3F, 0.4F, 0.8F},
|
||||
{.name = "CRT", .vignette = 0.6F, .scanlines = 0.7F, .chroma = 0.15F, .mask = 0.6F, .gamma = 0.8F},
|
||||
{.name = "NTSC", .vignette = 0.4F, .scanlines = 0.5F, .chroma = 0.2F, .mask = 0.4F, .gamma = 0.5F, .curvature = 0.0F, .bleeding = 0.6F},
|
||||
{.name = "CURVED", .vignette = 0.5F, .scanlines = 0.6F, .chroma = 0.1F, .mask = 0.5F, .gamma = 0.7F, .curvature = 0.8F},
|
||||
{.name = "SCANLINES", .vignette = 0.0F, .scanlines = 0.8F},
|
||||
{.name = "SUBTLE", .vignette = 0.3F, .scanlines = 0.4F, .chroma = 0.05F, .mask = 0.0F, .gamma = 0.3F},
|
||||
{.name = "CRT LIVE", .vignette = 0.5F, .scanlines = 0.6F, .chroma = 0.3F, .mask = 0.3F, .gamma = 0.4F, .curvature = 0.3F, .bleeding = 0.4F, .flicker = 0.8F},
|
||||
};
|
||||
return DEFAULTS;
|
||||
}
|
||||
|
||||
auto defaultCrtPiPresets() -> const std::vector<CrtPiPreset> & {
|
||||
static const std::vector<CrtPiPreset> DEFAULTS = {
|
||||
{"Default", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, false, false},
|
||||
{"Curved", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, true, true, true, false},
|
||||
{"Sharp", 6.0F, 0.12F, 3.5F, 2.4F, 2.2F, 0.80F, 0.05F, 0.10F, 2, true, false, true, false, true},
|
||||
{"Minimal", 8.0F, 0.05F, 2.0F, 2.4F, 2.2F, 1.00F, 0.0F, 0.0F, 0, true, false, false, false, false},
|
||||
{.name = "Default", .scanline_weight = 6.0F, .scanline_gap_brightness = 0.12F, .bloom_factor = 3.5F, .input_gamma = 2.4F, .output_gamma = 2.2F, .mask_brightness = 0.80F, .curvature_x = 0.05F, .curvature_y = 0.10F, .mask_type = 2, .enable_scanlines = true, .enable_multisample = true, .enable_gamma = true, .enable_curvature = false, .enable_sharper = false},
|
||||
{.name = "Curved", .scanline_weight = 6.0F, .scanline_gap_brightness = 0.12F, .bloom_factor = 3.5F, .input_gamma = 2.4F, .output_gamma = 2.2F, .mask_brightness = 0.80F, .curvature_x = 0.05F, .curvature_y = 0.10F, .mask_type = 2, .enable_scanlines = true, .enable_multisample = true, .enable_gamma = true, .enable_curvature = true, .enable_sharper = false},
|
||||
{.name = "Sharp", .scanline_weight = 6.0F, .scanline_gap_brightness = 0.12F, .bloom_factor = 3.5F, .input_gamma = 2.4F, .output_gamma = 2.2F, .mask_brightness = 0.80F, .curvature_x = 0.05F, .curvature_y = 0.10F, .mask_type = 2, .enable_scanlines = true, .enable_multisample = false, .enable_gamma = true, .enable_curvature = false, .enable_sharper = true},
|
||||
{.name = "Minimal", .scanline_weight = 8.0F, .scanline_gap_brightness = 0.05F, .bloom_factor = 2.0F, .input_gamma = 2.4F, .output_gamma = 2.2F, .mask_brightness = 1.00F, .curvature_x = 0.0F, .curvature_y = 0.0F, .mask_type = 0, .enable_scanlines = true, .enable_multisample = false, .enable_gamma = false, .enable_curvature = false, .enable_sharper = false},
|
||||
};
|
||||
return DEFAULTS;
|
||||
}
|
||||
@@ -449,11 +439,7 @@ namespace Options {
|
||||
if (yaml.contains("presets")) {
|
||||
for (const auto &p : yaml["presets"]) {
|
||||
PostFXPreset preset;
|
||||
if (p.contains("name")) {
|
||||
try {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<std::string>(p, "name", preset.name);
|
||||
parseFloatField(p, "vignette", preset.vignette);
|
||||
parseFloatField(p, "scanlines", preset.scanlines);
|
||||
parseFloatField(p, "chroma", preset.chroma);
|
||||
@@ -506,11 +492,7 @@ namespace Options {
|
||||
if (yaml.contains("presets")) {
|
||||
for (const auto &p : yaml["presets"]) {
|
||||
CrtPiPreset preset;
|
||||
if (p.contains("name")) {
|
||||
try {
|
||||
preset.name = p["name"].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<std::string>(p, "name", preset.name);
|
||||
parseFloatField(p, "scanline_weight", preset.scanline_weight);
|
||||
parseFloatField(p, "scanline_gap_brightness", preset.scanline_gap_brightness);
|
||||
parseFloatField(p, "bloom_factor", preset.bloom_factor);
|
||||
@@ -519,36 +501,12 @@ namespace Options {
|
||||
parseFloatField(p, "mask_brightness", preset.mask_brightness);
|
||||
parseFloatField(p, "curvature_x", preset.curvature_x);
|
||||
parseFloatField(p, "curvature_y", preset.curvature_y);
|
||||
if (p.contains("mask_type")) {
|
||||
try {
|
||||
preset.mask_type = p["mask_type"].get_value<int>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_scanlines")) {
|
||||
try {
|
||||
preset.enable_scanlines = p["enable_scanlines"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_multisample")) {
|
||||
try {
|
||||
preset.enable_multisample = p["enable_multisample"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_gamma")) {
|
||||
try {
|
||||
preset.enable_gamma = p["enable_gamma"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_curvature")) {
|
||||
try {
|
||||
preset.enable_curvature = p["enable_curvature"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (p.contains("enable_sharper")) {
|
||||
try {
|
||||
preset.enable_sharper = p["enable_sharper"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
tryGet<int>(p, "mask_type", preset.mask_type);
|
||||
tryGet<bool>(p, "enable_scanlines", preset.enable_scanlines);
|
||||
tryGet<bool>(p, "enable_multisample", preset.enable_multisample);
|
||||
tryGet<bool>(p, "enable_gamma", preset.enable_gamma);
|
||||
tryGet<bool>(p, "enable_curvature", preset.enable_curvature);
|
||||
tryGet<bool>(p, "enable_sharper", preset.enable_sharper);
|
||||
crtpi_presets.push_back(preset);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user